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