Wed Jan 29 06:19:39 2020 UTC ()
Adopt <net/if_stats.h>.


(thorpej)
diff -r1.29 -r1.30 src/sys/dev/ieee1394/if_fwip.c

cvs diff -r1.29 -r1.30 src/sys/dev/ieee1394/if_fwip.c (expand / switch to unified diff)

--- src/sys/dev/ieee1394/if_fwip.c 2018/11/15 10:23:55 1.29
+++ src/sys/dev/ieee1394/if_fwip.c 2020/01/29 06:19:39 1.30
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_fwip.c,v 1.29 2018/11/15 10:23:55 maxv Exp $ */ 1/* $NetBSD: if_fwip.c,v 1.30 2020/01/29 06:19:39 thorpej Exp $ */
2/*- 2/*-
3 * Copyright (c) 2004 3 * Copyright (c) 2004
4 * Doug Rabson 4 * Doug Rabson
5 * Copyright (c) 2002-2003 5 * Copyright (c) 2002-2003
6 * Hidetoshi Shimokawa. All rights reserved. 6 * Hidetoshi Shimokawa. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE. 35 * SUCH DAMAGE.
36 * 36 *
37 * $FreeBSD: src/sys/dev/firewire/if_fwip.c,v 1.18 2009/02/09 16:58:18 fjoe Exp $ 37 * $FreeBSD: src/sys/dev/firewire/if_fwip.c,v 1.18 2009/02/09 16:58:18 fjoe Exp $
38 */ 38 */
39 39
40#include <sys/cdefs.h> 40#include <sys/cdefs.h>
41__KERNEL_RCSID(0, "$NetBSD: if_fwip.c,v 1.29 2018/11/15 10:23:55 maxv Exp $"); 41__KERNEL_RCSID(0, "$NetBSD: if_fwip.c,v 1.30 2020/01/29 06:19:39 thorpej Exp $");
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/bus.h> 44#include <sys/bus.h>
45#include <sys/device.h> 45#include <sys/device.h>
46#include <sys/errno.h> 46#include <sys/errno.h>
47#include <sys/malloc.h> 47#include <sys/malloc.h>
48#include <sys/mbuf.h> 48#include <sys/mbuf.h>
49#include <sys/mutex.h> 49#include <sys/mutex.h>
50#include <sys/sysctl.h> 50#include <sys/sysctl.h>
51 51
52#include <net/bpf.h> 52#include <net/bpf.h>
53#include <net/if.h> 53#include <net/if.h>
54#include <net/if_ieee1394.h> 54#include <net/if_ieee1394.h>
@@ -260,27 +260,27 @@ fwip_start(struct ifnet *ifp) @@ -260,27 +260,27 @@ fwip_start(struct ifnet *ifp)
260 struct fwip_softc *sc = ((struct fwip_eth_softc *)ifp->if_softc)->fwip; 260 struct fwip_softc *sc = ((struct fwip_eth_softc *)ifp->if_softc)->fwip;
261 261
262 FWIPDEBUG(ifp, "starting\n"); 262 FWIPDEBUG(ifp, "starting\n");
263 263
264 if (sc->sc_dma_ch < 0) { 264 if (sc->sc_dma_ch < 0) {
265 struct mbuf *m = NULL; 265 struct mbuf *m = NULL;
266 266
267 FWIPDEBUG(ifp, "not ready\n"); 267 FWIPDEBUG(ifp, "not ready\n");
268 268
269 do { 269 do {
270 IF_DEQUEUE(&ifp->if_snd, m); 270 IF_DEQUEUE(&ifp->if_snd, m);
271 if (m != NULL) 271 if (m != NULL)
272 m_freem(m); 272 m_freem(m);
273 ifp->if_oerrors++; 273 if_statinc(ifp, if_oerrors);
274 } while (m != NULL); 274 } while (m != NULL);
275 275
276 return; 276 return;
277 } 277 }
278 278
279 ifp->if_flags |= IFF_OACTIVE; 279 ifp->if_flags |= IFF_OACTIVE;
280 280
281 if (ifp->if_snd.ifq_len != 0) 281 if (ifp->if_snd.ifq_len != 0)
282 fwip_async_output(sc, ifp); 282 fwip_async_output(sc, ifp);
283 283
284 ifp->if_flags &= ~IFF_OACTIVE; 284 ifp->if_flags &= ~IFF_OACTIVE;
285} 285}
286 286
@@ -501,27 +501,27 @@ fwip_post_busreset(void *arg) @@ -501,27 +501,27 @@ fwip_post_busreset(void *arg)
501 ieee1394_drain(sc->sc_eth.fwip_ifp); 501 ieee1394_drain(sc->sc_eth.fwip_ifp);
502} 502}
503 503
504static void 504static void
505fwip_output_callback(struct fw_xfer *xfer) 505fwip_output_callback(struct fw_xfer *xfer)
506{ 506{
507 struct fwip_softc *sc = (struct fwip_softc *)xfer->sc; 507 struct fwip_softc *sc = (struct fwip_softc *)xfer->sc;
508 struct ifnet *ifp; 508 struct ifnet *ifp;
509 509
510 ifp = sc->sc_eth.fwip_ifp; 510 ifp = sc->sc_eth.fwip_ifp;
511 /* XXX error check */ 511 /* XXX error check */
512 FWIPDEBUG(ifp, "resp = %d\n", xfer->resp); 512 FWIPDEBUG(ifp, "resp = %d\n", xfer->resp);
513 if (xfer->resp != 0) 513 if (xfer->resp != 0)
514 ifp->if_oerrors++; 514 if_statinc(ifp, if_oerrors);
515 515
516 m_freem(xfer->mbuf); 516 m_freem(xfer->mbuf);
517 fw_xfer_unload(xfer); 517 fw_xfer_unload(xfer);
518 518
519 mutex_enter(&sc->sc_mtx); 519 mutex_enter(&sc->sc_mtx);
520 STAILQ_INSERT_TAIL(&sc->sc_xferlist, xfer, link); 520 STAILQ_INSERT_TAIL(&sc->sc_xferlist, xfer, link);
521 mutex_exit(&sc->sc_mtx); 521 mutex_exit(&sc->sc_mtx);
522 522
523 /* for queue full */ 523 /* for queue full */
524 if (ifp->if_snd.ifq_head != NULL) 524 if (ifp->if_snd.ifq_head != NULL)
525 fwip_start(ifp); 525 fwip_start(ifp);
526} 526}
527 527
@@ -615,27 +615,27 @@ fwip_async_output(struct fwip_softc *sc, @@ -615,27 +615,27 @@ fwip_async_output(struct fwip_softc *sc,
615 * address is stored in network byte order to 615 * address is stored in network byte order to
616 * make life easier for ARP. 616 * make life easier for ARP.
617 */ 617 */
618 struct fw_device *fd; 618 struct fw_device *fd;
619 struct fw_eui64 eui; 619 struct fw_eui64 eui;
620 620
621 eui.hi = ntohl(destfw->sender_unique_ID_hi); 621 eui.hi = ntohl(destfw->sender_unique_ID_hi);
622 eui.lo = ntohl(destfw->sender_unique_ID_lo); 622 eui.lo = ntohl(destfw->sender_unique_ID_lo);
623 if (sc->sc_last_dest.hi != eui.hi || 623 if (sc->sc_last_dest.hi != eui.hi ||
624 sc->sc_last_dest.lo != eui.lo) { 624 sc->sc_last_dest.lo != eui.lo) {
625 fd = fw_noderesolve_eui64(fc, &eui); 625 fd = fw_noderesolve_eui64(fc, &eui);
626 if (!fd) { 626 if (!fd) {
627 /* error */ 627 /* error */
628 ifp->if_oerrors++; 628 if_statinc(ifp, if_oerrors);
629 /* XXX set error code */ 629 /* XXX set error code */
630 fwip_output_callback(xfer); 630 fwip_output_callback(xfer);
631 continue; 631 continue;
632 632
633 } 633 }
634 sc->sc_last_hdr.mode.wreqb.dst = 634 sc->sc_last_hdr.mode.wreqb.dst =
635 FWLOCALBUS | fd->dst; 635 FWLOCALBUS | fd->dst;
636 sc->sc_last_hdr.mode.wreqb.tlrt = 0; 636 sc->sc_last_hdr.mode.wreqb.tlrt = 0;
637 sc->sc_last_hdr.mode.wreqb.tcode = 637 sc->sc_last_hdr.mode.wreqb.tcode =
638 FWTCODE_WREQB; 638 FWTCODE_WREQB;
639 sc->sc_last_hdr.mode.wreqb.pri = 0; 639 sc->sc_last_hdr.mode.wreqb.pri = 0;
640 sc->sc_last_hdr.mode.wreqb.src = nodeid; 640 sc->sc_last_hdr.mode.wreqb.src = nodeid;
641 sc->sc_last_hdr.mode.wreqb.dest_hi = 641 sc->sc_last_hdr.mode.wreqb.dest_hi =
@@ -658,32 +658,32 @@ fwip_async_output(struct fwip_softc *sc, @@ -658,32 +658,32 @@ fwip_async_output(struct fwip_softc *sc,
658 /* 658 /*
659 * We ran out of tlabels - requeue the packet 659 * We ran out of tlabels - requeue the packet
660 * for later transmission. 660 * for later transmission.
661 */ 661 */
662 xfer->mbuf = 0; 662 xfer->mbuf = 0;
663 mutex_enter(&sc->sc_mtx); 663 mutex_enter(&sc->sc_mtx);
664 STAILQ_INSERT_TAIL(&sc->sc_xferlist, xfer, link); 664 STAILQ_INSERT_TAIL(&sc->sc_xferlist, xfer, link);
665 mutex_exit(&sc->sc_mtx); 665 mutex_exit(&sc->sc_mtx);
666 IF_PREPEND(&ifp->if_snd, m); 666 IF_PREPEND(&ifp->if_snd, m);
667 break; 667 break;
668 } 668 }
669 if (error) { 669 if (error) {
670 /* error */ 670 /* error */
671 ifp->if_oerrors++; 671 if_statinc(ifp, if_oerrors);
672 /* XXX set error code */ 672 /* XXX set error code */
673 fwip_output_callback(xfer); 673 fwip_output_callback(xfer);
674 continue; 674 continue;
675 } else { 675 } else {
676 ifp->if_opackets++; 676 if_statinc(ifp, if_opackets);
677 i++; 677 i++;
678 } 678 }
679 } 679 }
680#if 0 680#if 0
681 if (i > 1) 681 if (i > 1)
682 aprint_normal("%d queued\n", i); 682 aprint_normal("%d queued\n", i);
683#endif 683#endif
684 if (i > 0) 684 if (i > 0)
685 xferq->start(fc); 685 xferq->start(fc);
686} 686}
687 687
688/* Async. stream output */ 688/* Async. stream output */
689static void 689static void
@@ -716,54 +716,54 @@ fwip_stream_input(struct fw_xferq *xferq @@ -716,54 +716,54 @@ fwip_stream_input(struct fw_xferq *xferq
716 aprint_error_ifnet(ifp, 716 aprint_error_ifnet(ifp,
717 "fwip_as_input: m_getcl failed\n"); 717 "fwip_as_input: m_getcl failed\n");
718 718
719 /* 719 /*
720 * We must have a GASP header - leave the 720 * We must have a GASP header - leave the
721 * encapsulation sanity checks to the generic 721 * encapsulation sanity checks to the generic
722 * code. Remeber that we also have the firewire async 722 * code. Remeber that we also have the firewire async
723 * stream header even though that isn't accounted for 723 * stream header even though that isn't accounted for
724 * in mode.stream.len. 724 * in mode.stream.len.
725 */ 725 */
726 if (sxfer->resp != 0 || 726 if (sxfer->resp != 0 ||
727 fp->mode.stream.len < 2 * sizeof(uint32_t)) { 727 fp->mode.stream.len < 2 * sizeof(uint32_t)) {
728 m_freem(m); 728 m_freem(m);
729 ifp->if_ierrors++; 729 if_statinc(ifp, if_ierrors);
730 continue; 730 continue;
731 } 731 }
732 m->m_len = m->m_pkthdr.len = fp->mode.stream.len 732 m->m_len = m->m_pkthdr.len = fp->mode.stream.len
733 + sizeof(fp->mode.stream); 733 + sizeof(fp->mode.stream);
734 734
735 /* 735 /*
736 * If we received the packet on the broadcast channel, 736 * If we received the packet on the broadcast channel,
737 * mark it as broadcast, otherwise we assume it must 737 * mark it as broadcast, otherwise we assume it must
738 * be multicast. 738 * be multicast.
739 */ 739 */
740 if (fp->mode.stream.chtag == broadcast_channel) 740 if (fp->mode.stream.chtag == broadcast_channel)
741 m->m_flags |= M_BCAST; 741 m->m_flags |= M_BCAST;
742 else 742 else
743 m->m_flags |= M_MCAST; 743 m->m_flags |= M_MCAST;
744 744
745 /* 745 /*
746 * Make sure we recognise the GASP specifier and 746 * Make sure we recognise the GASP specifier and
747 * version. 747 * version.
748 */ 748 */
749 p = mtod(m, uint32_t *); 749 p = mtod(m, uint32_t *);
750 if ((((ntohl(p[1]) & 0xffff) << 8) | ntohl(p[2]) >> 24) != 750 if ((((ntohl(p[1]) & 0xffff) << 8) | ntohl(p[2]) >> 24) !=
751 0x00005e || 751 0x00005e ||
752 (ntohl(p[2]) & 0xffffff) != 1) { 752 (ntohl(p[2]) & 0xffffff) != 1) {
753 FWIPDEBUG(ifp, "Unrecognised GASP header %#08x %#08x\n", 753 FWIPDEBUG(ifp, "Unrecognised GASP header %#08x %#08x\n",
754 ntohl(p[1]), ntohl(p[2])); 754 ntohl(p[1]), ntohl(p[2]));
755 m_freem(m); 755 m_freem(m);
756 ifp->if_ierrors++; 756 if_statinc(ifp, if_ierrors);
757 continue; 757 continue;
758 } 758 }
759 759
760 /* 760 /*
761 * Record the sender ID for possible BPF usage. 761 * Record the sender ID for possible BPF usage.
762 */ 762 */
763 src = ntohl(p[1]) >> 16; 763 src = ntohl(p[1]) >> 16;
764 if (ifp->if_bpf) { 764 if (ifp->if_bpf) {
765 mtag = m_tag_get(MTAG_FIREWIRE_SENDER_EUID, 765 mtag = m_tag_get(MTAG_FIREWIRE_SENDER_EUID,
766 2 * sizeof(uint32_t), M_NOWAIT); 766 2 * sizeof(uint32_t), M_NOWAIT);
767 if (mtag) { 767 if (mtag) {
768 /* bpf wants it in network byte order */ 768 /* bpf wants it in network byte order */
769 struct fw_device *fd; 769 struct fw_device *fd;
@@ -778,27 +778,27 @@ fwip_stream_input(struct fw_xferq *xferq @@ -778,27 +778,27 @@ fwip_stream_input(struct fw_xferq *xferq
778 p2[0] = 0; 778 p2[0] = 0;
779 p2[1] = 0; 779 p2[1] = 0;
780 } 780 }
781 m_tag_prepend(m, mtag); 781 m_tag_prepend(m, mtag);
782 } 782 }
783 } 783 }
784 784
785 /* 785 /*
786 * Trim off the GASP header 786 * Trim off the GASP header
787 */ 787 */
788 m_adj(m, 3*sizeof(uint32_t)); 788 m_adj(m, 3*sizeof(uint32_t));
789 m_set_rcvif(m, ifp); 789 m_set_rcvif(m, ifp);
790 ieee1394_input(ifp, m, src); 790 ieee1394_input(ifp, m, src);
791 ifp->if_ipackets++; 791 if_statinc(ifp, if_ipackets);
792 } 792 }
793 if (STAILQ_FIRST(&xferq->stfree) != NULL) 793 if (STAILQ_FIRST(&xferq->stfree) != NULL)
794 sc->sc_fd.fc->irx_enable(sc->sc_fd.fc, sc->sc_dma_ch); 794 sc->sc_fd.fc->irx_enable(sc->sc_fd.fc, sc->sc_dma_ch);
795} 795}
796 796
797static inline void 797static inline void
798fwip_unicast_input_recycle(struct fwip_softc *sc, struct fw_xfer *xfer) 798fwip_unicast_input_recycle(struct fwip_softc *sc, struct fw_xfer *xfer)
799{ 799{
800 struct mbuf *m; 800 struct mbuf *m;
801 801
802 /* 802 /*
803 * We have finished with a unicast xfer. Allocate a new 803 * We have finished with a unicast xfer. Allocate a new
804 * cluster and stick it on the back of the input queue. 804 * cluster and stick it on the back of the input queue.
@@ -847,27 +847,27 @@ fwip_unicast_input(struct fw_xfer *xfer) @@ -847,27 +847,27 @@ fwip_unicast_input(struct fw_xfer *xfer)
847 } 847 }
848 848
849 /* 849 /*
850 * Pick up a new mbuf and stick it on the back of the receive 850 * Pick up a new mbuf and stick it on the back of the receive
851 * queue. 851 * queue.
852 */ 852 */
853 fwip_unicast_input_recycle(sc, xfer); 853 fwip_unicast_input_recycle(sc, xfer);
854 854
855 /* 855 /*
856 * If we've already rejected the packet, give up now. 856 * If we've already rejected the packet, give up now.
857 */ 857 */
858 if (rtcode != FWRCODE_COMPLETE) { 858 if (rtcode != FWRCODE_COMPLETE) {
859 m_freem(m); 859 m_freem(m);
860 ifp->if_ierrors++; 860 if_statinc(ifp, if_ierrors);
861 return; 861 return;
862 } 862 }
863 863
864 if (ifp->if_bpf) { 864 if (ifp->if_bpf) {
865 /* 865 /*
866 * Record the sender ID for possible BPF usage. 866 * Record the sender ID for possible BPF usage.
867 */ 867 */
868 mtag = m_tag_get(MTAG_FIREWIRE_SENDER_EUID, 868 mtag = m_tag_get(MTAG_FIREWIRE_SENDER_EUID,
869 2 * sizeof(uint32_t), M_NOWAIT); 869 2 * sizeof(uint32_t), M_NOWAIT);
870 if (mtag) { 870 if (mtag) {
871 /* bpf wants it in network byte order */ 871 /* bpf wants it in network byte order */
872 struct fw_device *fd; 872 struct fw_device *fd;
873 uint32_t *p = (uint32_t *) (mtag + 1); 873 uint32_t *p = (uint32_t *) (mtag + 1);
@@ -883,15 +883,15 @@ fwip_unicast_input(struct fw_xfer *xfer) @@ -883,15 +883,15 @@ fwip_unicast_input(struct fw_xfer *xfer)
883 } 883 }
884 m_tag_prepend(m, mtag); 884 m_tag_prepend(m, mtag);
885 } 885 }
886 } 886 }
887 887
888 /* 888 /*
889 * Hand off to the generic encapsulation code. We don't use 889 * Hand off to the generic encapsulation code. We don't use
890 * ifp->if_input so that we can pass the source nodeid as an 890 * ifp->if_input so that we can pass the source nodeid as an
891 * argument to facilitate link-level fragment reassembly. 891 * argument to facilitate link-level fragment reassembly.
892 */ 892 */
893 m->m_len = m->m_pkthdr.len = fp->mode.wreqb.len; 893 m->m_len = m->m_pkthdr.len = fp->mode.wreqb.len;
894 m_set_rcvif(m, ifp); 894 m_set_rcvif(m, ifp);
895 ieee1394_input(ifp, m, fp->mode.wreqb.src); 895 ieee1394_input(ifp, m, fp->mode.wreqb.src);
896 ifp->if_ipackets++; 896 if_statinc(ifp, if_ipackets);
897} 897}