if_txp.c revision 1.73 1 1.73 thorpej /* $NetBSD: if_txp.c,v 1.73 2020/03/10 01:23:42 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.73 thorpej __KERNEL_RCSID(0, "$NetBSD: if_txp.c,v 1.73 2020/03/10 01:23:42 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.72 thorpej /*
347 1.72 thorpej * XXX Because we allocate Rx buffers in txp_alloc_rings(),
348 1.72 thorpej * XXX we have to go back and claim them now that our mowners
349 1.72 thorpej * XXX have been initialized (in ether_ifattach()).
350 1.72 thorpej *
351 1.72 thorpej * XXX FIXME by allocating Rx buffers only when interface is
352 1.72 thorpej * XXX running, like other drivers do.
353 1.72 thorpej */
354 1.72 thorpej for (i = 0; i < RXBUF_ENTRIES; i++) {
355 1.72 thorpej KASSERT(sc->sc_rxd[i].sd_mbuf != NULL);
356 1.72 thorpej MCLAIM(sc->sc_rxd[i].sd_mbuf, &sc->sc_arpcom.ec_rx_mowner);
357 1.72 thorpej }
358 1.72 thorpej
359 1.35 tsutsui if (pmf_device_register1(self, NULL, NULL, txp_shutdown))
360 1.35 tsutsui pmf_class_network_register(self, ifp);
361 1.35 tsutsui else
362 1.35 tsutsui aprint_error_dev(self, "couldn't establish power handler\n");
363 1.7 is
364 1.7 is return;
365 1.7 is
366 1.7 is cleanupintr:
367 1.55 msaitoh pci_intr_disestablish(pc, sc->sc_ih);
368 1.7 is
369 1.7 is return;
370 1.7 is
371 1.1 drochner }
372 1.1 drochner
373 1.62 maxv static int
374 1.29 dsl txp_chip_init(struct txp_softc *sc)
375 1.1 drochner {
376 1.1 drochner /* disable interrupts */
377 1.1 drochner WRITE_REG(sc, TXP_IER, 0);
378 1.1 drochner WRITE_REG(sc, TXP_IMR,
379 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
380 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
381 1.1 drochner TXP_INT_LATCH);
382 1.1 drochner
383 1.1 drochner /* ack all interrupts */
384 1.1 drochner WRITE_REG(sc, TXP_ISR, TXP_INT_RESERVED | TXP_INT_LATCH |
385 1.1 drochner TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
386 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
387 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
388 1.1 drochner TXP_INT_A2H_3 | TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0);
389 1.1 drochner
390 1.1 drochner if (txp_reset_adapter(sc))
391 1.1 drochner return (-1);
392 1.1 drochner
393 1.1 drochner /* disable interrupts */
394 1.1 drochner WRITE_REG(sc, TXP_IER, 0);
395 1.1 drochner WRITE_REG(sc, TXP_IMR,
396 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
397 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
398 1.1 drochner TXP_INT_LATCH);
399 1.1 drochner
400 1.1 drochner /* ack all interrupts */
401 1.1 drochner WRITE_REG(sc, TXP_ISR, TXP_INT_RESERVED | TXP_INT_LATCH |
402 1.1 drochner TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
403 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
404 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
405 1.1 drochner TXP_INT_A2H_3 | TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0);
406 1.1 drochner
407 1.1 drochner return (0);
408 1.1 drochner }
409 1.1 drochner
410 1.62 maxv static int
411 1.29 dsl txp_reset_adapter(struct txp_softc *sc)
412 1.1 drochner {
413 1.53 msaitoh uint32_t r;
414 1.1 drochner int i;
415 1.1 drochner
416 1.1 drochner WRITE_REG(sc, TXP_SRR, TXP_SRR_ALL);
417 1.1 drochner DELAY(1000);
418 1.1 drochner WRITE_REG(sc, TXP_SRR, 0);
419 1.1 drochner
420 1.1 drochner /* Should wait max 6 seconds */
421 1.1 drochner for (i = 0; i < 6000; i++) {
422 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
423 1.1 drochner if (r == STAT_WAITING_FOR_HOST_REQUEST)
424 1.1 drochner break;
425 1.1 drochner DELAY(1000);
426 1.1 drochner }
427 1.1 drochner
428 1.1 drochner if (r != STAT_WAITING_FOR_HOST_REQUEST) {
429 1.1 drochner printf("%s: reset hung\n", TXP_DEVNAME(sc));
430 1.1 drochner return (-1);
431 1.1 drochner }
432 1.1 drochner
433 1.1 drochner return (0);
434 1.1 drochner }
435 1.1 drochner
436 1.62 maxv static int
437 1.29 dsl txp_download_fw(struct txp_softc *sc)
438 1.1 drochner {
439 1.12 chs const struct txp_fw_file_header *fileheader;
440 1.12 chs const struct txp_fw_section_header *secthead;
441 1.1 drochner int sect;
442 1.53 msaitoh uint32_t r, i, ier, imr;
443 1.1 drochner
444 1.1 drochner ier = READ_REG(sc, TXP_IER);
445 1.1 drochner WRITE_REG(sc, TXP_IER, ier | TXP_INT_A2H_0);
446 1.1 drochner
447 1.1 drochner imr = READ_REG(sc, TXP_IMR);
448 1.1 drochner WRITE_REG(sc, TXP_IMR, imr | TXP_INT_A2H_0);
449 1.1 drochner
450 1.1 drochner for (i = 0; i < 10000; i++) {
451 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
452 1.1 drochner if (r == STAT_WAITING_FOR_HOST_REQUEST)
453 1.1 drochner break;
454 1.1 drochner DELAY(50);
455 1.1 drochner }
456 1.1 drochner if (r != STAT_WAITING_FOR_HOST_REQUEST) {
457 1.1 drochner printf(": not waiting for host request\n");
458 1.1 drochner return (-1);
459 1.1 drochner }
460 1.1 drochner
461 1.1 drochner /* Ack the status */
462 1.1 drochner WRITE_REG(sc, TXP_ISR, TXP_INT_A2H_0);
463 1.1 drochner
464 1.12 chs fileheader = (const struct txp_fw_file_header *)tc990image;
465 1.44 msaitoh if (memcmp("TYPHOON", fileheader->magicid,
466 1.44 msaitoh sizeof(fileheader->magicid))) {
467 1.1 drochner printf(": fw invalid magic\n");
468 1.1 drochner return (-1);
469 1.1 drochner }
470 1.1 drochner
471 1.1 drochner /* Tell boot firmware to get ready for image */
472 1.1 drochner WRITE_REG(sc, TXP_H2A_1, le32toh(fileheader->addr));
473 1.67 thorpej WRITE_REG(sc, TXP_H2A_2, le32toh(fileheader->hmac[0]));
474 1.67 thorpej WRITE_REG(sc, TXP_H2A_3, le32toh(fileheader->hmac[1]));
475 1.67 thorpej WRITE_REG(sc, TXP_H2A_4, le32toh(fileheader->hmac[2]));
476 1.67 thorpej WRITE_REG(sc, TXP_H2A_5, le32toh(fileheader->hmac[3]));
477 1.67 thorpej WRITE_REG(sc, TXP_H2A_6, le32toh(fileheader->hmac[4]));
478 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_RUNTIME_IMAGE);
479 1.1 drochner
480 1.1 drochner if (txp_download_fw_wait(sc)) {
481 1.44 msaitoh printf("%s: fw wait failed, initial\n",
482 1.44 msaitoh device_xname(sc->sc_dev));
483 1.1 drochner return (-1);
484 1.1 drochner }
485 1.1 drochner
486 1.12 chs secthead = (const struct txp_fw_section_header *)
487 1.53 msaitoh (((const uint8_t *)tc990image) +
488 1.12 chs sizeof(struct txp_fw_file_header));
489 1.1 drochner
490 1.1 drochner for (sect = 0; sect < le32toh(fileheader->nsections); sect++) {
491 1.1 drochner if (txp_download_fw_section(sc, secthead, sect))
492 1.1 drochner return (-1);
493 1.12 chs secthead = (const struct txp_fw_section_header *)
494 1.53 msaitoh (((const uint8_t *)secthead) + le32toh(secthead->nbytes) +
495 1.1 drochner sizeof(*secthead));
496 1.1 drochner }
497 1.1 drochner
498 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_DOWNLOAD_COMPLETE);
499 1.1 drochner
500 1.1 drochner for (i = 0; i < 10000; i++) {
501 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
502 1.1 drochner if (r == STAT_WAITING_FOR_BOOT)
503 1.1 drochner break;
504 1.1 drochner DELAY(50);
505 1.1 drochner }
506 1.1 drochner if (r != STAT_WAITING_FOR_BOOT) {
507 1.1 drochner printf(": not waiting for boot\n");
508 1.1 drochner return (-1);
509 1.1 drochner }
510 1.1 drochner
511 1.1 drochner WRITE_REG(sc, TXP_IER, ier);
512 1.1 drochner WRITE_REG(sc, TXP_IMR, imr);
513 1.1 drochner
514 1.1 drochner return (0);
515 1.1 drochner }
516 1.1 drochner
517 1.62 maxv static int
518 1.29 dsl txp_download_fw_wait(struct txp_softc *sc)
519 1.1 drochner {
520 1.53 msaitoh uint32_t i, r;
521 1.1 drochner
522 1.1 drochner for (i = 0; i < 10000; i++) {
523 1.1 drochner r = READ_REG(sc, TXP_ISR);
524 1.1 drochner if (r & TXP_INT_A2H_0)
525 1.1 drochner break;
526 1.1 drochner DELAY(50);
527 1.1 drochner }
528 1.1 drochner
529 1.1 drochner if (!(r & TXP_INT_A2H_0)) {
530 1.1 drochner printf(": fw wait failed comm0\n");
531 1.1 drochner return (-1);
532 1.1 drochner }
533 1.1 drochner
534 1.1 drochner WRITE_REG(sc, TXP_ISR, TXP_INT_A2H_0);
535 1.1 drochner
536 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
537 1.1 drochner if (r != STAT_WAITING_FOR_SEGMENT) {
538 1.1 drochner printf(": fw not waiting for segment\n");
539 1.1 drochner return (-1);
540 1.1 drochner }
541 1.1 drochner return (0);
542 1.1 drochner }
543 1.1 drochner
544 1.62 maxv static int
545 1.44 msaitoh txp_download_fw_section(struct txp_softc *sc,
546 1.44 msaitoh const struct txp_fw_section_header *sect, int sectnum)
547 1.1 drochner {
548 1.1 drochner struct txp_dma_alloc dma;
549 1.1 drochner int rseg, err = 0;
550 1.1 drochner struct mbuf m;
551 1.14 christos #ifdef INET
552 1.53 msaitoh uint16_t csum;
553 1.14 christos #endif
554 1.1 drochner
555 1.1 drochner /* Skip zero length sections */
556 1.1 drochner if (sect->nbytes == 0)
557 1.1 drochner return (0);
558 1.1 drochner
559 1.1 drochner /* Make sure we aren't past the end of the image */
560 1.53 msaitoh rseg = ((const uint8_t *)sect) - ((const uint8_t *)tc990image);
561 1.1 drochner if (rseg >= sizeof(tc990image)) {
562 1.1 drochner printf(": fw invalid section address, section %d\n", sectnum);
563 1.1 drochner return (-1);
564 1.1 drochner }
565 1.1 drochner
566 1.1 drochner /* Make sure this section doesn't go past the end */
567 1.1 drochner rseg += le32toh(sect->nbytes);
568 1.1 drochner if (rseg >= sizeof(tc990image)) {
569 1.1 drochner printf(": fw truncated section %d\n", sectnum);
570 1.1 drochner return (-1);
571 1.1 drochner }
572 1.1 drochner
573 1.1 drochner /* map a buffer, copy segment to it, get physaddr */
574 1.1 drochner if (txp_dma_malloc(sc, le32toh(sect->nbytes), &dma, 0)) {
575 1.1 drochner printf(": fw dma malloc failed, section %d\n", sectnum);
576 1.1 drochner return (-1);
577 1.1 drochner }
578 1.1 drochner
579 1.53 msaitoh memcpy(dma.dma_vaddr, ((const uint8_t *)sect) + sizeof(*sect),
580 1.1 drochner le32toh(sect->nbytes));
581 1.1 drochner
582 1.1 drochner /*
583 1.1 drochner * dummy up mbuf and verify section checksum
584 1.1 drochner */
585 1.1 drochner m.m_type = MT_DATA;
586 1.1 drochner m.m_next = m.m_nextpkt = NULL;
587 1.50 msaitoh m.m_owner = NULL;
588 1.1 drochner m.m_len = le32toh(sect->nbytes);
589 1.1 drochner m.m_data = dma.dma_vaddr;
590 1.1 drochner m.m_flags = 0;
591 1.14 christos #ifdef INET
592 1.1 drochner csum = in_cksum(&m, le32toh(sect->nbytes));
593 1.1 drochner if (csum != sect->cksum) {
594 1.1 drochner printf(": fw section %d, bad cksum (expected 0x%x got 0x%x)\n",
595 1.1 drochner sectnum, sect->cksum, csum);
596 1.14 christos txp_dma_free(sc, &dma);
597 1.14 christos return -1;
598 1.1 drochner }
599 1.14 christos #endif
600 1.1 drochner
601 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma.dma_map, 0,
602 1.1 drochner dma.dma_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
603 1.1 drochner
604 1.1 drochner WRITE_REG(sc, TXP_H2A_1, le32toh(sect->nbytes));
605 1.1 drochner WRITE_REG(sc, TXP_H2A_2, le32toh(sect->cksum));
606 1.1 drochner WRITE_REG(sc, TXP_H2A_3, le32toh(sect->addr));
607 1.65 thorpej WRITE_REG(sc, TXP_H2A_4, BUS_ADDR_HI32(dma.dma_paddr));
608 1.65 thorpej WRITE_REG(sc, TXP_H2A_5, BUS_ADDR_LO32(dma.dma_paddr));
609 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_SEGMENT_AVAILABLE);
610 1.1 drochner
611 1.1 drochner if (txp_download_fw_wait(sc)) {
612 1.1 drochner printf("%s: fw wait failed, section %d\n",
613 1.39 chs device_xname(sc->sc_dev), sectnum);
614 1.1 drochner err = -1;
615 1.1 drochner }
616 1.1 drochner
617 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma.dma_map, 0,
618 1.1 drochner dma.dma_map->dm_mapsize, BUS_DMASYNC_POSTWRITE);
619 1.1 drochner
620 1.1 drochner txp_dma_free(sc, &dma);
621 1.1 drochner return (err);
622 1.1 drochner }
623 1.1 drochner
624 1.62 maxv static int
625 1.29 dsl txp_intr(void *vsc)
626 1.1 drochner {
627 1.1 drochner struct txp_softc *sc = vsc;
628 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
629 1.53 msaitoh uint32_t isr;
630 1.1 drochner int claimed = 0;
631 1.1 drochner
632 1.1 drochner /* mask all interrupts */
633 1.1 drochner WRITE_REG(sc, TXP_IMR, TXP_INT_RESERVED | TXP_INT_SELF |
634 1.1 drochner TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
635 1.1 drochner TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0 |
636 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
637 1.1 drochner TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT | TXP_INT_LATCH);
638 1.1 drochner
639 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
640 1.53 msaitoh sizeof(struct txp_hostvar),
641 1.53 msaitoh BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
642 1.1 drochner
643 1.1 drochner isr = READ_REG(sc, TXP_ISR);
644 1.1 drochner while (isr) {
645 1.1 drochner claimed = 1;
646 1.1 drochner WRITE_REG(sc, TXP_ISR, isr);
647 1.1 drochner
648 1.1 drochner if ((*sc->sc_rxhir.r_roff) != (*sc->sc_rxhir.r_woff))
649 1.1 drochner txp_rx_reclaim(sc, &sc->sc_rxhir, &sc->sc_rxhiring_dma);
650 1.1 drochner if ((*sc->sc_rxlor.r_roff) != (*sc->sc_rxlor.r_woff))
651 1.1 drochner txp_rx_reclaim(sc, &sc->sc_rxlor, &sc->sc_rxloring_dma);
652 1.1 drochner
653 1.1 drochner if (hv->hv_rx_buf_write_idx == hv->hv_rx_buf_read_idx)
654 1.1 drochner txp_rxbuf_reclaim(sc);
655 1.1 drochner
656 1.1 drochner if (sc->sc_txhir.r_cnt && (sc->sc_txhir.r_cons !=
657 1.1 drochner TXP_OFFSET2IDX(le32toh(*(sc->sc_txhir.r_off)))))
658 1.1 drochner txp_tx_reclaim(sc, &sc->sc_txhir, &sc->sc_txhiring_dma);
659 1.1 drochner
660 1.1 drochner if (sc->sc_txlor.r_cnt && (sc->sc_txlor.r_cons !=
661 1.1 drochner TXP_OFFSET2IDX(le32toh(*(sc->sc_txlor.r_off)))))
662 1.1 drochner txp_tx_reclaim(sc, &sc->sc_txlor, &sc->sc_txloring_dma);
663 1.1 drochner
664 1.1 drochner isr = READ_REG(sc, TXP_ISR);
665 1.1 drochner }
666 1.1 drochner
667 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
668 1.53 msaitoh sizeof(struct txp_hostvar),
669 1.53 msaitoh BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
670 1.1 drochner
671 1.1 drochner /* unmask all interrupts */
672 1.1 drochner WRITE_REG(sc, TXP_IMR, TXP_INT_A2H_3);
673 1.1 drochner
674 1.46 ozaki if_schedule_deferred_start(&sc->sc_arpcom.ec_if);
675 1.1 drochner
676 1.1 drochner return (claimed);
677 1.1 drochner }
678 1.1 drochner
679 1.69 thorpej static struct txp_swdesc *
680 1.69 thorpej txp_rxd_alloc(struct txp_softc *sc)
681 1.69 thorpej {
682 1.69 thorpej if (sc->sc_txd_pool_ptr == 0)
683 1.69 thorpej return NULL;
684 1.69 thorpej return sc->sc_rxd_pool[--sc->sc_txd_pool_ptr];
685 1.69 thorpej }
686 1.69 thorpej
687 1.69 thorpej static void
688 1.69 thorpej txp_rxd_free(struct txp_softc *sc, struct txp_swdesc *sd)
689 1.69 thorpej {
690 1.69 thorpej KASSERT(sc->sc_txd_pool_ptr < RXBUF_ENTRIES);
691 1.69 thorpej sc->sc_rxd_pool[sc->sc_txd_pool_ptr++] = sd;
692 1.69 thorpej }
693 1.69 thorpej
694 1.70 thorpej static inline uint32_t
695 1.70 thorpej txp_rxd_idx(struct txp_softc *sc, struct txp_swdesc *sd)
696 1.70 thorpej {
697 1.70 thorpej KASSERT(sd >= &sc->sc_rxd[0] && sd < &sc->sc_rxd[RXBUF_ENTRIES]);
698 1.70 thorpej return (uint32_t)(sd - &sc->sc_rxd[0]);
699 1.70 thorpej }
700 1.70 thorpej
701 1.72 thorpej static inline uint32_t
702 1.72 thorpej txp_txd_idx(struct txp_softc *sc, struct txp_swdesc *sd)
703 1.72 thorpej {
704 1.72 thorpej KASSERT(sd >= &sc->sc_txd[0] && sd < &sc->sc_txd[TX_ENTRIES]);
705 1.72 thorpej return (uint32_t)(sd - &sc->sc_txd[0]);
706 1.72 thorpej }
707 1.72 thorpej
708 1.62 maxv static void
709 1.44 msaitoh txp_rx_reclaim(struct txp_softc *sc, struct txp_rx_ring *r,
710 1.44 msaitoh struct txp_dma_alloc *dma)
711 1.1 drochner {
712 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
713 1.1 drochner struct txp_rx_desc *rxd;
714 1.1 drochner struct mbuf *m;
715 1.1 drochner struct txp_swdesc *sd;
716 1.53 msaitoh uint32_t roff, woff;
717 1.73 thorpej uint16_t len;
718 1.1 drochner int sumflags = 0;
719 1.1 drochner int idx;
720 1.1 drochner
721 1.1 drochner roff = le32toh(*r->r_roff);
722 1.1 drochner woff = le32toh(*r->r_woff);
723 1.1 drochner idx = roff / sizeof(struct txp_rx_desc);
724 1.1 drochner rxd = r->r_desc + idx;
725 1.1 drochner
726 1.1 drochner while (roff != woff) {
727 1.1 drochner
728 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma->dma_map,
729 1.44 msaitoh idx * sizeof(struct txp_rx_desc),
730 1.44 msaitoh sizeof(struct txp_rx_desc), BUS_DMASYNC_POSTREAD);
731 1.1 drochner
732 1.1 drochner if (rxd->rx_flags & RX_FLAGS_ERROR) {
733 1.39 chs printf("%s: error 0x%x\n", device_xname(sc->sc_dev),
734 1.1 drochner le32toh(rxd->rx_stat));
735 1.63 thorpej if_statinc(ifp, if_ierrors);
736 1.1 drochner goto next;
737 1.1 drochner }
738 1.1 drochner
739 1.1 drochner /* retrieve stashed pointer */
740 1.71 thorpej KASSERT(rxd->rx_vaddrlo < RXBUF_ENTRIES);
741 1.70 thorpej sd = &sc->sc_rxd[rxd->rx_vaddrlo];
742 1.1 drochner
743 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
744 1.1 drochner sd->sd_map->dm_mapsize, BUS_DMASYNC_POSTREAD);
745 1.73 thorpej
746 1.73 thorpej len = le16toh(rxd->rx_len);
747 1.73 thorpej
748 1.73 thorpej #ifdef __NO_STRICT_ALIGNMENT
749 1.1 drochner bus_dmamap_unload(sc->sc_dmat, sd->sd_map);
750 1.1 drochner m = sd->sd_mbuf;
751 1.72 thorpej sd->sd_mbuf = NULL;
752 1.69 thorpej txp_rxd_free(sc, sd);
753 1.73 thorpej #else
754 1.73 thorpej /*
755 1.73 thorpej * The Typhoon's receive buffers must be 4-byte aligned.
756 1.73 thorpej * But this means the data after the Ethernet header
757 1.73 thorpej * is misaligned. We must allocate a new buffer and
758 1.73 thorpej * copy the data, shifted forward 2 bytes.
759 1.73 thorpej */
760 1.73 thorpej MGETHDR(m, M_DONTWAIT, MT_DATA);
761 1.73 thorpej if (m == NULL) {
762 1.73 thorpej dropit:
763 1.73 thorpej if_statinc(ifp, if_ierrors);
764 1.73 thorpej txp_rxd_free(sc, sd);
765 1.73 thorpej goto next;
766 1.73 thorpej }
767 1.73 thorpej MCLAIM(m, &sc->sc_arpcom.ec_rx_mowner);
768 1.73 thorpej if (len > (MHLEN - ETHER_ALIGN)) {
769 1.73 thorpej MCLGET(m, M_DONTWAIT);
770 1.73 thorpej if ((m->m_flags & M_EXT) == 0) {
771 1.1 drochner m_freem(m);
772 1.73 thorpej goto dropit;
773 1.1 drochner }
774 1.1 drochner }
775 1.73 thorpej m_set_rcvif(m, ifp);
776 1.73 thorpej m->m_data += ETHER_ALIGN;
777 1.73 thorpej memcpy(mtod(m, void *), mtod(sd->sd_mbuf, void *), len);
778 1.73 thorpej txp_rxd_free(sc, sd);
779 1.73 thorpej #endif /* __NO_STRICT_ALIGNMENT */
780 1.73 thorpej
781 1.73 thorpej m->m_pkthdr.len = m->m_len = len;
782 1.1 drochner
783 1.1 drochner if (rxd->rx_stat & htole32(RX_STAT_IPCKSUMBAD))
784 1.53 msaitoh sumflags |= (M_CSUM_IPv4 | M_CSUM_IPv4_BAD);
785 1.1 drochner else if (rxd->rx_stat & htole32(RX_STAT_IPCKSUMGOOD))
786 1.2 drochner sumflags |= M_CSUM_IPv4;
787 1.1 drochner
788 1.1 drochner if (rxd->rx_stat & htole32(RX_STAT_TCPCKSUMBAD))
789 1.53 msaitoh sumflags |= (M_CSUM_TCPv4 | M_CSUM_TCP_UDP_BAD);
790 1.1 drochner else if (rxd->rx_stat & htole32(RX_STAT_TCPCKSUMGOOD))
791 1.2 drochner sumflags |= M_CSUM_TCPv4;
792 1.1 drochner
793 1.1 drochner if (rxd->rx_stat & htole32(RX_STAT_UDPCKSUMBAD))
794 1.53 msaitoh sumflags |= (M_CSUM_UDPv4 | M_CSUM_TCP_UDP_BAD);
795 1.1 drochner else if (rxd->rx_stat & htole32(RX_STAT_UDPCKSUMGOOD))
796 1.2 drochner sumflags |= M_CSUM_UDPv4;
797 1.1 drochner
798 1.2 drochner m->m_pkthdr.csum_flags = sumflags;
799 1.1 drochner
800 1.1 drochner if (rxd->rx_stat & htole32(RX_STAT_VLAN)) {
801 1.48 knakahar vlan_set_tag(m, htons(rxd->rx_vlan >> 16));
802 1.1 drochner }
803 1.1 drochner
804 1.42 ozaki if_percpuq_enqueue(ifp->if_percpuq, m);
805 1.1 drochner
806 1.1 drochner next:
807 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma->dma_map,
808 1.44 msaitoh idx * sizeof(struct txp_rx_desc),
809 1.44 msaitoh sizeof(struct txp_rx_desc), BUS_DMASYNC_PREREAD);
810 1.1 drochner
811 1.1 drochner roff += sizeof(struct txp_rx_desc);
812 1.1 drochner if (roff == (RX_ENTRIES * sizeof(struct txp_rx_desc))) {
813 1.1 drochner idx = 0;
814 1.1 drochner roff = 0;
815 1.1 drochner rxd = r->r_desc;
816 1.1 drochner } else {
817 1.1 drochner idx++;
818 1.1 drochner rxd++;
819 1.1 drochner }
820 1.1 drochner woff = le32toh(*r->r_woff);
821 1.1 drochner }
822 1.1 drochner
823 1.1 drochner *r->r_roff = htole32(woff);
824 1.1 drochner }
825 1.1 drochner
826 1.62 maxv static void
827 1.29 dsl txp_rxbuf_reclaim(struct txp_softc *sc)
828 1.1 drochner {
829 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
830 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
831 1.1 drochner struct txp_rxbuf_desc *rbd;
832 1.1 drochner struct txp_swdesc *sd;
833 1.53 msaitoh uint32_t i, end;
834 1.1 drochner
835 1.1 drochner end = TXP_OFFSET2IDX(le32toh(hv->hv_rx_buf_read_idx));
836 1.1 drochner i = TXP_OFFSET2IDX(le32toh(hv->hv_rx_buf_write_idx));
837 1.1 drochner
838 1.1 drochner if (++i == RXBUF_ENTRIES)
839 1.1 drochner i = 0;
840 1.1 drochner
841 1.1 drochner rbd = sc->sc_rxbufs + i;
842 1.1 drochner
843 1.1 drochner while (i != end) {
844 1.69 thorpej sd = txp_rxd_alloc(sc);
845 1.1 drochner if (sd == NULL)
846 1.1 drochner break;
847 1.1 drochner
848 1.73 thorpej /* We might already have a buffer allocated. */
849 1.73 thorpej if (sd->sd_mbuf == NULL) {
850 1.73 thorpej MGETHDR(sd->sd_mbuf, M_DONTWAIT, MT_DATA);
851 1.73 thorpej if (sd->sd_mbuf == NULL)
852 1.73 thorpej goto err_sd;
853 1.73 thorpej MCLAIM(sd->sd_mbuf, &sc->sc_arpcom.ec_rx_mowner);
854 1.73 thorpej
855 1.73 thorpej MCLGET(sd->sd_mbuf, M_DONTWAIT);
856 1.73 thorpej if ((sd->sd_mbuf->m_flags & M_EXT) == 0)
857 1.73 thorpej goto err_mbuf;
858 1.73 thorpej m_set_rcvif(sd->sd_mbuf, ifp);
859 1.73 thorpej sd->sd_mbuf->m_pkthdr.len =
860 1.73 thorpej sd->sd_mbuf->m_len = MCLBYTES;
861 1.73 thorpej if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map,
862 1.73 thorpej sd->sd_mbuf, BUS_DMA_NOWAIT)) {
863 1.73 thorpej goto err_mbuf;
864 1.73 thorpej }
865 1.1 drochner }
866 1.1 drochner
867 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxbufring_dma.dma_map,
868 1.1 drochner i * sizeof(struct txp_rxbuf_desc),
869 1.1 drochner sizeof(struct txp_rxbuf_desc), BUS_DMASYNC_POSTWRITE);
870 1.10 perry
871 1.1 drochner /* stash away pointer */
872 1.70 thorpej rbd->rb_vaddrlo = txp_rxd_idx(sc, sd);
873 1.1 drochner
874 1.65 thorpej rbd->rb_paddrlo =
875 1.65 thorpej htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[0].ds_addr));
876 1.65 thorpej rbd->rb_paddrhi =
877 1.65 thorpej htole32(BUS_ADDR_HI32(sd->sd_map->dm_segs[0].ds_addr));
878 1.1 drochner
879 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
880 1.1 drochner sd->sd_map->dm_mapsize, BUS_DMASYNC_PREREAD);
881 1.1 drochner
882 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxbufring_dma.dma_map,
883 1.1 drochner i * sizeof(struct txp_rxbuf_desc),
884 1.1 drochner sizeof(struct txp_rxbuf_desc), BUS_DMASYNC_PREWRITE);
885 1.1 drochner
886 1.1 drochner hv->hv_rx_buf_write_idx = htole32(TXP_IDX2OFFSET(i));
887 1.1 drochner
888 1.1 drochner if (++i == RXBUF_ENTRIES) {
889 1.1 drochner i = 0;
890 1.1 drochner rbd = sc->sc_rxbufs;
891 1.1 drochner } else
892 1.1 drochner rbd++;
893 1.1 drochner }
894 1.1 drochner return;
895 1.1 drochner
896 1.1 drochner err_mbuf:
897 1.1 drochner m_freem(sd->sd_mbuf);
898 1.72 thorpej sd->sd_mbuf = NULL;
899 1.1 drochner err_sd:
900 1.69 thorpej txp_rxd_free(sc, sd);
901 1.1 drochner }
902 1.1 drochner
903 1.1 drochner /*
904 1.1 drochner * Reclaim mbufs and entries from a transmit ring.
905 1.1 drochner */
906 1.62 maxv static void
907 1.44 msaitoh txp_tx_reclaim(struct txp_softc *sc, struct txp_tx_ring *r,
908 1.44 msaitoh struct txp_dma_alloc *dma)
909 1.1 drochner {
910 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
911 1.53 msaitoh uint32_t idx = TXP_OFFSET2IDX(le32toh(*(r->r_off)));
912 1.53 msaitoh uint32_t cons = r->r_cons, cnt = r->r_cnt;
913 1.1 drochner struct txp_tx_desc *txd = r->r_desc + cons;
914 1.72 thorpej struct txp_swdesc *sd;
915 1.1 drochner struct mbuf *m;
916 1.1 drochner
917 1.1 drochner while (cons != idx) {
918 1.1 drochner if (cnt == 0)
919 1.1 drochner break;
920 1.1 drochner
921 1.1 drochner bus_dmamap_sync(sc->sc_dmat, dma->dma_map,
922 1.1 drochner cons * sizeof(struct txp_tx_desc),
923 1.1 drochner sizeof(struct txp_tx_desc),
924 1.1 drochner BUS_DMASYNC_POSTWRITE);
925 1.1 drochner
926 1.1 drochner if ((txd->tx_flags & TX_FLAGS_TYPE_M) ==
927 1.1 drochner TX_FLAGS_TYPE_DATA) {
928 1.72 thorpej KASSERT(txd->tx_addrlo < TX_ENTRIES);
929 1.72 thorpej sd = &sc->sc_txd[txd->tx_addrlo];
930 1.1 drochner m = sd->sd_mbuf;
931 1.72 thorpej sd->sd_mbuf = NULL;
932 1.1 drochner if (m != NULL) {
933 1.72 thorpej bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
934 1.72 thorpej sd->sd_map->dm_mapsize,
935 1.72 thorpej BUS_DMASYNC_POSTWRITE);
936 1.72 thorpej bus_dmamap_unload(sc->sc_dmat, sd->sd_map);
937 1.1 drochner m_freem(m);
938 1.1 drochner txd->tx_addrlo = 0;
939 1.1 drochner txd->tx_addrhi = 0;
940 1.63 thorpej if_statinc(ifp, if_opackets);
941 1.1 drochner }
942 1.1 drochner }
943 1.1 drochner ifp->if_flags &= ~IFF_OACTIVE;
944 1.1 drochner
945 1.1 drochner if (++cons == TX_ENTRIES) {
946 1.1 drochner txd = r->r_desc;
947 1.1 drochner cons = 0;
948 1.72 thorpej } else
949 1.1 drochner txd++;
950 1.1 drochner
951 1.1 drochner cnt--;
952 1.1 drochner }
953 1.1 drochner
954 1.1 drochner r->r_cons = cons;
955 1.1 drochner r->r_cnt = cnt;
956 1.1 drochner if (cnt == 0)
957 1.1 drochner ifp->if_timer = 0;
958 1.1 drochner }
959 1.1 drochner
960 1.62 maxv static bool
961 1.35 tsutsui txp_shutdown(device_t self, int howto)
962 1.1 drochner {
963 1.35 tsutsui struct txp_softc *sc;
964 1.35 tsutsui
965 1.35 tsutsui sc = device_private(self);
966 1.1 drochner
967 1.1 drochner /* mask all interrupts */
968 1.1 drochner WRITE_REG(sc, TXP_IMR,
969 1.1 drochner TXP_INT_SELF | TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT |
970 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
971 1.1 drochner TXP_INT_LATCH);
972 1.1 drochner
973 1.1 drochner txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
974 1.1 drochner txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 0);
975 1.1 drochner txp_command(sc, TXP_CMD_HALT, 0, 0, 0, NULL, NULL, NULL, 0);
976 1.35 tsutsui
977 1.35 tsutsui return true;
978 1.1 drochner }
979 1.1 drochner
980 1.62 maxv static int
981 1.29 dsl txp_alloc_rings(struct txp_softc *sc)
982 1.1 drochner {
983 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
984 1.1 drochner struct txp_boot_record *boot;
985 1.1 drochner struct txp_swdesc *sd;
986 1.53 msaitoh uint32_t r;
987 1.15 christos int i, j, nb;
988 1.1 drochner
989 1.1 drochner /* boot record */
990 1.44 msaitoh if (txp_dma_malloc(sc, sizeof(struct txp_boot_record),
991 1.44 msaitoh &sc->sc_boot_dma, BUS_DMA_COHERENT)) {
992 1.1 drochner printf(": can't allocate boot record\n");
993 1.1 drochner return (-1);
994 1.1 drochner }
995 1.1 drochner boot = (struct txp_boot_record *)sc->sc_boot_dma.dma_vaddr;
996 1.32 cegger memset(boot, 0, sizeof(*boot));
997 1.1 drochner sc->sc_boot = boot;
998 1.1 drochner
999 1.1 drochner /* host variables */
1000 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_hostvar), &sc->sc_host_dma,
1001 1.1 drochner BUS_DMA_COHERENT)) {
1002 1.1 drochner printf(": can't allocate host ring\n");
1003 1.1 drochner goto bail_boot;
1004 1.1 drochner }
1005 1.32 cegger memset(sc->sc_host_dma.dma_vaddr, 0, sizeof(struct txp_hostvar));
1006 1.65 thorpej boot->br_hostvar_lo = htole32(BUS_ADDR_LO32(sc->sc_host_dma.dma_paddr));
1007 1.65 thorpej boot->br_hostvar_hi = htole32(BUS_ADDR_HI32(sc->sc_host_dma.dma_paddr));
1008 1.1 drochner sc->sc_hostvar = (struct txp_hostvar *)sc->sc_host_dma.dma_vaddr;
1009 1.1 drochner
1010 1.1 drochner /* high priority tx ring */
1011 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_tx_desc) * TX_ENTRIES,
1012 1.1 drochner &sc->sc_txhiring_dma, BUS_DMA_COHERENT)) {
1013 1.1 drochner printf(": can't allocate high tx ring\n");
1014 1.1 drochner goto bail_host;
1015 1.1 drochner }
1016 1.44 msaitoh memset(sc->sc_txhiring_dma.dma_vaddr, 0,
1017 1.44 msaitoh sizeof(struct txp_tx_desc) * TX_ENTRIES);
1018 1.65 thorpej boot->br_txhipri_lo =
1019 1.65 thorpej htole32(BUS_ADDR_LO32(sc->sc_txhiring_dma.dma_paddr));
1020 1.65 thorpej boot->br_txhipri_hi =
1021 1.65 thorpej htole32(BUS_ADDR_HI32(sc->sc_txhiring_dma.dma_paddr));
1022 1.1 drochner boot->br_txhipri_siz = htole32(TX_ENTRIES * sizeof(struct txp_tx_desc));
1023 1.1 drochner sc->sc_txhir.r_reg = TXP_H2A_1;
1024 1.65 thorpej sc->sc_txhir.r_desc =
1025 1.65 thorpej (struct txp_tx_desc *)sc->sc_txhiring_dma.dma_vaddr;
1026 1.1 drochner sc->sc_txhir.r_cons = sc->sc_txhir.r_prod = sc->sc_txhir.r_cnt = 0;
1027 1.1 drochner sc->sc_txhir.r_off = &sc->sc_hostvar->hv_tx_hi_desc_read_idx;
1028 1.1 drochner for (i = 0; i < TX_ENTRIES; i++) {
1029 1.1 drochner if (bus_dmamap_create(sc->sc_dmat, TXP_MAX_PKTLEN,
1030 1.68 thorpej TXP_MAXTXSEGS, TXP_MAX_SEGLEN, 0, BUS_DMA_NOWAIT,
1031 1.68 thorpej &sc->sc_txd[i].sd_map) != 0) {
1032 1.1 drochner for (j = 0; j < i; j++) {
1033 1.1 drochner bus_dmamap_destroy(sc->sc_dmat,
1034 1.1 drochner sc->sc_txd[j].sd_map);
1035 1.1 drochner sc->sc_txd[j].sd_map = NULL;
1036 1.1 drochner }
1037 1.1 drochner goto bail_txhiring;
1038 1.1 drochner }
1039 1.1 drochner }
1040 1.1 drochner
1041 1.1 drochner /* low priority tx ring */
1042 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_tx_desc) * TX_ENTRIES,
1043 1.1 drochner &sc->sc_txloring_dma, BUS_DMA_COHERENT)) {
1044 1.1 drochner printf(": can't allocate low tx ring\n");
1045 1.1 drochner goto bail_txhiring;
1046 1.1 drochner }
1047 1.44 msaitoh memset(sc->sc_txloring_dma.dma_vaddr, 0,
1048 1.44 msaitoh sizeof(struct txp_tx_desc) * TX_ENTRIES);
1049 1.65 thorpej boot->br_txlopri_lo =
1050 1.65 thorpej htole32(BUS_ADDR_LO32(sc->sc_txloring_dma.dma_paddr));
1051 1.65 thorpej boot->br_txlopri_hi =
1052 1.65 thorpej htole32(BUS_ADDR_HI32(sc->sc_txloring_dma.dma_paddr));
1053 1.1 drochner boot->br_txlopri_siz = htole32(TX_ENTRIES * sizeof(struct txp_tx_desc));
1054 1.1 drochner sc->sc_txlor.r_reg = TXP_H2A_3;
1055 1.65 thorpej sc->sc_txlor.r_desc =
1056 1.65 thorpej (struct txp_tx_desc *)sc->sc_txloring_dma.dma_vaddr;
1057 1.1 drochner sc->sc_txlor.r_cons = sc->sc_txlor.r_prod = sc->sc_txlor.r_cnt = 0;
1058 1.1 drochner sc->sc_txlor.r_off = &sc->sc_hostvar->hv_tx_lo_desc_read_idx;
1059 1.1 drochner
1060 1.1 drochner /* high priority rx ring */
1061 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_rx_desc) * RX_ENTRIES,
1062 1.1 drochner &sc->sc_rxhiring_dma, BUS_DMA_COHERENT)) {
1063 1.1 drochner printf(": can't allocate high rx ring\n");
1064 1.1 drochner goto bail_txloring;
1065 1.1 drochner }
1066 1.44 msaitoh memset(sc->sc_rxhiring_dma.dma_vaddr, 0,
1067 1.44 msaitoh sizeof(struct txp_rx_desc) * RX_ENTRIES);
1068 1.65 thorpej boot->br_rxhipri_lo =
1069 1.65 thorpej htole32(BUS_ADDR_LO32(sc->sc_rxhiring_dma.dma_paddr));
1070 1.65 thorpej boot->br_rxhipri_hi =
1071 1.65 thorpej htole32(BUS_ADDR_HI32(sc->sc_rxhiring_dma.dma_paddr));
1072 1.1 drochner boot->br_rxhipri_siz = htole32(RX_ENTRIES * sizeof(struct txp_rx_desc));
1073 1.1 drochner sc->sc_rxhir.r_desc =
1074 1.1 drochner (struct txp_rx_desc *)sc->sc_rxhiring_dma.dma_vaddr;
1075 1.1 drochner sc->sc_rxhir.r_roff = &sc->sc_hostvar->hv_rx_hi_read_idx;
1076 1.1 drochner sc->sc_rxhir.r_woff = &sc->sc_hostvar->hv_rx_hi_write_idx;
1077 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxhiring_dma.dma_map,
1078 1.1 drochner 0, sc->sc_rxhiring_dma.dma_map->dm_mapsize, BUS_DMASYNC_PREREAD);
1079 1.1 drochner
1080 1.1 drochner /* low priority ring */
1081 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_rx_desc) * RX_ENTRIES,
1082 1.1 drochner &sc->sc_rxloring_dma, BUS_DMA_COHERENT)) {
1083 1.1 drochner printf(": can't allocate low rx ring\n");
1084 1.1 drochner goto bail_rxhiring;
1085 1.1 drochner }
1086 1.44 msaitoh memset(sc->sc_rxloring_dma.dma_vaddr, 0,
1087 1.44 msaitoh sizeof(struct txp_rx_desc) * RX_ENTRIES);
1088 1.65 thorpej boot->br_rxlopri_lo =
1089 1.65 thorpej htole32(BUS_ADDR_LO32(sc->sc_rxloring_dma.dma_paddr));
1090 1.65 thorpej boot->br_rxlopri_hi =
1091 1.65 thorpej htole32(BUS_ADDR_HI32(sc->sc_rxloring_dma.dma_paddr));
1092 1.1 drochner boot->br_rxlopri_siz = htole32(RX_ENTRIES * sizeof(struct txp_rx_desc));
1093 1.1 drochner sc->sc_rxlor.r_desc =
1094 1.1 drochner (struct txp_rx_desc *)sc->sc_rxloring_dma.dma_vaddr;
1095 1.1 drochner sc->sc_rxlor.r_roff = &sc->sc_hostvar->hv_rx_lo_read_idx;
1096 1.1 drochner sc->sc_rxlor.r_woff = &sc->sc_hostvar->hv_rx_lo_write_idx;
1097 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxloring_dma.dma_map,
1098 1.1 drochner 0, sc->sc_rxloring_dma.dma_map->dm_mapsize, BUS_DMASYNC_PREREAD);
1099 1.1 drochner
1100 1.1 drochner /* command ring */
1101 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_cmd_desc) * CMD_ENTRIES,
1102 1.1 drochner &sc->sc_cmdring_dma, BUS_DMA_COHERENT)) {
1103 1.1 drochner printf(": can't allocate command ring\n");
1104 1.1 drochner goto bail_rxloring;
1105 1.1 drochner }
1106 1.44 msaitoh memset(sc->sc_cmdring_dma.dma_vaddr, 0,
1107 1.44 msaitoh sizeof(struct txp_cmd_desc) * CMD_ENTRIES);
1108 1.65 thorpej boot->br_cmd_lo = htole32(BUS_ADDR_LO32(sc->sc_cmdring_dma.dma_paddr));
1109 1.65 thorpej boot->br_cmd_hi = htole32(BUS_ADDR_HI32(sc->sc_cmdring_dma.dma_paddr));
1110 1.1 drochner boot->br_cmd_siz = htole32(CMD_ENTRIES * sizeof(struct txp_cmd_desc));
1111 1.1 drochner sc->sc_cmdring.base = (struct txp_cmd_desc *)sc->sc_cmdring_dma.dma_vaddr;
1112 1.1 drochner sc->sc_cmdring.size = CMD_ENTRIES * sizeof(struct txp_cmd_desc);
1113 1.1 drochner sc->sc_cmdring.lastwrite = 0;
1114 1.1 drochner
1115 1.1 drochner /* response ring */
1116 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_rsp_desc) * RSP_ENTRIES,
1117 1.1 drochner &sc->sc_rspring_dma, BUS_DMA_COHERENT)) {
1118 1.1 drochner printf(": can't allocate response ring\n");
1119 1.1 drochner goto bail_cmdring;
1120 1.1 drochner }
1121 1.44 msaitoh memset(sc->sc_rspring_dma.dma_vaddr, 0,
1122 1.44 msaitoh sizeof(struct txp_rsp_desc) * RSP_ENTRIES);
1123 1.65 thorpej boot->br_resp_lo = htole32(BUS_ADDR_LO32(sc->sc_rspring_dma.dma_paddr));
1124 1.65 thorpej boot->br_resp_hi = htole32(BUS_ADDR_HI32(sc->sc_rspring_dma.dma_paddr));
1125 1.1 drochner boot->br_resp_siz = htole32(CMD_ENTRIES * sizeof(struct txp_rsp_desc));
1126 1.1 drochner sc->sc_rspring.base = (struct txp_rsp_desc *)sc->sc_rspring_dma.dma_vaddr;
1127 1.1 drochner sc->sc_rspring.size = RSP_ENTRIES * sizeof(struct txp_rsp_desc);
1128 1.1 drochner sc->sc_rspring.lastwrite = 0;
1129 1.1 drochner
1130 1.1 drochner /* receive buffer ring */
1131 1.1 drochner if (txp_dma_malloc(sc, sizeof(struct txp_rxbuf_desc) * RXBUF_ENTRIES,
1132 1.1 drochner &sc->sc_rxbufring_dma, BUS_DMA_COHERENT)) {
1133 1.1 drochner printf(": can't allocate rx buffer ring\n");
1134 1.1 drochner goto bail_rspring;
1135 1.1 drochner }
1136 1.44 msaitoh memset(sc->sc_rxbufring_dma.dma_vaddr, 0,
1137 1.44 msaitoh sizeof(struct txp_rxbuf_desc) * RXBUF_ENTRIES);
1138 1.65 thorpej boot->br_rxbuf_lo = htole32(BUS_ADDR_LO32(sc->sc_rxbufring_dma.dma_paddr));
1139 1.65 thorpej boot->br_rxbuf_hi = htole32(BUS_ADDR_HI32(sc->sc_rxbufring_dma.dma_paddr));
1140 1.1 drochner boot->br_rxbuf_siz = htole32(RXBUF_ENTRIES * sizeof(struct txp_rxbuf_desc));
1141 1.1 drochner sc->sc_rxbufs = (struct txp_rxbuf_desc *)sc->sc_rxbufring_dma.dma_vaddr;
1142 1.15 christos for (nb = 0; nb < RXBUF_ENTRIES; nb++) {
1143 1.69 thorpej sd = &sc->sc_rxd[nb];
1144 1.70 thorpej
1145 1.15 christos /* stash away pointer */
1146 1.70 thorpej sc->sc_rxbufs[nb].rb_vaddrlo = txp_rxd_idx(sc, sd);
1147 1.1 drochner
1148 1.69 thorpej MGETHDR(sd->sd_mbuf, M_WAIT, MT_DATA);
1149 1.1 drochner if (sd->sd_mbuf == NULL) {
1150 1.1 drochner goto bail_rxbufring;
1151 1.1 drochner }
1152 1.1 drochner
1153 1.69 thorpej MCLGET(sd->sd_mbuf, M_WAIT);
1154 1.1 drochner if ((sd->sd_mbuf->m_flags & M_EXT) == 0) {
1155 1.1 drochner goto bail_rxbufring;
1156 1.1 drochner }
1157 1.1 drochner sd->sd_mbuf->m_pkthdr.len = sd->sd_mbuf->m_len = MCLBYTES;
1158 1.43 ozaki m_set_rcvif(sd->sd_mbuf, ifp);
1159 1.1 drochner if (bus_dmamap_create(sc->sc_dmat, TXP_MAX_PKTLEN, 1,
1160 1.69 thorpej TXP_MAX_PKTLEN, 0, BUS_DMA_WAITOK, &sd->sd_map)) {
1161 1.1 drochner goto bail_rxbufring;
1162 1.1 drochner }
1163 1.1 drochner if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map, sd->sd_mbuf,
1164 1.69 thorpej BUS_DMA_WAITOK)) {
1165 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, sd->sd_map);
1166 1.1 drochner goto bail_rxbufring;
1167 1.1 drochner }
1168 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
1169 1.1 drochner sd->sd_map->dm_mapsize, BUS_DMASYNC_PREREAD);
1170 1.1 drochner
1171 1.15 christos sc->sc_rxbufs[nb].rb_paddrlo =
1172 1.65 thorpej htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[0].ds_addr));
1173 1.15 christos sc->sc_rxbufs[nb].rb_paddrhi =
1174 1.65 thorpej htole32(BUS_ADDR_HI32(sd->sd_map->dm_segs[0].ds_addr));
1175 1.1 drochner }
1176 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_rxbufring_dma.dma_map,
1177 1.1 drochner 0, sc->sc_rxbufring_dma.dma_map->dm_mapsize,
1178 1.1 drochner BUS_DMASYNC_PREWRITE);
1179 1.1 drochner sc->sc_hostvar->hv_rx_buf_write_idx = htole32((RXBUF_ENTRIES - 1) *
1180 1.1 drochner sizeof(struct txp_rxbuf_desc));
1181 1.1 drochner
1182 1.1 drochner /* zero dma */
1183 1.53 msaitoh if (txp_dma_malloc(sc, sizeof(uint32_t), &sc->sc_zero_dma,
1184 1.1 drochner BUS_DMA_COHERENT)) {
1185 1.1 drochner printf(": can't allocate response ring\n");
1186 1.1 drochner goto bail_rxbufring;
1187 1.1 drochner }
1188 1.53 msaitoh memset(sc->sc_zero_dma.dma_vaddr, 0, sizeof(uint32_t));
1189 1.65 thorpej boot->br_zero_lo = htole32(BUS_ADDR_LO32(sc->sc_zero_dma.dma_paddr));
1190 1.65 thorpej boot->br_zero_hi = htole32(BUS_ADDR_HI32(sc->sc_zero_dma.dma_paddr));
1191 1.1 drochner
1192 1.1 drochner /* See if it's waiting for boot, and try to boot it */
1193 1.1 drochner for (i = 0; i < 10000; i++) {
1194 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
1195 1.1 drochner if (r == STAT_WAITING_FOR_BOOT)
1196 1.1 drochner break;
1197 1.1 drochner DELAY(50);
1198 1.1 drochner }
1199 1.1 drochner if (r != STAT_WAITING_FOR_BOOT) {
1200 1.1 drochner printf(": not waiting for boot\n");
1201 1.1 drochner goto bail;
1202 1.1 drochner }
1203 1.65 thorpej WRITE_REG(sc, TXP_H2A_2, BUS_ADDR_HI32(sc->sc_boot_dma.dma_paddr));
1204 1.65 thorpej WRITE_REG(sc, TXP_H2A_1, BUS_ADDR_LO32(sc->sc_boot_dma.dma_paddr));
1205 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_REGISTER_BOOT_RECORD);
1206 1.1 drochner
1207 1.1 drochner /* See if it booted */
1208 1.1 drochner for (i = 0; i < 10000; i++) {
1209 1.1 drochner r = READ_REG(sc, TXP_A2H_0);
1210 1.1 drochner if (r == STAT_RUNNING)
1211 1.1 drochner break;
1212 1.1 drochner DELAY(50);
1213 1.1 drochner }
1214 1.1 drochner if (r != STAT_RUNNING) {
1215 1.1 drochner printf(": fw not running\n");
1216 1.1 drochner goto bail;
1217 1.1 drochner }
1218 1.1 drochner
1219 1.1 drochner /* Clear TX and CMD ring write registers */
1220 1.1 drochner WRITE_REG(sc, TXP_H2A_1, TXP_BOOTCMD_NULL);
1221 1.1 drochner WRITE_REG(sc, TXP_H2A_2, TXP_BOOTCMD_NULL);
1222 1.1 drochner WRITE_REG(sc, TXP_H2A_3, TXP_BOOTCMD_NULL);
1223 1.1 drochner WRITE_REG(sc, TXP_H2A_0, TXP_BOOTCMD_NULL);
1224 1.1 drochner
1225 1.1 drochner return (0);
1226 1.1 drochner
1227 1.1 drochner bail:
1228 1.1 drochner txp_dma_free(sc, &sc->sc_zero_dma);
1229 1.1 drochner bail_rxbufring:
1230 1.15 christos if (nb == RXBUF_ENTRIES)
1231 1.15 christos nb--;
1232 1.15 christos for (i = 0; i <= nb; i++) {
1233 1.34 tsutsui memcpy(&sd, __UNVOLATILE(&sc->sc_rxbufs[i].rb_vaddrlo),
1234 1.15 christos sizeof(sd));
1235 1.69 thorpej /* XXXJRT */
1236 1.15 christos }
1237 1.1 drochner txp_dma_free(sc, &sc->sc_rxbufring_dma);
1238 1.1 drochner bail_rspring:
1239 1.1 drochner txp_dma_free(sc, &sc->sc_rspring_dma);
1240 1.1 drochner bail_cmdring:
1241 1.1 drochner txp_dma_free(sc, &sc->sc_cmdring_dma);
1242 1.1 drochner bail_rxloring:
1243 1.1 drochner txp_dma_free(sc, &sc->sc_rxloring_dma);
1244 1.1 drochner bail_rxhiring:
1245 1.1 drochner txp_dma_free(sc, &sc->sc_rxhiring_dma);
1246 1.1 drochner bail_txloring:
1247 1.1 drochner txp_dma_free(sc, &sc->sc_txloring_dma);
1248 1.1 drochner bail_txhiring:
1249 1.1 drochner txp_dma_free(sc, &sc->sc_txhiring_dma);
1250 1.1 drochner bail_host:
1251 1.1 drochner txp_dma_free(sc, &sc->sc_host_dma);
1252 1.1 drochner bail_boot:
1253 1.1 drochner txp_dma_free(sc, &sc->sc_boot_dma);
1254 1.1 drochner return (-1);
1255 1.1 drochner }
1256 1.1 drochner
1257 1.62 maxv static int
1258 1.44 msaitoh txp_dma_malloc(struct txp_softc *sc, bus_size_t size,
1259 1.44 msaitoh struct txp_dma_alloc *dma, int mapflags)
1260 1.1 drochner {
1261 1.1 drochner int r;
1262 1.1 drochner
1263 1.1 drochner if ((r = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0,
1264 1.1 drochner &dma->dma_seg, 1, &dma->dma_nseg, 0)) != 0)
1265 1.1 drochner goto fail_0;
1266 1.1 drochner
1267 1.1 drochner if ((r = bus_dmamem_map(sc->sc_dmat, &dma->dma_seg, dma->dma_nseg,
1268 1.1 drochner size, &dma->dma_vaddr, mapflags | BUS_DMA_NOWAIT)) != 0)
1269 1.1 drochner goto fail_1;
1270 1.1 drochner
1271 1.1 drochner if ((r = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
1272 1.1 drochner BUS_DMA_NOWAIT, &dma->dma_map)) != 0)
1273 1.1 drochner goto fail_2;
1274 1.1 drochner
1275 1.1 drochner if ((r = bus_dmamap_load(sc->sc_dmat, dma->dma_map, dma->dma_vaddr,
1276 1.1 drochner size, NULL, BUS_DMA_NOWAIT)) != 0)
1277 1.1 drochner goto fail_3;
1278 1.1 drochner
1279 1.1 drochner dma->dma_paddr = dma->dma_map->dm_segs[0].ds_addr;
1280 1.1 drochner return (0);
1281 1.1 drochner
1282 1.1 drochner fail_3:
1283 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, dma->dma_map);
1284 1.1 drochner fail_2:
1285 1.1 drochner bus_dmamem_unmap(sc->sc_dmat, dma->dma_vaddr, size);
1286 1.1 drochner fail_1:
1287 1.1 drochner bus_dmamem_free(sc->sc_dmat, &dma->dma_seg, dma->dma_nseg);
1288 1.1 drochner fail_0:
1289 1.1 drochner return (r);
1290 1.1 drochner }
1291 1.1 drochner
1292 1.62 maxv static void
1293 1.29 dsl txp_dma_free(struct txp_softc *sc, struct txp_dma_alloc *dma)
1294 1.1 drochner {
1295 1.54 msaitoh bus_size_t mapsize = dma->dma_map->dm_mapsize;
1296 1.54 msaitoh
1297 1.1 drochner bus_dmamap_unload(sc->sc_dmat, dma->dma_map);
1298 1.54 msaitoh bus_dmamem_unmap(sc->sc_dmat, dma->dma_vaddr, mapsize);
1299 1.1 drochner bus_dmamem_free(sc->sc_dmat, &dma->dma_seg, dma->dma_nseg);
1300 1.1 drochner bus_dmamap_destroy(sc->sc_dmat, dma->dma_map);
1301 1.1 drochner }
1302 1.1 drochner
1303 1.62 maxv static int
1304 1.27 dyoung txp_ioctl(struct ifnet *ifp, u_long command, void *data)
1305 1.1 drochner {
1306 1.1 drochner struct txp_softc *sc = ifp->if_softc;
1307 1.1 drochner struct ifaddr *ifa = (struct ifaddr *)data;
1308 1.1 drochner int s, error = 0;
1309 1.1 drochner
1310 1.1 drochner s = splnet();
1311 1.1 drochner
1312 1.1 drochner #if 0
1313 1.1 drochner if ((error = ether_ioctl(ifp, &sc->sc_arpcom, command, data)) > 0) {
1314 1.1 drochner splx(s);
1315 1.1 drochner return error;
1316 1.1 drochner }
1317 1.1 drochner #endif
1318 1.1 drochner
1319 1.55 msaitoh switch (command) {
1320 1.27 dyoung case SIOCINITIFADDR:
1321 1.1 drochner ifp->if_flags |= IFF_UP;
1322 1.27 dyoung txp_init(sc);
1323 1.1 drochner switch (ifa->ifa_addr->sa_family) {
1324 1.1 drochner #ifdef INET
1325 1.1 drochner case AF_INET:
1326 1.1 drochner arp_ifinit(ifp, ifa);
1327 1.1 drochner break;
1328 1.1 drochner #endif /* INET */
1329 1.1 drochner default:
1330 1.1 drochner break;
1331 1.1 drochner }
1332 1.1 drochner break;
1333 1.1 drochner case SIOCSIFFLAGS:
1334 1.27 dyoung if ((error = ifioctl_common(ifp, command, data)) != 0)
1335 1.27 dyoung break;
1336 1.1 drochner if (ifp->if_flags & IFF_UP) {
1337 1.1 drochner txp_init(sc);
1338 1.1 drochner } else {
1339 1.1 drochner if (ifp->if_flags & IFF_RUNNING)
1340 1.1 drochner txp_stop(sc);
1341 1.1 drochner }
1342 1.1 drochner break;
1343 1.1 drochner case SIOCADDMULTI:
1344 1.1 drochner case SIOCDELMULTI:
1345 1.23 dyoung if ((error = ether_ioctl(ifp, command, data)) != ENETRESET)
1346 1.23 dyoung break;
1347 1.23 dyoung
1348 1.23 dyoung error = 0;
1349 1.23 dyoung
1350 1.23 dyoung if (command != SIOCADDMULTI && command != SIOCDELMULTI)
1351 1.23 dyoung ;
1352 1.23 dyoung else if (ifp->if_flags & IFF_RUNNING) {
1353 1.1 drochner /*
1354 1.1 drochner * Multicast list has changed; set the hardware
1355 1.1 drochner * filter accordingly.
1356 1.1 drochner */
1357 1.23 dyoung txp_set_filter(sc);
1358 1.1 drochner }
1359 1.1 drochner break;
1360 1.1 drochner default:
1361 1.27 dyoung error = ether_ioctl(ifp, command, data);
1362 1.1 drochner break;
1363 1.1 drochner }
1364 1.1 drochner
1365 1.1 drochner splx(s);
1366 1.1 drochner
1367 1.55 msaitoh return (error);
1368 1.1 drochner }
1369 1.1 drochner
1370 1.62 maxv static void
1371 1.29 dsl txp_init(struct txp_softc *sc)
1372 1.1 drochner {
1373 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
1374 1.1 drochner int s;
1375 1.1 drochner
1376 1.1 drochner txp_stop(sc);
1377 1.1 drochner
1378 1.1 drochner s = splnet();
1379 1.1 drochner
1380 1.1 drochner txp_set_filter(sc);
1381 1.1 drochner
1382 1.1 drochner txp_command(sc, TXP_CMD_TX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1383 1.1 drochner txp_command(sc, TXP_CMD_RX_ENABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1384 1.1 drochner
1385 1.1 drochner WRITE_REG(sc, TXP_IER, TXP_INT_RESERVED | TXP_INT_SELF |
1386 1.1 drochner TXP_INT_A2H_7 | TXP_INT_A2H_6 | TXP_INT_A2H_5 | TXP_INT_A2H_4 |
1387 1.1 drochner TXP_INT_A2H_2 | TXP_INT_A2H_1 | TXP_INT_A2H_0 |
1388 1.1 drochner TXP_INT_DMA3 | TXP_INT_DMA2 | TXP_INT_DMA1 | TXP_INT_DMA0 |
1389 1.1 drochner TXP_INT_PCI_TABORT | TXP_INT_PCI_MABORT | TXP_INT_LATCH);
1390 1.1 drochner WRITE_REG(sc, TXP_IMR, TXP_INT_A2H_3);
1391 1.1 drochner
1392 1.1 drochner ifp->if_flags |= IFF_RUNNING;
1393 1.1 drochner ifp->if_flags &= ~IFF_OACTIVE;
1394 1.1 drochner ifp->if_timer = 0;
1395 1.1 drochner
1396 1.1 drochner if (!callout_pending(&sc->sc_tick))
1397 1.1 drochner callout_schedule(&sc->sc_tick, hz);
1398 1.1 drochner
1399 1.1 drochner splx(s);
1400 1.1 drochner }
1401 1.1 drochner
1402 1.62 maxv static void
1403 1.29 dsl txp_tick(void *vsc)
1404 1.1 drochner {
1405 1.1 drochner struct txp_softc *sc = vsc;
1406 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
1407 1.1 drochner struct txp_rsp_desc *rsp = NULL;
1408 1.1 drochner struct txp_ext_desc *ext;
1409 1.1 drochner int s;
1410 1.1 drochner
1411 1.1 drochner s = splnet();
1412 1.1 drochner txp_rxbuf_reclaim(sc);
1413 1.1 drochner
1414 1.1 drochner if (txp_command2(sc, TXP_CMD_READ_STATISTICS, 0, 0, 0, NULL, 0,
1415 1.1 drochner &rsp, 1))
1416 1.1 drochner goto out;
1417 1.1 drochner if (rsp->rsp_numdesc != 6)
1418 1.1 drochner goto out;
1419 1.1 drochner if (txp_command(sc, TXP_CMD_CLEAR_STATISTICS, 0, 0, 0,
1420 1.1 drochner NULL, NULL, NULL, 1))
1421 1.1 drochner goto out;
1422 1.1 drochner ext = (struct txp_ext_desc *)(rsp + 1);
1423 1.1 drochner
1424 1.63 thorpej net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
1425 1.63 thorpej if_statadd_ref(nsr, if_ierrors,
1426 1.63 thorpej ext[3].ext_2 + ext[3].ext_3 + ext[3].ext_4 +
1427 1.63 thorpej ext[4].ext_1 + ext[4].ext_4);
1428 1.63 thorpej if_statadd_ref(nsr, if_oerrors,
1429 1.63 thorpej ext[0].ext_1 + ext[1].ext_1 + ext[1].ext_4 + ext[2].ext_1);
1430 1.63 thorpej if_statadd_ref(nsr, if_collisions,
1431 1.63 thorpej ext[0].ext_2 + ext[0].ext_3 + ext[1].ext_2 + ext[1].ext_3);
1432 1.63 thorpej if_statadd_ref(nsr, if_opackets, rsp->rsp_par2);
1433 1.63 thorpej IF_STAT_PUTREF(ifp);
1434 1.1 drochner
1435 1.1 drochner out:
1436 1.1 drochner if (rsp != NULL)
1437 1.1 drochner free(rsp, M_DEVBUF);
1438 1.1 drochner
1439 1.1 drochner splx(s);
1440 1.1 drochner callout_schedule(&sc->sc_tick, hz);
1441 1.1 drochner }
1442 1.1 drochner
1443 1.62 maxv static void
1444 1.29 dsl txp_start(struct ifnet *ifp)
1445 1.1 drochner {
1446 1.1 drochner struct txp_softc *sc = ifp->if_softc;
1447 1.1 drochner struct txp_tx_ring *r = &sc->sc_txhir;
1448 1.1 drochner struct txp_tx_desc *txd;
1449 1.1 drochner int txdidx;
1450 1.1 drochner struct txp_frag_desc *fxd;
1451 1.1 drochner struct mbuf *m, *mnew;
1452 1.1 drochner struct txp_swdesc *sd;
1453 1.68 thorpej uint32_t prod, cnt, i;
1454 1.68 thorpej int error;
1455 1.1 drochner
1456 1.1 drochner if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
1457 1.1 drochner return;
1458 1.1 drochner
1459 1.1 drochner prod = r->r_prod;
1460 1.1 drochner cnt = r->r_cnt;
1461 1.1 drochner
1462 1.1 drochner while (1) {
1463 1.68 thorpej if (cnt >= TX_ENTRIES - TXP_MAXTXSEGS - 4) {
1464 1.68 thorpej ifp->if_flags |= IFF_OACTIVE;
1465 1.68 thorpej break;
1466 1.68 thorpej }
1467 1.68 thorpej
1468 1.1 drochner IFQ_POLL(&ifp->if_snd, m);
1469 1.1 drochner if (m == NULL)
1470 1.1 drochner break;
1471 1.1 drochner mnew = NULL;
1472 1.1 drochner
1473 1.1 drochner sd = sc->sc_txd + prod;
1474 1.1 drochner
1475 1.68 thorpej /*
1476 1.68 thorpej * Load the DMA map. If this fails, the packet either
1477 1.68 thorpej * didn't fit in the alloted number of segments, or we
1478 1.68 thorpej * were short on resources. In this case, we'll copy
1479 1.68 thorpej * and try again.
1480 1.68 thorpej */
1481 1.1 drochner if (bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map, m,
1482 1.68 thorpej BUS_DMA_NOWAIT) != 0) {
1483 1.1 drochner MGETHDR(mnew, M_DONTWAIT, MT_DATA);
1484 1.68 thorpej if (mnew == NULL) {
1485 1.68 thorpej printf("%s: unable to allocate Tx mbuf\n",
1486 1.68 thorpej device_xname(sc->sc_dev));
1487 1.68 thorpej break;
1488 1.68 thorpej }
1489 1.72 thorpej MCLAIM(mnew, &sc->sc_arpcom.ec_tx_mowner);
1490 1.1 drochner if (m->m_pkthdr.len > MHLEN) {
1491 1.1 drochner MCLGET(mnew, M_DONTWAIT);
1492 1.1 drochner if ((mnew->m_flags & M_EXT) == 0) {
1493 1.68 thorpej printf("%s: unable to allocate Tx "
1494 1.68 thorpej "cluster\n",
1495 1.68 thorpej device_xname(sc->sc_dev));
1496 1.1 drochner m_freem(mnew);
1497 1.68 thorpej break;
1498 1.1 drochner }
1499 1.1 drochner }
1500 1.19 christos m_copydata(m, 0, m->m_pkthdr.len, mtod(mnew, void *));
1501 1.1 drochner mnew->m_pkthdr.len = mnew->m_len = m->m_pkthdr.len;
1502 1.68 thorpej error = bus_dmamap_load_mbuf(sc->sc_dmat, sd->sd_map,
1503 1.68 thorpej mnew, BUS_DMA_NOWAIT);
1504 1.68 thorpej if (error) {
1505 1.68 thorpej printf("%s: unable to load Tx buffer, "
1506 1.68 thorpej "error = %d\n", device_xname(sc->sc_dev),
1507 1.68 thorpej error);
1508 1.68 thorpej m_freem(mnew);
1509 1.68 thorpej break;
1510 1.68 thorpej }
1511 1.68 thorpej }
1512 1.68 thorpej
1513 1.68 thorpej IFQ_DEQUEUE(&ifp->if_snd, m);
1514 1.68 thorpej if (mnew != NULL) {
1515 1.1 drochner m_freem(m);
1516 1.1 drochner m = mnew;
1517 1.1 drochner }
1518 1.1 drochner
1519 1.68 thorpej /*
1520 1.68 thorpej * WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET.
1521 1.68 thorpej */
1522 1.68 thorpej
1523 1.68 thorpej sd->sd_mbuf = m;
1524 1.1 drochner
1525 1.1 drochner txd = r->r_desc + prod;
1526 1.1 drochner txdidx = prod;
1527 1.1 drochner txd->tx_flags = TX_FLAGS_TYPE_DATA;
1528 1.1 drochner txd->tx_numdesc = 0;
1529 1.72 thorpej txd->tx_addrlo = txp_txd_idx(sc, sd);
1530 1.1 drochner txd->tx_addrhi = 0;
1531 1.1 drochner txd->tx_totlen = m->m_pkthdr.len;
1532 1.1 drochner txd->tx_pflags = 0;
1533 1.1 drochner txd->tx_numdesc = sd->sd_map->dm_nsegs;
1534 1.1 drochner
1535 1.1 drochner if (++prod == TX_ENTRIES)
1536 1.1 drochner prod = 0;
1537 1.72 thorpej cnt++;
1538 1.1 drochner
1539 1.48 knakahar if (vlan_has_tag(m))
1540 1.1 drochner txd->tx_pflags = TX_PFLAGS_VLAN |
1541 1.48 knakahar (htons(vlan_get_tag(m)) << TX_PFLAGS_VLANTAG_S);
1542 1.1 drochner
1543 1.2 drochner if (m->m_pkthdr.csum_flags & M_CSUM_IPv4)
1544 1.1 drochner txd->tx_pflags |= TX_PFLAGS_IPCKSUM;
1545 1.1 drochner #ifdef TRY_TX_TCP_CSUM
1546 1.2 drochner if (m->m_pkthdr.csum_flags & M_CSUM_TCPv4)
1547 1.1 drochner txd->tx_pflags |= TX_PFLAGS_TCPCKSUM;
1548 1.1 drochner #endif
1549 1.1 drochner #ifdef TRY_TX_UDP_CSUM
1550 1.2 drochner if (m->m_pkthdr.csum_flags & M_CSUM_UDPv4)
1551 1.1 drochner txd->tx_pflags |= TX_PFLAGS_UDPCKSUM;
1552 1.1 drochner #endif
1553 1.1 drochner
1554 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sd->sd_map, 0,
1555 1.1 drochner sd->sd_map->dm_mapsize, BUS_DMASYNC_PREWRITE);
1556 1.1 drochner
1557 1.1 drochner fxd = (struct txp_frag_desc *)(r->r_desc + prod);
1558 1.1 drochner for (i = 0; i < sd->sd_map->dm_nsegs; i++) {
1559 1.1 drochner fxd->frag_flags = FRAG_FLAGS_TYPE_FRAG |
1560 1.1 drochner FRAG_FLAGS_VALID;
1561 1.1 drochner fxd->frag_rsvd1 = 0;
1562 1.65 thorpej fxd->frag_len = htole16(sd->sd_map->dm_segs[i].ds_len);
1563 1.1 drochner fxd->frag_addrlo =
1564 1.65 thorpej htole32(BUS_ADDR_LO32(sd->sd_map->dm_segs[i].ds_addr));
1565 1.1 drochner fxd->frag_addrhi =
1566 1.65 thorpej htole32(BUS_ADDR_HI32(sd->sd_map->dm_segs[i].ds_addr));
1567 1.1 drochner fxd->frag_rsvd2 = 0;
1568 1.1 drochner
1569 1.1 drochner bus_dmamap_sync(sc->sc_dmat,
1570 1.1 drochner sc->sc_txhiring_dma.dma_map,
1571 1.1 drochner prod * sizeof(struct txp_frag_desc),
1572 1.1 drochner sizeof(struct txp_frag_desc), BUS_DMASYNC_PREWRITE);
1573 1.1 drochner
1574 1.1 drochner if (++prod == TX_ENTRIES) {
1575 1.1 drochner fxd = (struct txp_frag_desc *)r->r_desc;
1576 1.1 drochner prod = 0;
1577 1.1 drochner } else
1578 1.1 drochner fxd++;
1579 1.72 thorpej cnt++;
1580 1.1 drochner }
1581 1.1 drochner
1582 1.1 drochner ifp->if_timer = 5;
1583 1.1 drochner
1584 1.49 msaitoh bpf_mtap(ifp, m, BPF_D_OUT);
1585 1.1 drochner
1586 1.1 drochner txd->tx_flags |= TX_FLAGS_VALID;
1587 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_txhiring_dma.dma_map,
1588 1.1 drochner txdidx * sizeof(struct txp_tx_desc),
1589 1.1 drochner sizeof(struct txp_tx_desc), BUS_DMASYNC_PREWRITE);
1590 1.1 drochner
1591 1.1 drochner #if 0
1592 1.1 drochner {
1593 1.1 drochner struct mbuf *mx;
1594 1.1 drochner int i;
1595 1.1 drochner
1596 1.1 drochner printf("txd: flags 0x%x ndesc %d totlen %d pflags 0x%x\n",
1597 1.1 drochner txd->tx_flags, txd->tx_numdesc, txd->tx_totlen,
1598 1.1 drochner txd->tx_pflags);
1599 1.1 drochner for (mx = m; mx != NULL; mx = mx->m_next) {
1600 1.1 drochner for (i = 0; i < mx->m_len; i++) {
1601 1.1 drochner printf(":%02x",
1602 1.53 msaitoh (uint8_t)m->m_data[i]);
1603 1.1 drochner }
1604 1.1 drochner }
1605 1.1 drochner printf("\n");
1606 1.1 drochner }
1607 1.1 drochner #endif
1608 1.1 drochner
1609 1.1 drochner WRITE_REG(sc, r->r_reg, TXP_IDX2OFFSET(prod));
1610 1.1 drochner }
1611 1.1 drochner
1612 1.1 drochner r->r_prod = prod;
1613 1.1 drochner r->r_cnt = cnt;
1614 1.1 drochner }
1615 1.1 drochner
1616 1.1 drochner /*
1617 1.1 drochner * Handle simple commands sent to the typhoon
1618 1.1 drochner */
1619 1.62 maxv static int
1620 1.53 msaitoh txp_command(struct txp_softc *sc, uint16_t id, uint16_t in1, uint32_t in2,
1621 1.53 msaitoh uint32_t in3, uint16_t *out1, uint32_t *out2, uint32_t *out3, int wait)
1622 1.1 drochner {
1623 1.1 drochner struct txp_rsp_desc *rsp = NULL;
1624 1.1 drochner
1625 1.1 drochner if (txp_command2(sc, id, in1, in2, in3, NULL, 0, &rsp, wait))
1626 1.1 drochner return (-1);
1627 1.1 drochner
1628 1.1 drochner if (!wait)
1629 1.1 drochner return (0);
1630 1.1 drochner
1631 1.1 drochner if (out1 != NULL)
1632 1.1 drochner *out1 = le16toh(rsp->rsp_par1);
1633 1.1 drochner if (out2 != NULL)
1634 1.1 drochner *out2 = le32toh(rsp->rsp_par2);
1635 1.1 drochner if (out3 != NULL)
1636 1.1 drochner *out3 = le32toh(rsp->rsp_par3);
1637 1.1 drochner free(rsp, M_DEVBUF);
1638 1.1 drochner return (0);
1639 1.1 drochner }
1640 1.1 drochner
1641 1.62 maxv static int
1642 1.53 msaitoh txp_command2(struct txp_softc *sc, uint16_t id, uint16_t in1, uint32_t in2,
1643 1.53 msaitoh uint32_t in3, struct txp_ext_desc *in_extp, uint8_t in_extn,
1644 1.44 msaitoh struct txp_rsp_desc **rspp, int wait)
1645 1.1 drochner {
1646 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
1647 1.1 drochner struct txp_cmd_desc *cmd;
1648 1.1 drochner struct txp_ext_desc *ext;
1649 1.53 msaitoh uint32_t idx, i;
1650 1.53 msaitoh uint16_t seq;
1651 1.1 drochner
1652 1.1 drochner if (txp_cmd_desc_numfree(sc) < (in_extn + 1)) {
1653 1.1 drochner printf("%s: no free cmd descriptors\n", TXP_DEVNAME(sc));
1654 1.1 drochner return (-1);
1655 1.1 drochner }
1656 1.1 drochner
1657 1.1 drochner idx = sc->sc_cmdring.lastwrite;
1658 1.53 msaitoh cmd = (struct txp_cmd_desc *)(((uint8_t *)sc->sc_cmdring.base) + idx);
1659 1.32 cegger memset(cmd, 0, sizeof(*cmd));
1660 1.1 drochner
1661 1.1 drochner cmd->cmd_numdesc = in_extn;
1662 1.1 drochner seq = sc->sc_seq++;
1663 1.1 drochner cmd->cmd_seq = htole16(seq);
1664 1.1 drochner cmd->cmd_id = htole16(id);
1665 1.1 drochner cmd->cmd_par1 = htole16(in1);
1666 1.1 drochner cmd->cmd_par2 = htole32(in2);
1667 1.1 drochner cmd->cmd_par3 = htole32(in3);
1668 1.1 drochner cmd->cmd_flags = CMD_FLAGS_TYPE_CMD |
1669 1.1 drochner (wait ? CMD_FLAGS_RESP : 0) | CMD_FLAGS_VALID;
1670 1.1 drochner
1671 1.1 drochner idx += sizeof(struct txp_cmd_desc);
1672 1.1 drochner if (idx == sc->sc_cmdring.size)
1673 1.1 drochner idx = 0;
1674 1.1 drochner
1675 1.1 drochner for (i = 0; i < in_extn; i++) {
1676 1.53 msaitoh ext = (struct txp_ext_desc *)(((uint8_t *)sc->sc_cmdring.base) + idx);
1677 1.34 tsutsui memcpy(ext, in_extp, sizeof(struct txp_ext_desc));
1678 1.1 drochner in_extp++;
1679 1.1 drochner idx += sizeof(struct txp_cmd_desc);
1680 1.1 drochner if (idx == sc->sc_cmdring.size)
1681 1.1 drochner idx = 0;
1682 1.1 drochner }
1683 1.1 drochner
1684 1.1 drochner sc->sc_cmdring.lastwrite = idx;
1685 1.1 drochner
1686 1.1 drochner WRITE_REG(sc, TXP_H2A_2, sc->sc_cmdring.lastwrite);
1687 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
1688 1.1 drochner sizeof(struct txp_hostvar), BUS_DMASYNC_PREREAD);
1689 1.1 drochner
1690 1.1 drochner if (!wait)
1691 1.1 drochner return (0);
1692 1.1 drochner
1693 1.1 drochner for (i = 0; i < 10000; i++) {
1694 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
1695 1.1 drochner sizeof(struct txp_hostvar), BUS_DMASYNC_POSTREAD);
1696 1.1 drochner idx = le32toh(hv->hv_resp_read_idx);
1697 1.1 drochner if (idx != le32toh(hv->hv_resp_write_idx)) {
1698 1.1 drochner *rspp = NULL;
1699 1.1 drochner if (txp_response(sc, idx, id, seq, rspp))
1700 1.1 drochner return (-1);
1701 1.1 drochner if (*rspp != NULL)
1702 1.1 drochner break;
1703 1.1 drochner }
1704 1.1 drochner bus_dmamap_sync(sc->sc_dmat, sc->sc_host_dma.dma_map, 0,
1705 1.1 drochner sizeof(struct txp_hostvar), BUS_DMASYNC_PREREAD);
1706 1.1 drochner DELAY(50);
1707 1.1 drochner }
1708 1.1 drochner if (i == 1000 || (*rspp) == NULL) {
1709 1.1 drochner printf("%s: 0x%x command failed\n", TXP_DEVNAME(sc), id);
1710 1.1 drochner return (-1);
1711 1.1 drochner }
1712 1.1 drochner
1713 1.1 drochner return (0);
1714 1.1 drochner }
1715 1.1 drochner
1716 1.62 maxv static int
1717 1.53 msaitoh txp_response(struct txp_softc *sc, uint32_t ridx, uint16_t id, uint16_t seq,
1718 1.44 msaitoh struct txp_rsp_desc **rspp)
1719 1.1 drochner {
1720 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
1721 1.1 drochner struct txp_rsp_desc *rsp;
1722 1.1 drochner
1723 1.1 drochner while (ridx != le32toh(hv->hv_resp_write_idx)) {
1724 1.53 msaitoh rsp = (struct txp_rsp_desc *)(((uint8_t *)sc->sc_rspring.base) + ridx);
1725 1.1 drochner
1726 1.1 drochner if (id == le16toh(rsp->rsp_id) && le16toh(rsp->rsp_seq) == seq) {
1727 1.1 drochner *rspp = (struct txp_rsp_desc *)malloc(
1728 1.1 drochner sizeof(struct txp_rsp_desc) * (rsp->rsp_numdesc + 1),
1729 1.1 drochner M_DEVBUF, M_NOWAIT);
1730 1.1 drochner if ((*rspp) == NULL)
1731 1.1 drochner return (-1);
1732 1.1 drochner txp_rsp_fixup(sc, rsp, *rspp);
1733 1.1 drochner return (0);
1734 1.1 drochner }
1735 1.1 drochner
1736 1.1 drochner if (rsp->rsp_flags & RSP_FLAGS_ERROR) {
1737 1.1 drochner printf("%s: response error: id 0x%x\n",
1738 1.1 drochner TXP_DEVNAME(sc), le16toh(rsp->rsp_id));
1739 1.1 drochner txp_rsp_fixup(sc, rsp, NULL);
1740 1.1 drochner ridx = le32toh(hv->hv_resp_read_idx);
1741 1.1 drochner continue;
1742 1.1 drochner }
1743 1.1 drochner
1744 1.1 drochner switch (le16toh(rsp->rsp_id)) {
1745 1.1 drochner case TXP_CMD_CYCLE_STATISTICS:
1746 1.1 drochner case TXP_CMD_MEDIA_STATUS_READ:
1747 1.1 drochner break;
1748 1.1 drochner case TXP_CMD_HELLO_RESPONSE:
1749 1.1 drochner printf("%s: hello\n", TXP_DEVNAME(sc));
1750 1.1 drochner break;
1751 1.1 drochner default:
1752 1.1 drochner printf("%s: unknown id(0x%x)\n", TXP_DEVNAME(sc),
1753 1.1 drochner le16toh(rsp->rsp_id));
1754 1.1 drochner }
1755 1.1 drochner
1756 1.1 drochner txp_rsp_fixup(sc, rsp, NULL);
1757 1.1 drochner ridx = le32toh(hv->hv_resp_read_idx);
1758 1.1 drochner hv->hv_resp_read_idx = le32toh(ridx);
1759 1.1 drochner }
1760 1.1 drochner
1761 1.1 drochner return (0);
1762 1.1 drochner }
1763 1.1 drochner
1764 1.62 maxv static void
1765 1.44 msaitoh txp_rsp_fixup(struct txp_softc *sc, struct txp_rsp_desc *rsp,
1766 1.44 msaitoh struct txp_rsp_desc *dst)
1767 1.1 drochner {
1768 1.1 drochner struct txp_rsp_desc *src = rsp;
1769 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
1770 1.53 msaitoh uint32_t i, ridx;
1771 1.1 drochner
1772 1.1 drochner ridx = le32toh(hv->hv_resp_read_idx);
1773 1.1 drochner
1774 1.1 drochner for (i = 0; i < rsp->rsp_numdesc + 1; i++) {
1775 1.1 drochner if (dst != NULL)
1776 1.34 tsutsui memcpy(dst++, src, sizeof(struct txp_rsp_desc));
1777 1.1 drochner ridx += sizeof(struct txp_rsp_desc);
1778 1.1 drochner if (ridx == sc->sc_rspring.size) {
1779 1.1 drochner src = sc->sc_rspring.base;
1780 1.1 drochner ridx = 0;
1781 1.1 drochner } else
1782 1.1 drochner src++;
1783 1.1 drochner sc->sc_rspring.lastwrite = ridx;
1784 1.1 drochner hv->hv_resp_read_idx = htole32(ridx);
1785 1.1 drochner }
1786 1.10 perry
1787 1.1 drochner hv->hv_resp_read_idx = htole32(ridx);
1788 1.1 drochner }
1789 1.1 drochner
1790 1.62 maxv static int
1791 1.29 dsl txp_cmd_desc_numfree(struct txp_softc *sc)
1792 1.1 drochner {
1793 1.1 drochner struct txp_hostvar *hv = sc->sc_hostvar;
1794 1.1 drochner struct txp_boot_record *br = sc->sc_boot;
1795 1.53 msaitoh uint32_t widx, ridx, nfree;
1796 1.1 drochner
1797 1.1 drochner widx = sc->sc_cmdring.lastwrite;
1798 1.1 drochner ridx = le32toh(hv->hv_cmd_read_idx);
1799 1.1 drochner
1800 1.1 drochner if (widx == ridx) {
1801 1.1 drochner /* Ring is completely free */
1802 1.1 drochner nfree = le32toh(br->br_cmd_siz) - sizeof(struct txp_cmd_desc);
1803 1.1 drochner } else {
1804 1.1 drochner if (widx > ridx)
1805 1.1 drochner nfree = le32toh(br->br_cmd_siz) -
1806 1.1 drochner (widx - ridx + sizeof(struct txp_cmd_desc));
1807 1.1 drochner else
1808 1.1 drochner nfree = ridx - widx - sizeof(struct txp_cmd_desc);
1809 1.1 drochner }
1810 1.1 drochner
1811 1.1 drochner return (nfree / sizeof(struct txp_cmd_desc));
1812 1.1 drochner }
1813 1.1 drochner
1814 1.62 maxv static void
1815 1.29 dsl txp_stop(struct txp_softc *sc)
1816 1.1 drochner {
1817 1.1 drochner txp_command(sc, TXP_CMD_TX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1818 1.1 drochner txp_command(sc, TXP_CMD_RX_DISABLE, 0, 0, 0, NULL, NULL, NULL, 1);
1819 1.1 drochner
1820 1.1 drochner if (callout_pending(&sc->sc_tick))
1821 1.1 drochner callout_stop(&sc->sc_tick);
1822 1.1 drochner }
1823 1.1 drochner
1824 1.62 maxv static void
1825 1.18 christos txp_watchdog(struct ifnet *ifp)
1826 1.1 drochner {
1827 1.1 drochner }
1828 1.1 drochner
1829 1.62 maxv static int
1830 1.29 dsl txp_ifmedia_upd(struct ifnet *ifp)
1831 1.1 drochner {
1832 1.1 drochner struct txp_softc *sc = ifp->if_softc;
1833 1.1 drochner struct ifmedia *ifm = &sc->sc_ifmedia;
1834 1.53 msaitoh uint16_t new_xcvr;
1835 1.1 drochner
1836 1.1 drochner if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1837 1.1 drochner return (EINVAL);
1838 1.1 drochner
1839 1.1 drochner if (IFM_SUBTYPE(ifm->ifm_media) == IFM_10_T) {
1840 1.52 msaitoh if ((ifm->ifm_media & IFM_FDX) != 0)
1841 1.1 drochner new_xcvr = TXP_XCVR_10_FDX;
1842 1.1 drochner else
1843 1.1 drochner new_xcvr = TXP_XCVR_10_HDX;
1844 1.2 drochner } else if ((IFM_SUBTYPE(ifm->ifm_media) == IFM_100_TX) ||
1845 1.2 drochner (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_FX)) {
1846 1.52 msaitoh if ((ifm->ifm_media & IFM_FDX) != 0)
1847 1.1 drochner new_xcvr = TXP_XCVR_100_FDX;
1848 1.1 drochner else
1849 1.1 drochner new_xcvr = TXP_XCVR_100_HDX;
1850 1.1 drochner } else if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) {
1851 1.1 drochner new_xcvr = TXP_XCVR_AUTO;
1852 1.1 drochner } else
1853 1.1 drochner return (EINVAL);
1854 1.1 drochner
1855 1.1 drochner /* nothing to do */
1856 1.1 drochner if (sc->sc_xcvr == new_xcvr)
1857 1.1 drochner return (0);
1858 1.1 drochner
1859 1.1 drochner txp_command(sc, TXP_CMD_XCVR_SELECT, new_xcvr, 0, 0,
1860 1.1 drochner NULL, NULL, NULL, 0);
1861 1.1 drochner sc->sc_xcvr = new_xcvr;
1862 1.1 drochner
1863 1.1 drochner return (0);
1864 1.1 drochner }
1865 1.1 drochner
1866 1.62 maxv static void
1867 1.29 dsl txp_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1868 1.1 drochner {
1869 1.1 drochner struct txp_softc *sc = ifp->if_softc;
1870 1.1 drochner struct ifmedia *ifm = &sc->sc_ifmedia;
1871 1.53 msaitoh uint16_t bmsr, bmcr, anlpar;
1872 1.1 drochner
1873 1.1 drochner ifmr->ifm_status = IFM_AVALID;
1874 1.1 drochner ifmr->ifm_active = IFM_ETHER;
1875 1.1 drochner
1876 1.1 drochner if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMSR, 0,
1877 1.1 drochner &bmsr, NULL, NULL, 1))
1878 1.1 drochner goto bail;
1879 1.1 drochner if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMSR, 0,
1880 1.1 drochner &bmsr, NULL, NULL, 1))
1881 1.1 drochner goto bail;
1882 1.1 drochner
1883 1.1 drochner if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_BMCR, 0,
1884 1.1 drochner &bmcr, NULL, NULL, 1))
1885 1.1 drochner goto bail;
1886 1.1 drochner
1887 1.1 drochner if (txp_command(sc, TXP_CMD_PHY_MGMT_READ, 0, MII_ANLPAR, 0,
1888 1.1 drochner &anlpar, NULL, NULL, 1))
1889 1.1 drochner goto bail;
1890 1.1 drochner
1891 1.1 drochner if (bmsr & BMSR_LINK)
1892 1.1 drochner ifmr->ifm_status |= IFM_ACTIVE;
1893 1.1 drochner
1894 1.1 drochner if (bmcr & BMCR_ISO) {
1895 1.1 drochner ifmr->ifm_active |= IFM_NONE;
1896 1.1 drochner ifmr->ifm_status = 0;
1897 1.1 drochner return;
1898 1.1 drochner }
1899 1.1 drochner
1900 1.1 drochner if (bmcr & BMCR_LOOP)
1901 1.1 drochner ifmr->ifm_active |= IFM_LOOP;
1902 1.1 drochner
1903 1.2 drochner if (!(sc->sc_flags & TXP_FIBER) && (bmcr & BMCR_AUTOEN)) {
1904 1.1 drochner if ((bmsr & BMSR_ACOMP) == 0) {
1905 1.1 drochner ifmr->ifm_active |= IFM_NONE;
1906 1.1 drochner return;
1907 1.1 drochner }
1908 1.1 drochner
1909 1.28 cegger if (anlpar & ANLPAR_TX_FD)
1910 1.53 msaitoh ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
1911 1.28 cegger else if (anlpar & ANLPAR_T4)
1912 1.53 msaitoh ifmr->ifm_active |= IFM_100_T4 | IFM_HDX;
1913 1.1 drochner else if (anlpar & ANLPAR_TX)
1914 1.53 msaitoh ifmr->ifm_active |= IFM_100_TX | IFM_HDX;
1915 1.1 drochner else if (anlpar & ANLPAR_10_FD)
1916 1.53 msaitoh ifmr->ifm_active |= IFM_10_T | IFM_FDX;
1917 1.1 drochner else if (anlpar & ANLPAR_10)
1918 1.53 msaitoh ifmr->ifm_active |= IFM_10_T | IFM_HDX;
1919 1.1 drochner else
1920 1.1 drochner ifmr->ifm_active |= IFM_NONE;
1921 1.1 drochner } else
1922 1.1 drochner ifmr->ifm_active = ifm->ifm_cur->ifm_media;
1923 1.1 drochner return;
1924 1.1 drochner
1925 1.1 drochner bail:
1926 1.1 drochner ifmr->ifm_active |= IFM_NONE;
1927 1.1 drochner ifmr->ifm_status &= ~IFM_AVALID;
1928 1.1 drochner }
1929 1.1 drochner
1930 1.62 maxv #if 0 /* XXX XXX XXX UNUSED */
1931 1.62 maxv static void
1932 1.29 dsl txp_show_descriptor(void *d)
1933 1.1 drochner {
1934 1.1 drochner struct txp_cmd_desc *cmd = d;
1935 1.1 drochner struct txp_rsp_desc *rsp = d;
1936 1.1 drochner struct txp_tx_desc *txd = d;
1937 1.1 drochner struct txp_frag_desc *frgd = d;
1938 1.1 drochner
1939 1.1 drochner switch (cmd->cmd_flags & CMD_FLAGS_TYPE_M) {
1940 1.1 drochner case CMD_FLAGS_TYPE_CMD:
1941 1.1 drochner /* command descriptor */
1942 1.53 msaitoh printf("[cmd flags 0x%x num %d id %d seq %d par1 0x%x par2 "
1943 1.53 msaitoh "0x%x par3 0x%x]\n",
1944 1.1 drochner cmd->cmd_flags, cmd->cmd_numdesc, le16toh(cmd->cmd_id),
1945 1.1 drochner le16toh(cmd->cmd_seq), le16toh(cmd->cmd_par1),
1946 1.1 drochner le32toh(cmd->cmd_par2), le32toh(cmd->cmd_par3));
1947 1.1 drochner break;
1948 1.1 drochner case CMD_FLAGS_TYPE_RESP:
1949 1.1 drochner /* response descriptor */
1950 1.53 msaitoh printf("[rsp flags 0x%x num %d id %d seq %d par1 0x%x par2 "
1951 1.53 msaitoh "0x%x par3 0x%x]\n",
1952 1.1 drochner rsp->rsp_flags, rsp->rsp_numdesc, le16toh(rsp->rsp_id),
1953 1.1 drochner le16toh(rsp->rsp_seq), le16toh(rsp->rsp_par1),
1954 1.1 drochner le32toh(rsp->rsp_par2), le32toh(rsp->rsp_par3));
1955 1.1 drochner break;
1956 1.1 drochner case CMD_FLAGS_TYPE_DATA:
1957 1.1 drochner /* data header (assuming tx for now) */
1958 1.53 msaitoh printf("[data flags 0x%x num %d totlen %d addr 0x%x/0x%x "
1959 1.53 msaitoh "pflags 0x%x]",
1960 1.1 drochner txd->tx_flags, txd->tx_numdesc, txd->tx_totlen,
1961 1.1 drochner txd->tx_addrlo, txd->tx_addrhi, txd->tx_pflags);
1962 1.1 drochner break;
1963 1.1 drochner case CMD_FLAGS_TYPE_FRAG:
1964 1.1 drochner /* fragment descriptor */
1965 1.53 msaitoh printf("[frag flags 0x%x rsvd1 0x%x len %d addr 0x%x/0x%x "
1966 1.53 msaitoh "rsvd2 0x%x]",
1967 1.1 drochner frgd->frag_flags, frgd->frag_rsvd1, frgd->frag_len,
1968 1.1 drochner frgd->frag_addrlo, frgd->frag_addrhi, frgd->frag_rsvd2);
1969 1.1 drochner break;
1970 1.1 drochner default:
1971 1.53 msaitoh printf("[unknown(%x) flags 0x%x num %d id %d seq %d par1 "
1972 1.53 msaitoh "0x%x par2 0x%x par3 0x%x]\n",
1973 1.1 drochner cmd->cmd_flags & CMD_FLAGS_TYPE_M,
1974 1.1 drochner cmd->cmd_flags, cmd->cmd_numdesc, le16toh(cmd->cmd_id),
1975 1.1 drochner le16toh(cmd->cmd_seq), le16toh(cmd->cmd_par1),
1976 1.1 drochner le32toh(cmd->cmd_par2), le32toh(cmd->cmd_par3));
1977 1.1 drochner break;
1978 1.1 drochner }
1979 1.1 drochner }
1980 1.62 maxv #endif
1981 1.1 drochner
1982 1.62 maxv static void
1983 1.29 dsl txp_set_filter(struct txp_softc *sc)
1984 1.1 drochner {
1985 1.55 msaitoh struct ethercom *ec = &sc->sc_arpcom;
1986 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
1987 1.53 msaitoh uint32_t crc, carry, hashbit, hash[2];
1988 1.53 msaitoh uint16_t filter;
1989 1.53 msaitoh uint8_t octet;
1990 1.1 drochner int i, j, mcnt = 0;
1991 1.1 drochner struct ether_multi *enm;
1992 1.1 drochner struct ether_multistep step;
1993 1.1 drochner
1994 1.1 drochner if (ifp->if_flags & IFF_PROMISC) {
1995 1.1 drochner filter = TXP_RXFILT_PROMISC;
1996 1.1 drochner goto setit;
1997 1.1 drochner }
1998 1.1 drochner
1999 1.1 drochner again:
2000 1.1 drochner filter = TXP_RXFILT_DIRECT;
2001 1.1 drochner
2002 1.1 drochner if (ifp->if_flags & IFF_BROADCAST)
2003 1.1 drochner filter |= TXP_RXFILT_BROADCAST;
2004 1.1 drochner
2005 1.1 drochner if (ifp->if_flags & IFF_ALLMULTI)
2006 1.1 drochner filter |= TXP_RXFILT_ALLMULTI;
2007 1.1 drochner else {
2008 1.1 drochner hash[0] = hash[1] = 0;
2009 1.1 drochner
2010 1.56 msaitoh ETHER_LOCK(ec);
2011 1.55 msaitoh ETHER_FIRST_MULTI(step, ec, enm);
2012 1.1 drochner while (enm != NULL) {
2013 1.44 msaitoh if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
2014 1.44 msaitoh ETHER_ADDR_LEN)) {
2015 1.1 drochner /*
2016 1.1 drochner * We must listen to a range of multicast
2017 1.1 drochner * addresses. For now, just accept all
2018 1.1 drochner * multicasts, rather than trying to set only
2019 1.1 drochner * those filter bits needed to match the range.
2020 1.1 drochner * (At this time, the only use of address
2021 1.1 drochner * ranges is for IP multicast routing, for
2022 1.1 drochner * which the range is big enough to require
2023 1.1 drochner * all bits set.)
2024 1.1 drochner */
2025 1.1 drochner ifp->if_flags |= IFF_ALLMULTI;
2026 1.56 msaitoh ETHER_UNLOCK(ec);
2027 1.1 drochner goto again;
2028 1.1 drochner }
2029 1.1 drochner
2030 1.1 drochner mcnt++;
2031 1.1 drochner crc = 0xffffffff;
2032 1.1 drochner
2033 1.1 drochner for (i = 0; i < ETHER_ADDR_LEN; i++) {
2034 1.1 drochner octet = enm->enm_addrlo[i];
2035 1.1 drochner for (j = 0; j < 8; j++) {
2036 1.1 drochner carry = ((crc & 0x80000000) ? 1 : 0) ^
2037 1.1 drochner (octet & 1);
2038 1.1 drochner crc <<= 1;
2039 1.1 drochner octet >>= 1;
2040 1.1 drochner if (carry)
2041 1.1 drochner crc = (crc ^ TXP_POLYNOMIAL) |
2042 1.1 drochner carry;
2043 1.1 drochner }
2044 1.1 drochner }
2045 1.53 msaitoh hashbit = (uint16_t)(crc & (64 - 1));
2046 1.1 drochner hash[hashbit / 32] |= (1 << hashbit % 32);
2047 1.1 drochner ETHER_NEXT_MULTI(step, enm);
2048 1.1 drochner }
2049 1.56 msaitoh ETHER_UNLOCK(ec);
2050 1.1 drochner
2051 1.1 drochner if (mcnt > 0) {
2052 1.1 drochner filter |= TXP_RXFILT_HASHMULTI;
2053 1.1 drochner txp_command(sc, TXP_CMD_MCAST_HASH_MASK_WRITE,
2054 1.1 drochner 2, hash[0], hash[1], NULL, NULL, NULL, 0);
2055 1.1 drochner }
2056 1.1 drochner }
2057 1.1 drochner
2058 1.1 drochner setit:
2059 1.1 drochner txp_command(sc, TXP_CMD_RX_FILTER_WRITE, filter, 0, 0,
2060 1.1 drochner NULL, NULL, NULL, 1);
2061 1.1 drochner }
2062 1.1 drochner
2063 1.62 maxv static void
2064 1.29 dsl txp_capabilities(struct txp_softc *sc)
2065 1.1 drochner {
2066 1.1 drochner struct ifnet *ifp = &sc->sc_arpcom.ec_if;
2067 1.1 drochner struct txp_rsp_desc *rsp = NULL;
2068 1.1 drochner struct txp_ext_desc *ext;
2069 1.1 drochner
2070 1.1 drochner if (txp_command2(sc, TXP_CMD_OFFLOAD_READ, 0, 0, 0, NULL, 0, &rsp, 1))
2071 1.1 drochner goto out;
2072 1.1 drochner
2073 1.1 drochner if (rsp->rsp_numdesc != 1)
2074 1.1 drochner goto out;
2075 1.1 drochner ext = (struct txp_ext_desc *)(rsp + 1);
2076 1.1 drochner
2077 1.1 drochner sc->sc_tx_capability = ext->ext_1 & OFFLOAD_MASK;
2078 1.1 drochner sc->sc_rx_capability = ext->ext_2 & OFFLOAD_MASK;
2079 1.1 drochner
2080 1.4 drochner sc->sc_arpcom.ec_capabilities |= ETHERCAP_VLAN_MTU;
2081 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_VLAN) {
2082 1.1 drochner sc->sc_tx_capability |= OFFLOAD_VLAN;
2083 1.1 drochner sc->sc_rx_capability |= OFFLOAD_VLAN;
2084 1.4 drochner sc->sc_arpcom.ec_capabilities |= ETHERCAP_VLAN_HWTAGGING;
2085 1.59 msaitoh sc->sc_arpcom.ec_capenable |= ETHERCAP_VLAN_HWTAGGING;
2086 1.1 drochner }
2087 1.1 drochner
2088 1.1 drochner #if 0
2089 1.1 drochner /* not ready yet */
2090 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_IPSEC) {
2091 1.1 drochner sc->sc_tx_capability |= OFFLOAD_IPSEC;
2092 1.1 drochner sc->sc_rx_capability |= OFFLOAD_IPSEC;
2093 1.1 drochner ifp->if_capabilities |= IFCAP_IPSEC;
2094 1.1 drochner }
2095 1.1 drochner #endif
2096 1.1 drochner
2097 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_IPCKSUM) {
2098 1.1 drochner sc->sc_tx_capability |= OFFLOAD_IPCKSUM;
2099 1.1 drochner sc->sc_rx_capability |= OFFLOAD_IPCKSUM;
2100 1.11 yamt ifp->if_capabilities |= IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx;
2101 1.1 drochner }
2102 1.1 drochner
2103 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_TCPCKSUM) {
2104 1.1 drochner sc->sc_rx_capability |= OFFLOAD_TCPCKSUM;
2105 1.1 drochner #ifdef TRY_TX_TCP_CSUM
2106 1.1 drochner sc->sc_tx_capability |= OFFLOAD_TCPCKSUM;
2107 1.11 yamt ifp->if_capabilities |=
2108 1.11 yamt IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx;
2109 1.1 drochner #endif
2110 1.1 drochner }
2111 1.1 drochner
2112 1.1 drochner if (rsp->rsp_par2 & rsp->rsp_par3 & OFFLOAD_UDPCKSUM) {
2113 1.1 drochner sc->sc_rx_capability |= OFFLOAD_UDPCKSUM;
2114 1.1 drochner #ifdef TRY_TX_UDP_CSUM
2115 1.1 drochner sc->sc_tx_capability |= OFFLOAD_UDPCKSUM;
2116 1.11 yamt ifp->if_capabilities |=
2117 1.11 yamt IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx;
2118 1.1 drochner #endif
2119 1.1 drochner }
2120 1.1 drochner
2121 1.1 drochner if (txp_command(sc, TXP_CMD_OFFLOAD_WRITE, 0,
2122 1.1 drochner sc->sc_tx_capability, sc->sc_rx_capability, NULL, NULL, NULL, 1))
2123 1.1 drochner goto out;
2124 1.1 drochner
2125 1.1 drochner out:
2126 1.1 drochner if (rsp != NULL)
2127 1.1 drochner free(rsp, M_DEVBUF);
2128 1.1 drochner }
2129