if_fwip.c revision 1.32 1 1.32 rin /* $NetBSD: if_fwip.c,v 1.32 2024/07/05 04:31:51 rin Exp $ */
2 1.1 kiyohara /*-
3 1.1 kiyohara * Copyright (c) 2004
4 1.1 kiyohara * Doug Rabson
5 1.1 kiyohara * Copyright (c) 2002-2003
6 1.1 kiyohara * Hidetoshi Shimokawa. All rights reserved.
7 1.22 kiyohara *
8 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
9 1.1 kiyohara * modification, are permitted provided that the following conditions
10 1.1 kiyohara * are met:
11 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
12 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
13 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
15 1.1 kiyohara * documentation and/or other materials provided with the distribution.
16 1.1 kiyohara * 3. All advertising materials mentioning features or use of this software
17 1.1 kiyohara * must display the following acknowledgement:
18 1.1 kiyohara *
19 1.1 kiyohara * This product includes software developed by Hidetoshi Shimokawa.
20 1.1 kiyohara *
21 1.1 kiyohara * 4. Neither the name of the author nor the names of its contributors
22 1.1 kiyohara * may be used to endorse or promote products derived from this software
23 1.1 kiyohara * without specific prior written permission.
24 1.22 kiyohara *
25 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1 kiyohara * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 kiyohara * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 kiyohara * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1 kiyohara * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1 kiyohara * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1 kiyohara * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 kiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 kiyohara * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 kiyohara * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 kiyohara * SUCH DAMAGE.
36 1.22 kiyohara *
37 1.22 kiyohara * $FreeBSD: src/sys/dev/firewire/if_fwip.c,v 1.18 2009/02/09 16:58:18 fjoe Exp $
38 1.1 kiyohara */
39 1.1 kiyohara
40 1.12 lukem #include <sys/cdefs.h>
41 1.32 rin __KERNEL_RCSID(0, "$NetBSD: if_fwip.c,v 1.32 2024/07/05 04:31:51 rin Exp $");
42 1.1 kiyohara
43 1.1 kiyohara #include <sys/param.h>
44 1.1 kiyohara #include <sys/bus.h>
45 1.1 kiyohara #include <sys/device.h>
46 1.1 kiyohara #include <sys/errno.h>
47 1.24 christos #include <sys/malloc.h>
48 1.1 kiyohara #include <sys/mbuf.h>
49 1.22 kiyohara #include <sys/mutex.h>
50 1.1 kiyohara #include <sys/sysctl.h>
51 1.1 kiyohara
52 1.22 kiyohara #include <net/bpf.h>
53 1.1 kiyohara #include <net/if.h>
54 1.1 kiyohara #include <net/if_ieee1394.h>
55 1.8 kiyohara #include <net/if_types.h>
56 1.1 kiyohara
57 1.1 kiyohara #include <dev/ieee1394/firewire.h>
58 1.1 kiyohara #include <dev/ieee1394/firewirereg.h>
59 1.1 kiyohara #include <dev/ieee1394/iec13213.h>
60 1.1 kiyohara #include <dev/ieee1394/if_fwipvar.h>
61 1.1 kiyohara
62 1.1 kiyohara /*
63 1.1 kiyohara * We really need a mechanism for allocating regions in the FIFO
64 1.1 kiyohara * address space. We pick a address in the OHCI controller's 'middle'
65 1.1 kiyohara * address space. This means that the controller will automatically
66 1.1 kiyohara * send responses for us, which is fine since we don't have any
67 1.1 kiyohara * important information to put in the response anyway.
68 1.1 kiyohara */
69 1.1 kiyohara #define INET_FIFO 0xfffe00000000LL
70 1.1 kiyohara
71 1.15 gmcgarry #define FWIPDEBUG if (fwipdebug) aprint_debug_ifnet
72 1.1 kiyohara #define TX_MAX_QUEUE (FWMAXQUEUE - 1)
73 1.1 kiyohara
74 1.1 kiyohara
75 1.22 kiyohara struct fw_hwaddr {
76 1.22 kiyohara uint32_t sender_unique_ID_hi;
77 1.22 kiyohara uint32_t sender_unique_ID_lo;
78 1.22 kiyohara uint8_t sender_max_rec;
79 1.22 kiyohara uint8_t sspd;
80 1.22 kiyohara uint16_t sender_unicast_FIFO_hi;
81 1.22 kiyohara uint32_t sender_unicast_FIFO_lo;
82 1.22 kiyohara };
83 1.22 kiyohara
84 1.22 kiyohara
85 1.22 kiyohara static int fwipmatch(device_t, cfdata_t, void *);
86 1.22 kiyohara static void fwipattach(device_t, device_t, void *);
87 1.22 kiyohara static int fwipdetach(device_t, int);
88 1.22 kiyohara static int fwipactivate(device_t, enum devact);
89 1.22 kiyohara
90 1.1 kiyohara /* network interface */
91 1.22 kiyohara static void fwip_start(struct ifnet *);
92 1.22 kiyohara static int fwip_ioctl(struct ifnet *, u_long, void *);
93 1.10 kiyohara static int fwip_init(struct ifnet *);
94 1.10 kiyohara static void fwip_stop(struct ifnet *, int);
95 1.1 kiyohara
96 1.22 kiyohara static void fwip_post_busreset(void *);
97 1.22 kiyohara static void fwip_output_callback(struct fw_xfer *);
98 1.22 kiyohara static void fwip_async_output(struct fwip_softc *, struct ifnet *);
99 1.22 kiyohara static void fwip_stream_input(struct fw_xferq *);
100 1.1 kiyohara static void fwip_unicast_input(struct fw_xfer *);
101 1.1 kiyohara
102 1.1 kiyohara static int fwipdebug = 0;
103 1.1 kiyohara static int broadcast_channel = 0xc0 | 0x1f; /* tag | channel(XXX) */
104 1.1 kiyohara static int tx_speed = 2;
105 1.1 kiyohara static int rx_queue_len = FWMAXQUEUE;
106 1.1 kiyohara
107 1.1 kiyohara /*
108 1.1 kiyohara * Setup sysctl(3) MIB, hw.fwip.*
109 1.1 kiyohara *
110 1.17 ad * TBD condition CTLFLAG_PERMANENT on being a module or not
111 1.1 kiyohara */
112 1.1 kiyohara SYSCTL_SETUP(sysctl_fwip, "sysctl fwip(4) subtree setup")
113 1.1 kiyohara {
114 1.1 kiyohara int rc, fwip_node_num;
115 1.1 kiyohara const struct sysctlnode *node;
116 1.1 kiyohara
117 1.1 kiyohara if ((rc = sysctl_createv(clog, 0, NULL, &node,
118 1.1 kiyohara CTLFLAG_PERMANENT, CTLTYPE_NODE, "fwip",
119 1.1 kiyohara SYSCTL_DESCR("fwip controls"),
120 1.1 kiyohara NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0) {
121 1.1 kiyohara goto err;
122 1.1 kiyohara }
123 1.1 kiyohara fwip_node_num = node->sysctl_num;
124 1.1 kiyohara
125 1.1 kiyohara /* fwip RX queue length */
126 1.1 kiyohara if ((rc = sysctl_createv(clog, 0, NULL, &node,
127 1.1 kiyohara CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT,
128 1.1 kiyohara "rx_queue_len", SYSCTL_DESCR("Length of the receive queue"),
129 1.1 kiyohara NULL, 0, &rx_queue_len,
130 1.1 kiyohara 0, CTL_HW, fwip_node_num, CTL_CREATE, CTL_EOL)) != 0) {
131 1.1 kiyohara goto err;
132 1.1 kiyohara }
133 1.1 kiyohara
134 1.1 kiyohara /* fwip RX queue length */
135 1.1 kiyohara if ((rc = sysctl_createv(clog, 0, NULL, &node,
136 1.1 kiyohara CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT,
137 1.1 kiyohara "if_fwip_debug", SYSCTL_DESCR("fwip driver debug flag"),
138 1.1 kiyohara NULL, 0, &fwipdebug,
139 1.1 kiyohara 0, CTL_HW, fwip_node_num, CTL_CREATE, CTL_EOL)) != 0) {
140 1.1 kiyohara goto err;
141 1.1 kiyohara }
142 1.1 kiyohara
143 1.1 kiyohara return;
144 1.1 kiyohara
145 1.1 kiyohara err:
146 1.22 kiyohara aprint_error("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
147 1.1 kiyohara }
148 1.1 kiyohara
149 1.1 kiyohara
150 1.22 kiyohara CFATTACH_DECL_NEW(fwip, sizeof(struct fwip_softc),
151 1.22 kiyohara fwipmatch, fwipattach, fwipdetach, fwipactivate);
152 1.8 kiyohara
153 1.1 kiyohara
154 1.1 kiyohara static int
155 1.19 cegger fwipmatch(device_t parent, cfdata_t cf, void *aux)
156 1.1 kiyohara {
157 1.1 kiyohara struct fw_attach_args *fwa = aux;
158 1.1 kiyohara
159 1.1 kiyohara if (strcmp(fwa->name, "fwip") == 0)
160 1.22 kiyohara return 1;
161 1.22 kiyohara return 0;
162 1.1 kiyohara }
163 1.1 kiyohara
164 1.22 kiyohara static void
165 1.22 kiyohara fwipattach(device_t parent, device_t self, void *aux)
166 1.1 kiyohara {
167 1.22 kiyohara struct fwip_softc *sc = device_private(self);
168 1.22 kiyohara struct fw_attach_args *fwa = (struct fw_attach_args *)aux;
169 1.22 kiyohara struct fw_hwaddr *hwaddr;
170 1.1 kiyohara struct ifnet *ifp;
171 1.1 kiyohara
172 1.22 kiyohara aprint_naive("\n");
173 1.22 kiyohara aprint_normal(": IP over IEEE1394\n");
174 1.22 kiyohara
175 1.22 kiyohara sc->sc_fd.dev = self;
176 1.22 kiyohara sc->sc_eth.fwip_ifp = &sc->sc_eth.fwcom.fc_if;
177 1.22 kiyohara hwaddr = (struct fw_hwaddr *)&sc->sc_eth.fwcom.ic_hwaddr;
178 1.1 kiyohara
179 1.22 kiyohara ifp = sc->sc_eth.fwip_ifp;
180 1.8 kiyohara
181 1.22 kiyohara mutex_init(&sc->sc_fwb.fwb_mtx, MUTEX_DEFAULT, IPL_NET);
182 1.22 kiyohara mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NET);
183 1.21 mrg
184 1.1 kiyohara /* XXX */
185 1.22 kiyohara sc->sc_dma_ch = -1;
186 1.1 kiyohara
187 1.22 kiyohara sc->sc_fd.fc = fwa->fc;
188 1.1 kiyohara if (tx_speed < 0)
189 1.22 kiyohara tx_speed = sc->sc_fd.fc->speed;
190 1.1 kiyohara
191 1.22 kiyohara sc->sc_fd.post_explore = NULL;
192 1.22 kiyohara sc->sc_fd.post_busreset = fwip_post_busreset;
193 1.22 kiyohara sc->sc_eth.fwip = sc;
194 1.1 kiyohara
195 1.1 kiyohara /*
196 1.1 kiyohara * Encode our hardware the way that arp likes it.
197 1.1 kiyohara */
198 1.22 kiyohara hwaddr->sender_unique_ID_hi = htonl(sc->sc_fd.fc->eui.hi);
199 1.22 kiyohara hwaddr->sender_unique_ID_lo = htonl(sc->sc_fd.fc->eui.lo);
200 1.22 kiyohara hwaddr->sender_max_rec = sc->sc_fd.fc->maxrec;
201 1.22 kiyohara hwaddr->sspd = sc->sc_fd.fc->speed;
202 1.1 kiyohara hwaddr->sender_unicast_FIFO_hi = htons((uint16_t)(INET_FIFO >> 32));
203 1.1 kiyohara hwaddr->sender_unicast_FIFO_lo = htonl((uint32_t)INET_FIFO);
204 1.1 kiyohara
205 1.22 kiyohara /* fill the rest and attach interface */
206 1.22 kiyohara ifp->if_softc = &sc->sc_eth;
207 1.1 kiyohara
208 1.22 kiyohara strlcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
209 1.22 kiyohara ifp->if_start = fwip_start;
210 1.22 kiyohara ifp->if_ioctl = fwip_ioctl;
211 1.22 kiyohara ifp->if_init = fwip_init;
212 1.22 kiyohara ifp->if_stop = fwip_stop;
213 1.22 kiyohara ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
214 1.1 kiyohara IFQ_SET_READY(&ifp->if_snd);
215 1.22 kiyohara IFQ_SET_MAXLEN(&ifp->if_snd, TX_MAX_QUEUE);
216 1.1 kiyohara
217 1.22 kiyohara if_attach(ifp);
218 1.22 kiyohara ieee1394_ifattach(ifp, (const struct ieee1394_hwaddr *)hwaddr);
219 1.1 kiyohara
220 1.11 jmcneill if (!pmf_device_register(self, NULL, NULL))
221 1.11 jmcneill aprint_error_dev(self, "couldn't establish power handler\n");
222 1.11 jmcneill else
223 1.11 jmcneill pmf_class_network_register(self, ifp);
224 1.11 jmcneill
225 1.1 kiyohara FWIPDEBUG(ifp, "interface created\n");
226 1.22 kiyohara return;
227 1.1 kiyohara }
228 1.1 kiyohara
229 1.22 kiyohara static int
230 1.22 kiyohara fwipdetach(device_t self, int flags)
231 1.1 kiyohara {
232 1.22 kiyohara struct fwip_softc *sc = device_private(self);
233 1.22 kiyohara struct ifnet *ifp = sc->sc_eth.fwip_ifp;
234 1.1 kiyohara
235 1.22 kiyohara fwip_stop(sc->sc_eth.fwip_ifp, 1);
236 1.22 kiyohara ieee1394_ifdetach(ifp);
237 1.22 kiyohara if_detach(ifp);
238 1.22 kiyohara mutex_destroy(&sc->sc_mtx);
239 1.22 kiyohara mutex_destroy(&sc->sc_fwb.fwb_mtx);
240 1.22 kiyohara return 0;
241 1.22 kiyohara }
242 1.1 kiyohara
243 1.22 kiyohara static int
244 1.22 kiyohara fwipactivate(device_t self, enum devact act)
245 1.22 kiyohara {
246 1.22 kiyohara struct fwip_softc *sc = device_private(self);
247 1.1 kiyohara
248 1.22 kiyohara switch (act) {
249 1.22 kiyohara case DVACT_DEACTIVATE:
250 1.22 kiyohara if_deactivate(sc->sc_eth.fwip_ifp);
251 1.22 kiyohara return 0;
252 1.22 kiyohara default:
253 1.22 kiyohara return EOPNOTSUPP;
254 1.22 kiyohara }
255 1.22 kiyohara }
256 1.22 kiyohara
257 1.22 kiyohara static void
258 1.22 kiyohara fwip_start(struct ifnet *ifp)
259 1.22 kiyohara {
260 1.22 kiyohara struct fwip_softc *sc = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
261 1.22 kiyohara
262 1.22 kiyohara FWIPDEBUG(ifp, "starting\n");
263 1.1 kiyohara
264 1.22 kiyohara if (sc->sc_dma_ch < 0) {
265 1.22 kiyohara struct mbuf *m = NULL;
266 1.1 kiyohara
267 1.22 kiyohara FWIPDEBUG(ifp, "not ready\n");
268 1.1 kiyohara
269 1.22 kiyohara do {
270 1.22 kiyohara IF_DEQUEUE(&ifp->if_snd, m);
271 1.32 rin m_freem(m);
272 1.30 thorpej if_statinc(ifp, if_oerrors);
273 1.22 kiyohara } while (m != NULL);
274 1.1 kiyohara
275 1.22 kiyohara return;
276 1.1 kiyohara }
277 1.1 kiyohara
278 1.22 kiyohara ifp->if_flags |= IFF_OACTIVE;
279 1.22 kiyohara
280 1.22 kiyohara if (ifp->if_snd.ifq_len != 0)
281 1.22 kiyohara fwip_async_output(sc, ifp);
282 1.22 kiyohara
283 1.22 kiyohara ifp->if_flags &= ~IFF_OACTIVE;
284 1.1 kiyohara }
285 1.1 kiyohara
286 1.22 kiyohara static int
287 1.22 kiyohara fwip_ioctl(struct ifnet *ifp, u_long cmd, void *data)
288 1.1 kiyohara {
289 1.22 kiyohara int s, error = 0;
290 1.1 kiyohara
291 1.22 kiyohara s = splnet();
292 1.8 kiyohara
293 1.22 kiyohara switch (cmd) {
294 1.22 kiyohara case SIOCSIFFLAGS:
295 1.22 kiyohara if ((error = ifioctl_common(ifp, cmd, data)) != 0)
296 1.22 kiyohara break;
297 1.22 kiyohara switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) {
298 1.22 kiyohara case IFF_RUNNING:
299 1.22 kiyohara fwip_stop(ifp, 0);
300 1.22 kiyohara break;
301 1.22 kiyohara case IFF_UP:
302 1.22 kiyohara fwip_init(ifp);
303 1.22 kiyohara break;
304 1.22 kiyohara default:
305 1.22 kiyohara break;
306 1.22 kiyohara }
307 1.22 kiyohara break;
308 1.8 kiyohara
309 1.22 kiyohara case SIOCADDMULTI:
310 1.22 kiyohara case SIOCDELMULTI:
311 1.22 kiyohara break;
312 1.1 kiyohara
313 1.22 kiyohara default:
314 1.22 kiyohara error = ieee1394_ioctl(ifp, cmd, data);
315 1.22 kiyohara if (error == ENETRESET)
316 1.22 kiyohara error = 0;
317 1.22 kiyohara break;
318 1.22 kiyohara }
319 1.1 kiyohara
320 1.1 kiyohara splx(s);
321 1.1 kiyohara
322 1.22 kiyohara return error;
323 1.1 kiyohara }
324 1.1 kiyohara
325 1.22 kiyohara static int
326 1.22 kiyohara fwip_init(struct ifnet *ifp)
327 1.1 kiyohara {
328 1.22 kiyohara struct fwip_softc *sc = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
329 1.1 kiyohara struct firewire_comm *fc;
330 1.1 kiyohara struct fw_xferq *xferq;
331 1.1 kiyohara struct fw_xfer *xfer;
332 1.1 kiyohara struct mbuf *m;
333 1.1 kiyohara int i;
334 1.1 kiyohara
335 1.1 kiyohara FWIPDEBUG(ifp, "initializing\n");
336 1.1 kiyohara
337 1.22 kiyohara fc = sc->sc_fd.fc;
338 1.22 kiyohara if (sc->sc_dma_ch < 0) {
339 1.22 kiyohara sc->sc_dma_ch = fw_open_isodma(fc, /* tx */0);
340 1.22 kiyohara if (sc->sc_dma_ch < 0)
341 1.22 kiyohara return ENXIO;
342 1.22 kiyohara xferq = fc->ir[sc->sc_dma_ch];
343 1.10 kiyohara xferq->flag |=
344 1.10 kiyohara FWXFERQ_EXTBUF | FWXFERQ_HANDLER | FWXFERQ_STREAM;
345 1.1 kiyohara xferq->flag &= ~0xff;
346 1.1 kiyohara xferq->flag |= broadcast_channel & 0xff;
347 1.1 kiyohara /* register fwip_input handler */
348 1.22 kiyohara xferq->sc = (void *) sc;
349 1.1 kiyohara xferq->hand = fwip_stream_input;
350 1.1 kiyohara xferq->bnchunk = rx_queue_len;
351 1.1 kiyohara xferq->bnpacket = 1;
352 1.1 kiyohara xferq->psize = MCLBYTES;
353 1.1 kiyohara xferq->queued = 0;
354 1.1 kiyohara xferq->buf = NULL;
355 1.24 christos xferq->bulkxfer = (struct fw_bulkxfer *) malloc(
356 1.24 christos sizeof(struct fw_bulkxfer) * xferq->bnchunk,
357 1.25 dsl M_FW, M_WAITOK);
358 1.1 kiyohara if (xferq->bulkxfer == NULL) {
359 1.24 christos aprint_error_ifnet(ifp, "if_fwip: malloc failed\n");
360 1.22 kiyohara return ENOMEM;
361 1.1 kiyohara }
362 1.1 kiyohara STAILQ_INIT(&xferq->stvalid);
363 1.1 kiyohara STAILQ_INIT(&xferq->stfree);
364 1.1 kiyohara STAILQ_INIT(&xferq->stdma);
365 1.1 kiyohara xferq->stproc = NULL;
366 1.22 kiyohara for (i = 0; i < xferq->bnchunk; i++) {
367 1.22 kiyohara m = m_getcl(M_WAITOK, MT_DATA, M_PKTHDR);
368 1.1 kiyohara xferq->bulkxfer[i].mbuf = m;
369 1.1 kiyohara if (m != NULL) {
370 1.1 kiyohara m->m_len = m->m_pkthdr.len = m->m_ext.ext_size;
371 1.1 kiyohara STAILQ_INSERT_TAIL(&xferq->stfree,
372 1.1 kiyohara &xferq->bulkxfer[i], link);
373 1.1 kiyohara } else
374 1.22 kiyohara aprint_error_ifnet(ifp,
375 1.22 kiyohara "fwip_as_input: m_getcl failed\n");
376 1.1 kiyohara }
377 1.1 kiyohara
378 1.22 kiyohara sc->sc_fwb.start = INET_FIFO;
379 1.22 kiyohara sc->sc_fwb.end = INET_FIFO + 16384; /* S3200 packet size */
380 1.1 kiyohara
381 1.1 kiyohara /* pre-allocate xfer */
382 1.22 kiyohara STAILQ_INIT(&sc->sc_fwb.xferlist);
383 1.22 kiyohara for (i = 0; i < rx_queue_len; i++) {
384 1.25 dsl xfer = fw_xfer_alloc(M_FW);
385 1.1 kiyohara if (xfer == NULL)
386 1.1 kiyohara break;
387 1.22 kiyohara m = m_getcl(M_WAITOK, MT_DATA, M_PKTHDR);
388 1.1 kiyohara xfer->recv.payload = mtod(m, uint32_t *);
389 1.1 kiyohara xfer->recv.pay_len = MCLBYTES;
390 1.1 kiyohara xfer->hand = fwip_unicast_input;
391 1.1 kiyohara xfer->fc = fc;
392 1.22 kiyohara xfer->sc = (void *) sc;
393 1.1 kiyohara xfer->mbuf = m;
394 1.22 kiyohara STAILQ_INSERT_TAIL(&sc->sc_fwb.xferlist, xfer, link);
395 1.1 kiyohara }
396 1.22 kiyohara fw_bindadd(fc, &sc->sc_fwb);
397 1.1 kiyohara
398 1.22 kiyohara STAILQ_INIT(&sc->sc_xferlist);
399 1.1 kiyohara for (i = 0; i < TX_MAX_QUEUE; i++) {
400 1.25 dsl xfer = fw_xfer_alloc(M_FW);
401 1.1 kiyohara if (xfer == NULL)
402 1.1 kiyohara break;
403 1.1 kiyohara xfer->send.spd = tx_speed;
404 1.22 kiyohara xfer->fc = sc->sc_fd.fc;
405 1.22 kiyohara xfer->sc = (void *)sc;
406 1.1 kiyohara xfer->hand = fwip_output_callback;
407 1.22 kiyohara STAILQ_INSERT_TAIL(&sc->sc_xferlist, xfer, link);
408 1.1 kiyohara }
409 1.1 kiyohara } else
410 1.22 kiyohara xferq = fc->ir[sc->sc_dma_ch];
411 1.1 kiyohara
412 1.22 kiyohara sc->sc_last_dest.hi = 0;
413 1.22 kiyohara sc->sc_last_dest.lo = 0;
414 1.1 kiyohara
415 1.1 kiyohara /* start dma */
416 1.1 kiyohara if ((xferq->flag & FWXFERQ_RUNNING) == 0)
417 1.22 kiyohara fc->irx_enable(fc, sc->sc_dma_ch);
418 1.1 kiyohara
419 1.1 kiyohara ifp->if_flags |= IFF_RUNNING;
420 1.1 kiyohara ifp->if_flags &= ~IFF_OACTIVE;
421 1.1 kiyohara
422 1.1 kiyohara #if 0
423 1.1 kiyohara /* attempt to start output */
424 1.1 kiyohara fwip_start(ifp);
425 1.1 kiyohara #endif
426 1.22 kiyohara return 0;
427 1.1 kiyohara }
428 1.1 kiyohara
429 1.22 kiyohara static void
430 1.22 kiyohara fwip_stop(struct ifnet *ifp, int disable)
431 1.1 kiyohara {
432 1.22 kiyohara struct fwip_softc *sc = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
433 1.22 kiyohara struct firewire_comm *fc = sc->sc_fd.fc;
434 1.22 kiyohara struct fw_xferq *xferq;
435 1.22 kiyohara struct fw_xfer *xfer, *next;
436 1.22 kiyohara int i;
437 1.22 kiyohara
438 1.22 kiyohara if (sc->sc_dma_ch >= 0) {
439 1.22 kiyohara xferq = fc->ir[sc->sc_dma_ch];
440 1.22 kiyohara
441 1.22 kiyohara if (xferq->flag & FWXFERQ_RUNNING)
442 1.22 kiyohara fc->irx_disable(fc, sc->sc_dma_ch);
443 1.22 kiyohara xferq->flag &=
444 1.22 kiyohara ~(FWXFERQ_MODEMASK | FWXFERQ_OPEN | FWXFERQ_STREAM |
445 1.22 kiyohara FWXFERQ_EXTBUF | FWXFERQ_HANDLER | FWXFERQ_CHTAGMASK);
446 1.22 kiyohara xferq->hand = NULL;
447 1.22 kiyohara
448 1.22 kiyohara for (i = 0; i < xferq->bnchunk; i++)
449 1.22 kiyohara m_freem(xferq->bulkxfer[i].mbuf);
450 1.25 dsl free(xferq->bulkxfer, M_FW);
451 1.1 kiyohara
452 1.22 kiyohara fw_bindremove(fc, &sc->sc_fwb);
453 1.22 kiyohara for (xfer = STAILQ_FIRST(&sc->sc_fwb.xferlist); xfer != NULL;
454 1.22 kiyohara xfer = next) {
455 1.22 kiyohara next = STAILQ_NEXT(xfer, link);
456 1.22 kiyohara fw_xfer_free(xfer);
457 1.1 kiyohara }
458 1.8 kiyohara
459 1.22 kiyohara for (xfer = STAILQ_FIRST(&sc->sc_xferlist); xfer != NULL;
460 1.22 kiyohara xfer = next) {
461 1.22 kiyohara next = STAILQ_NEXT(xfer, link);
462 1.22 kiyohara fw_xfer_free(xfer);
463 1.8 kiyohara }
464 1.1 kiyohara
465 1.22 kiyohara xferq->bulkxfer = NULL;
466 1.22 kiyohara sc->sc_dma_ch = -1;
467 1.1 kiyohara }
468 1.1 kiyohara
469 1.22 kiyohara ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
470 1.1 kiyohara }
471 1.1 kiyohara
472 1.1 kiyohara static void
473 1.1 kiyohara fwip_post_busreset(void *arg)
474 1.1 kiyohara {
475 1.22 kiyohara struct fwip_softc *sc = arg;
476 1.1 kiyohara struct crom_src *src;
477 1.1 kiyohara struct crom_chunk *root;
478 1.1 kiyohara
479 1.22 kiyohara src = sc->sc_fd.fc->crom_src;
480 1.22 kiyohara root = sc->sc_fd.fc->crom_root;
481 1.1 kiyohara
482 1.1 kiyohara /* RFC2734 IPv4 over IEEE1394 */
483 1.22 kiyohara memset(&sc->sc_unit4, 0, sizeof(struct crom_chunk));
484 1.22 kiyohara crom_add_chunk(src, root, &sc->sc_unit4, CROM_UDIR);
485 1.22 kiyohara crom_add_entry(&sc->sc_unit4, CSRKEY_SPEC, CSRVAL_IETF);
486 1.22 kiyohara crom_add_simple_text(src, &sc->sc_unit4, &sc->sc_spec4, "IANA");
487 1.22 kiyohara crom_add_entry(&sc->sc_unit4, CSRKEY_VER, 1);
488 1.22 kiyohara crom_add_simple_text(src, &sc->sc_unit4, &sc->sc_ver4, "IPv4");
489 1.1 kiyohara
490 1.1 kiyohara /* RFC3146 IPv6 over IEEE1394 */
491 1.22 kiyohara memset(&sc->sc_unit6, 0, sizeof(struct crom_chunk));
492 1.22 kiyohara crom_add_chunk(src, root, &sc->sc_unit6, CROM_UDIR);
493 1.22 kiyohara crom_add_entry(&sc->sc_unit6, CSRKEY_SPEC, CSRVAL_IETF);
494 1.22 kiyohara crom_add_simple_text(src, &sc->sc_unit6, &sc->sc_spec6, "IANA");
495 1.22 kiyohara crom_add_entry(&sc->sc_unit6, CSRKEY_VER, 2);
496 1.22 kiyohara crom_add_simple_text(src, &sc->sc_unit6, &sc->sc_ver6, "IPv6");
497 1.22 kiyohara
498 1.22 kiyohara sc->sc_last_dest.hi = 0;
499 1.22 kiyohara sc->sc_last_dest.lo = 0;
500 1.22 kiyohara ieee1394_drain(sc->sc_eth.fwip_ifp);
501 1.1 kiyohara }
502 1.1 kiyohara
503 1.1 kiyohara static void
504 1.1 kiyohara fwip_output_callback(struct fw_xfer *xfer)
505 1.1 kiyohara {
506 1.22 kiyohara struct fwip_softc *sc = (struct fwip_softc *)xfer->sc;
507 1.1 kiyohara struct ifnet *ifp;
508 1.1 kiyohara
509 1.22 kiyohara ifp = sc->sc_eth.fwip_ifp;
510 1.1 kiyohara /* XXX error check */
511 1.1 kiyohara FWIPDEBUG(ifp, "resp = %d\n", xfer->resp);
512 1.1 kiyohara if (xfer->resp != 0)
513 1.30 thorpej if_statinc(ifp, if_oerrors);
514 1.22 kiyohara
515 1.1 kiyohara m_freem(xfer->mbuf);
516 1.1 kiyohara fw_xfer_unload(xfer);
517 1.1 kiyohara
518 1.22 kiyohara mutex_enter(&sc->sc_mtx);
519 1.22 kiyohara STAILQ_INSERT_TAIL(&sc->sc_xferlist, xfer, link);
520 1.22 kiyohara mutex_exit(&sc->sc_mtx);
521 1.1 kiyohara
522 1.1 kiyohara /* for queue full */
523 1.22 kiyohara if (ifp->if_snd.ifq_head != NULL)
524 1.1 kiyohara fwip_start(ifp);
525 1.1 kiyohara }
526 1.1 kiyohara
527 1.1 kiyohara /* Async. stream output */
528 1.1 kiyohara static void
529 1.22 kiyohara fwip_async_output(struct fwip_softc *sc, struct ifnet *ifp)
530 1.1 kiyohara {
531 1.22 kiyohara struct firewire_comm *fc = sc->sc_fd.fc;
532 1.1 kiyohara struct mbuf *m;
533 1.1 kiyohara struct m_tag *mtag;
534 1.1 kiyohara struct fw_hwaddr *destfw;
535 1.1 kiyohara struct fw_xfer *xfer;
536 1.1 kiyohara struct fw_xferq *xferq;
537 1.1 kiyohara struct fw_pkt *fp;
538 1.1 kiyohara uint16_t nodeid;
539 1.1 kiyohara int error;
540 1.1 kiyohara int i = 0;
541 1.1 kiyohara
542 1.1 kiyohara xfer = NULL;
543 1.10 kiyohara xferq = fc->atq;
544 1.10 kiyohara while ((xferq->queued < xferq->maxq - 1) &&
545 1.10 kiyohara (ifp->if_snd.ifq_head != NULL)) {
546 1.22 kiyohara mutex_enter(&sc->sc_mtx);
547 1.22 kiyohara if (STAILQ_EMPTY(&sc->sc_xferlist)) {
548 1.22 kiyohara mutex_exit(&sc->sc_mtx);
549 1.10 kiyohara #if 0
550 1.22 kiyohara aprint_normal("if_fwip: lack of xfer\n");
551 1.10 kiyohara #endif
552 1.10 kiyohara break;
553 1.1 kiyohara }
554 1.31 thorpej IF_POLL(&ifp->if_snd, m);
555 1.10 kiyohara if (m == NULL) {
556 1.22 kiyohara mutex_exit(&sc->sc_mtx);
557 1.1 kiyohara break;
558 1.10 kiyohara }
559 1.22 kiyohara xfer = STAILQ_FIRST(&sc->sc_xferlist);
560 1.22 kiyohara STAILQ_REMOVE_HEAD(&sc->sc_xferlist, link);
561 1.22 kiyohara mutex_exit(&sc->sc_mtx);
562 1.1 kiyohara
563 1.1 kiyohara /*
564 1.1 kiyohara * Dig out the link-level address which
565 1.1 kiyohara * firewire_output got via arp or neighbour
566 1.1 kiyohara * discovery. If we don't have a link-level address,
567 1.1 kiyohara * just stick the thing on the broadcast channel.
568 1.1 kiyohara */
569 1.29 maxv mtag = m_tag_find(m, MTAG_FIREWIRE_HWADDR);
570 1.1 kiyohara if (mtag == NULL)
571 1.1 kiyohara destfw = 0;
572 1.1 kiyohara else
573 1.1 kiyohara destfw = (struct fw_hwaddr *) (mtag + 1);
574 1.1 kiyohara
575 1.1 kiyohara /*
576 1.1 kiyohara * Put the mbuf in the xfer early in case we hit an
577 1.1 kiyohara * error case below - fwip_output_callback will free
578 1.1 kiyohara * the mbuf.
579 1.1 kiyohara */
580 1.1 kiyohara xfer->mbuf = m;
581 1.1 kiyohara
582 1.1 kiyohara /*
583 1.1 kiyohara * We use the arp result (if any) to add a suitable firewire
584 1.1 kiyohara * packet header before handing off to the bus.
585 1.1 kiyohara */
586 1.1 kiyohara fp = &xfer->send.hdr;
587 1.1 kiyohara nodeid = FWLOCALBUS | fc->nodeid;
588 1.1 kiyohara if ((m->m_flags & M_BCAST) || !destfw) {
589 1.1 kiyohara /*
590 1.1 kiyohara * Broadcast packets are sent as GASP packets with
591 1.1 kiyohara * specifier ID 0x00005e, version 1 on the broadcast
592 1.1 kiyohara * channel. To be conservative, we send at the
593 1.1 kiyohara * slowest possible speed.
594 1.1 kiyohara */
595 1.1 kiyohara uint32_t *p;
596 1.1 kiyohara
597 1.22 kiyohara M_PREPEND(m, 2 * sizeof(uint32_t), M_DONTWAIT);
598 1.1 kiyohara p = mtod(m, uint32_t *);
599 1.1 kiyohara fp->mode.stream.len = m->m_pkthdr.len;
600 1.1 kiyohara fp->mode.stream.chtag = broadcast_channel;
601 1.1 kiyohara fp->mode.stream.tcode = FWTCODE_STREAM;
602 1.1 kiyohara fp->mode.stream.sy = 0;
603 1.1 kiyohara xfer->send.spd = 0;
604 1.1 kiyohara p[0] = htonl(nodeid << 16);
605 1.1 kiyohara p[1] = htonl((0x5e << 24) | 1);
606 1.1 kiyohara } else {
607 1.1 kiyohara /*
608 1.1 kiyohara * Unicast packets are sent as block writes to the
609 1.1 kiyohara * target's unicast fifo address. If we can't
610 1.1 kiyohara * find the node address, we just give up. We
611 1.1 kiyohara * could broadcast it but that might overflow
612 1.1 kiyohara * the packet size limitations due to the
613 1.1 kiyohara * extra GASP header. Note: the hardware
614 1.1 kiyohara * address is stored in network byte order to
615 1.1 kiyohara * make life easier for ARP.
616 1.1 kiyohara */
617 1.1 kiyohara struct fw_device *fd;
618 1.1 kiyohara struct fw_eui64 eui;
619 1.1 kiyohara
620 1.1 kiyohara eui.hi = ntohl(destfw->sender_unique_ID_hi);
621 1.1 kiyohara eui.lo = ntohl(destfw->sender_unique_ID_lo);
622 1.22 kiyohara if (sc->sc_last_dest.hi != eui.hi ||
623 1.22 kiyohara sc->sc_last_dest.lo != eui.lo) {
624 1.1 kiyohara fd = fw_noderesolve_eui64(fc, &eui);
625 1.1 kiyohara if (!fd) {
626 1.1 kiyohara /* error */
627 1.30 thorpej if_statinc(ifp, if_oerrors);
628 1.1 kiyohara /* XXX set error code */
629 1.1 kiyohara fwip_output_callback(xfer);
630 1.1 kiyohara continue;
631 1.1 kiyohara
632 1.1 kiyohara }
633 1.22 kiyohara sc->sc_last_hdr.mode.wreqb.dst =
634 1.22 kiyohara FWLOCALBUS | fd->dst;
635 1.22 kiyohara sc->sc_last_hdr.mode.wreqb.tlrt = 0;
636 1.22 kiyohara sc->sc_last_hdr.mode.wreqb.tcode =
637 1.22 kiyohara FWTCODE_WREQB;
638 1.22 kiyohara sc->sc_last_hdr.mode.wreqb.pri = 0;
639 1.22 kiyohara sc->sc_last_hdr.mode.wreqb.src = nodeid;
640 1.22 kiyohara sc->sc_last_hdr.mode.wreqb.dest_hi =
641 1.1 kiyohara ntohs(destfw->sender_unicast_FIFO_hi);
642 1.22 kiyohara sc->sc_last_hdr.mode.wreqb.dest_lo =
643 1.1 kiyohara ntohl(destfw->sender_unicast_FIFO_lo);
644 1.22 kiyohara sc->sc_last_hdr.mode.wreqb.extcode = 0;
645 1.22 kiyohara sc->sc_last_dest = eui;
646 1.1 kiyohara }
647 1.1 kiyohara
648 1.22 kiyohara fp->mode.wreqb = sc->sc_last_hdr.mode.wreqb;
649 1.1 kiyohara fp->mode.wreqb.len = m->m_pkthdr.len;
650 1.28 riastrad xfer->send.spd = uimin(destfw->sspd, fc->speed);
651 1.1 kiyohara }
652 1.1 kiyohara
653 1.1 kiyohara xfer->send.pay_len = m->m_pkthdr.len;
654 1.1 kiyohara
655 1.1 kiyohara error = fw_asyreq(fc, -1, xfer);
656 1.1 kiyohara if (error == EAGAIN) {
657 1.1 kiyohara /*
658 1.1 kiyohara * We ran out of tlabels - requeue the packet
659 1.1 kiyohara * for later transmission.
660 1.1 kiyohara */
661 1.1 kiyohara xfer->mbuf = 0;
662 1.22 kiyohara mutex_enter(&sc->sc_mtx);
663 1.22 kiyohara STAILQ_INSERT_TAIL(&sc->sc_xferlist, xfer, link);
664 1.22 kiyohara mutex_exit(&sc->sc_mtx);
665 1.1 kiyohara break;
666 1.1 kiyohara }
667 1.31 thorpej IF_DEQUEUE(&ifp->if_snd, m);
668 1.1 kiyohara if (error) {
669 1.1 kiyohara /* error */
670 1.30 thorpej if_statinc(ifp, if_oerrors);
671 1.1 kiyohara /* XXX set error code */
672 1.1 kiyohara fwip_output_callback(xfer);
673 1.1 kiyohara continue;
674 1.1 kiyohara } else {
675 1.30 thorpej if_statinc(ifp, if_opackets);
676 1.1 kiyohara i++;
677 1.1 kiyohara }
678 1.1 kiyohara }
679 1.1 kiyohara #if 0
680 1.1 kiyohara if (i > 1)
681 1.22 kiyohara aprint_normal("%d queued\n", i);
682 1.1 kiyohara #endif
683 1.10 kiyohara if (i > 0)
684 1.1 kiyohara xferq->start(fc);
685 1.1 kiyohara }
686 1.1 kiyohara
687 1.1 kiyohara /* Async. stream output */
688 1.1 kiyohara static void
689 1.1 kiyohara fwip_stream_input(struct fw_xferq *xferq)
690 1.1 kiyohara {
691 1.1 kiyohara struct mbuf *m, *m0;
692 1.1 kiyohara struct m_tag *mtag;
693 1.1 kiyohara struct ifnet *ifp;
694 1.22 kiyohara struct fwip_softc *sc;
695 1.1 kiyohara struct fw_bulkxfer *sxfer;
696 1.1 kiyohara struct fw_pkt *fp;
697 1.1 kiyohara uint16_t src;
698 1.1 kiyohara uint32_t *p;
699 1.1 kiyohara
700 1.22 kiyohara sc = (struct fwip_softc *)xferq->sc;
701 1.22 kiyohara ifp = sc->sc_eth.fwip_ifp;
702 1.1 kiyohara while ((sxfer = STAILQ_FIRST(&xferq->stvalid)) != NULL) {
703 1.1 kiyohara STAILQ_REMOVE_HEAD(&xferq->stvalid, link);
704 1.1 kiyohara fp = mtod(sxfer->mbuf, struct fw_pkt *);
705 1.22 kiyohara if (sc->sc_fd.fc->irx_post != NULL)
706 1.22 kiyohara sc->sc_fd.fc->irx_post(sc->sc_fd.fc, fp->mode.ld);
707 1.1 kiyohara m = sxfer->mbuf;
708 1.1 kiyohara
709 1.1 kiyohara /* insert new rbuf */
710 1.1 kiyohara sxfer->mbuf = m0 = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
711 1.1 kiyohara if (m0 != NULL) {
712 1.1 kiyohara m0->m_len = m0->m_pkthdr.len = m0->m_ext.ext_size;
713 1.1 kiyohara STAILQ_INSERT_TAIL(&xferq->stfree, sxfer, link);
714 1.1 kiyohara } else
715 1.22 kiyohara aprint_error_ifnet(ifp,
716 1.22 kiyohara "fwip_as_input: m_getcl failed\n");
717 1.1 kiyohara
718 1.1 kiyohara /*
719 1.1 kiyohara * We must have a GASP header - leave the
720 1.1 kiyohara * encapsulation sanity checks to the generic
721 1.1 kiyohara * code. Remeber that we also have the firewire async
722 1.1 kiyohara * stream header even though that isn't accounted for
723 1.1 kiyohara * in mode.stream.len.
724 1.1 kiyohara */
725 1.22 kiyohara if (sxfer->resp != 0 ||
726 1.22 kiyohara fp->mode.stream.len < 2 * sizeof(uint32_t)) {
727 1.1 kiyohara m_freem(m);
728 1.30 thorpej if_statinc(ifp, if_ierrors);
729 1.1 kiyohara continue;
730 1.1 kiyohara }
731 1.1 kiyohara m->m_len = m->m_pkthdr.len = fp->mode.stream.len
732 1.1 kiyohara + sizeof(fp->mode.stream);
733 1.1 kiyohara
734 1.1 kiyohara /*
735 1.1 kiyohara * If we received the packet on the broadcast channel,
736 1.1 kiyohara * mark it as broadcast, otherwise we assume it must
737 1.1 kiyohara * be multicast.
738 1.1 kiyohara */
739 1.1 kiyohara if (fp->mode.stream.chtag == broadcast_channel)
740 1.1 kiyohara m->m_flags |= M_BCAST;
741 1.1 kiyohara else
742 1.1 kiyohara m->m_flags |= M_MCAST;
743 1.1 kiyohara
744 1.1 kiyohara /*
745 1.1 kiyohara * Make sure we recognise the GASP specifier and
746 1.1 kiyohara * version.
747 1.1 kiyohara */
748 1.1 kiyohara p = mtod(m, uint32_t *);
749 1.22 kiyohara if ((((ntohl(p[1]) & 0xffff) << 8) | ntohl(p[2]) >> 24) !=
750 1.22 kiyohara 0x00005e ||
751 1.22 kiyohara (ntohl(p[2]) & 0xffffff) != 1) {
752 1.1 kiyohara FWIPDEBUG(ifp, "Unrecognised GASP header %#08x %#08x\n",
753 1.1 kiyohara ntohl(p[1]), ntohl(p[2]));
754 1.1 kiyohara m_freem(m);
755 1.30 thorpej if_statinc(ifp, if_ierrors);
756 1.1 kiyohara continue;
757 1.1 kiyohara }
758 1.1 kiyohara
759 1.1 kiyohara /*
760 1.1 kiyohara * Record the sender ID for possible BPF usage.
761 1.1 kiyohara */
762 1.1 kiyohara src = ntohl(p[1]) >> 16;
763 1.22 kiyohara if (ifp->if_bpf) {
764 1.22 kiyohara mtag = m_tag_get(MTAG_FIREWIRE_SENDER_EUID,
765 1.22 kiyohara 2 * sizeof(uint32_t), M_NOWAIT);
766 1.1 kiyohara if (mtag) {
767 1.1 kiyohara /* bpf wants it in network byte order */
768 1.1 kiyohara struct fw_device *fd;
769 1.1 kiyohara uint32_t *p2 = (uint32_t *) (mtag + 1);
770 1.22 kiyohara
771 1.22 kiyohara fd = fw_noderesolve_nodeid(sc->sc_fd.fc,
772 1.1 kiyohara src & 0x3f);
773 1.1 kiyohara if (fd) {
774 1.1 kiyohara p2[0] = htonl(fd->eui.hi);
775 1.1 kiyohara p2[1] = htonl(fd->eui.lo);
776 1.1 kiyohara } else {
777 1.1 kiyohara p2[0] = 0;
778 1.1 kiyohara p2[1] = 0;
779 1.1 kiyohara }
780 1.1 kiyohara m_tag_prepend(m, mtag);
781 1.1 kiyohara }
782 1.1 kiyohara }
783 1.1 kiyohara
784 1.1 kiyohara /*
785 1.1 kiyohara * Trim off the GASP header
786 1.1 kiyohara */
787 1.1 kiyohara m_adj(m, 3*sizeof(uint32_t));
788 1.27 ozaki m_set_rcvif(m, ifp);
789 1.22 kiyohara ieee1394_input(ifp, m, src);
790 1.30 thorpej if_statinc(ifp, if_ipackets);
791 1.1 kiyohara }
792 1.1 kiyohara if (STAILQ_FIRST(&xferq->stfree) != NULL)
793 1.22 kiyohara sc->sc_fd.fc->irx_enable(sc->sc_fd.fc, sc->sc_dma_ch);
794 1.1 kiyohara }
795 1.1 kiyohara
796 1.4 perry static inline void
797 1.22 kiyohara fwip_unicast_input_recycle(struct fwip_softc *sc, struct fw_xfer *xfer)
798 1.1 kiyohara {
799 1.1 kiyohara struct mbuf *m;
800 1.1 kiyohara
801 1.1 kiyohara /*
802 1.1 kiyohara * We have finished with a unicast xfer. Allocate a new
803 1.1 kiyohara * cluster and stick it on the back of the input queue.
804 1.1 kiyohara */
805 1.2 kiyohara m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
806 1.2 kiyohara if (m == NULL)
807 1.22 kiyohara aprint_error_dev(sc->sc_fd.dev,
808 1.22 kiyohara "fwip_unicast_input_recycle: m_getcl failed\n");
809 1.1 kiyohara xfer->recv.payload = mtod(m, uint32_t *);
810 1.1 kiyohara xfer->recv.pay_len = MCLBYTES;
811 1.1 kiyohara xfer->mbuf = m;
812 1.22 kiyohara mutex_enter(&sc->sc_fwb.fwb_mtx);
813 1.22 kiyohara STAILQ_INSERT_TAIL(&sc->sc_fwb.xferlist, xfer, link);
814 1.22 kiyohara mutex_exit(&sc->sc_fwb.fwb_mtx);
815 1.1 kiyohara }
816 1.1 kiyohara
817 1.1 kiyohara static void
818 1.1 kiyohara fwip_unicast_input(struct fw_xfer *xfer)
819 1.1 kiyohara {
820 1.1 kiyohara uint64_t address;
821 1.1 kiyohara struct mbuf *m;
822 1.1 kiyohara struct m_tag *mtag;
823 1.1 kiyohara struct ifnet *ifp;
824 1.22 kiyohara struct fwip_softc *sc;
825 1.1 kiyohara struct fw_pkt *fp;
826 1.1 kiyohara int rtcode;
827 1.1 kiyohara
828 1.22 kiyohara sc = (struct fwip_softc *)xfer->sc;
829 1.22 kiyohara ifp = sc->sc_eth.fwip_ifp;
830 1.1 kiyohara m = xfer->mbuf;
831 1.1 kiyohara xfer->mbuf = 0;
832 1.1 kiyohara fp = &xfer->recv.hdr;
833 1.1 kiyohara
834 1.1 kiyohara /*
835 1.1 kiyohara * Check the fifo address - we only accept addresses of
836 1.1 kiyohara * exactly INET_FIFO.
837 1.1 kiyohara */
838 1.1 kiyohara address = ((uint64_t)fp->mode.wreqb.dest_hi << 32)
839 1.1 kiyohara | fp->mode.wreqb.dest_lo;
840 1.1 kiyohara if (fp->mode.wreqb.tcode != FWTCODE_WREQB) {
841 1.1 kiyohara rtcode = FWRCODE_ER_TYPE;
842 1.1 kiyohara } else if (address != INET_FIFO) {
843 1.1 kiyohara rtcode = FWRCODE_ER_ADDR;
844 1.1 kiyohara } else {
845 1.1 kiyohara rtcode = FWRCODE_COMPLETE;
846 1.1 kiyohara }
847 1.1 kiyohara
848 1.1 kiyohara /*
849 1.1 kiyohara * Pick up a new mbuf and stick it on the back of the receive
850 1.1 kiyohara * queue.
851 1.1 kiyohara */
852 1.22 kiyohara fwip_unicast_input_recycle(sc, xfer);
853 1.1 kiyohara
854 1.1 kiyohara /*
855 1.1 kiyohara * If we've already rejected the packet, give up now.
856 1.1 kiyohara */
857 1.1 kiyohara if (rtcode != FWRCODE_COMPLETE) {
858 1.1 kiyohara m_freem(m);
859 1.30 thorpej if_statinc(ifp, if_ierrors);
860 1.1 kiyohara return;
861 1.1 kiyohara }
862 1.1 kiyohara
863 1.22 kiyohara if (ifp->if_bpf) {
864 1.1 kiyohara /*
865 1.1 kiyohara * Record the sender ID for possible BPF usage.
866 1.1 kiyohara */
867 1.22 kiyohara mtag = m_tag_get(MTAG_FIREWIRE_SENDER_EUID,
868 1.22 kiyohara 2 * sizeof(uint32_t), M_NOWAIT);
869 1.1 kiyohara if (mtag) {
870 1.1 kiyohara /* bpf wants it in network byte order */
871 1.1 kiyohara struct fw_device *fd;
872 1.1 kiyohara uint32_t *p = (uint32_t *) (mtag + 1);
873 1.22 kiyohara
874 1.22 kiyohara fd = fw_noderesolve_nodeid(sc->sc_fd.fc,
875 1.1 kiyohara fp->mode.wreqb.src & 0x3f);
876 1.1 kiyohara if (fd) {
877 1.1 kiyohara p[0] = htonl(fd->eui.hi);
878 1.1 kiyohara p[1] = htonl(fd->eui.lo);
879 1.1 kiyohara } else {
880 1.1 kiyohara p[0] = 0;
881 1.1 kiyohara p[1] = 0;
882 1.1 kiyohara }
883 1.1 kiyohara m_tag_prepend(m, mtag);
884 1.1 kiyohara }
885 1.1 kiyohara }
886 1.1 kiyohara
887 1.1 kiyohara /*
888 1.1 kiyohara * Hand off to the generic encapsulation code. We don't use
889 1.1 kiyohara * ifp->if_input so that we can pass the source nodeid as an
890 1.1 kiyohara * argument to facilitate link-level fragment reassembly.
891 1.1 kiyohara */
892 1.1 kiyohara m->m_len = m->m_pkthdr.len = fp->mode.wreqb.len;
893 1.27 ozaki m_set_rcvif(m, ifp);
894 1.22 kiyohara ieee1394_input(ifp, m, fp->mode.wreqb.src);
895 1.30 thorpej if_statinc(ifp, if_ipackets);
896 1.1 kiyohara }
897