Deleted Added
full compact
if_rue.c (194228) if_rue.c (194677)
1/*-
2 * Copyright (c) 2001-2003, Shunsuke Akiyama <akiyama@FreeBSD.org>.
3 * Copyright (c) 1997, 1998, 1999, 2000 Bill Paul <wpaul@ee.columbia.edu>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 43 unchanged lines hidden (view full) ---

52 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
56 * THE POSSIBILITY OF SUCH DAMAGE.
57 */
58
59#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001-2003, Shunsuke Akiyama <akiyama@FreeBSD.org>.
3 * Copyright (c) 1997, 1998, 1999, 2000 Bill Paul <wpaul@ee.columbia.edu>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 43 unchanged lines hidden (view full) ---

52 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
56 * THE POSSIBILITY OF SUCH DAMAGE.
57 */
58
59#include <sys/cdefs.h>
60__FBSDID("$FreeBSD: head/sys/dev/usb/net/if_rue.c 194228 2009-06-15 01:02:43Z thompsa $");
60__FBSDID("$FreeBSD: head/sys/dev/usb/net/if_rue.c 194677 2009-06-23 02:19:59Z thompsa $");
61
62/*
63 * RealTek RTL8150 USB to fast ethernet controller driver.
64 * Datasheet is available from
65 * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/.
66 */
67
61
62/*
63 * RealTek RTL8150 USB to fast ethernet controller driver.
64 * Datasheet is available from
65 * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/.
66 */
67
68#include "usbdevs.h"
68#include <sys/stdint.h>
69#include <sys/stddef.h>
70#include <sys/param.h>
71#include <sys/queue.h>
72#include <sys/types.h>
73#include <sys/systm.h>
74#include <sys/kernel.h>
75#include <sys/bus.h>
76#include <sys/linker_set.h>
77#include <sys/module.h>
78#include <sys/lock.h>
79#include <sys/mutex.h>
80#include <sys/condvar.h>
81#include <sys/sysctl.h>
82#include <sys/sx.h>
83#include <sys/unistd.h>
84#include <sys/callout.h>
85#include <sys/malloc.h>
86#include <sys/priv.h>
87
69#include <dev/usb/usb.h>
88#include <dev/usb/usb.h>
70#include <dev/usb/usb_mfunc.h>
71#include <dev/usb/usb_error.h>
89#include <dev/usb/usbdi.h>
90#include <dev/usb/usbdi_util.h>
91#include "usbdevs.h"
72
73#define USB_DEBUG_VAR rue_debug
92
93#define USB_DEBUG_VAR rue_debug
74
75#include <dev/usb/usb_core.h>
76#include <dev/usb/usb_lookup.h>
77#include <dev/usb/usb_process.h>
78#include <dev/usb/usb_debug.h>
94#include <dev/usb/usb_debug.h>
79#include <dev/usb/usb_request.h>
80#include <dev/usb/usb_busdma.h>
81#include <dev/usb/usb_util.h>
95#include <dev/usb/usb_process.h>
82
83#include <dev/usb/net/usb_ethernet.h>
84#include <dev/usb/net/if_ruereg.h>
85
86#if USB_DEBUG
87static int rue_debug = 0;
88
89SYSCTL_NODE(_hw_usb, OID_AUTO, rue, CTLFLAG_RW, 0, "USB rue");

--- 518 unchanged lines hidden (view full) ---

608 usbd_transfer_unsetup(sc->sc_xfer, RUE_N_TRANSFER);
609 uether_ifdetach(ue);
610 mtx_destroy(&sc->sc_mtx);
611
612 return (0);
613}
614
615static void
96
97#include <dev/usb/net/usb_ethernet.h>
98#include <dev/usb/net/if_ruereg.h>
99
100#if USB_DEBUG
101static int rue_debug = 0;
102
103SYSCTL_NODE(_hw_usb, OID_AUTO, rue, CTLFLAG_RW, 0, "USB rue");

--- 518 unchanged lines hidden (view full) ---

622 usbd_transfer_unsetup(sc->sc_xfer, RUE_N_TRANSFER);
623 uether_ifdetach(ue);
624 mtx_destroy(&sc->sc_mtx);
625
626 return (0);
627}
628
629static void
616rue_intr_callback(struct usb_xfer *xfer)
630rue_intr_callback(struct usb_xfer *xfer, usb_error_t error)
617{
631{
618 struct rue_softc *sc = xfer->priv_sc;
632 struct rue_softc *sc = usbd_xfer_softc(xfer);
619 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
620 struct rue_intrpkt pkt;
633 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
634 struct rue_intrpkt pkt;
635 struct usb_page_cache *pc;
636 int actlen;
621
637
638 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
639
622 switch (USB_GET_STATE(xfer)) {
623 case USB_ST_TRANSFERRED:
624
625 if (ifp && (ifp->if_drv_flags & IFF_DRV_RUNNING) &&
640 switch (USB_GET_STATE(xfer)) {
641 case USB_ST_TRANSFERRED:
642
643 if (ifp && (ifp->if_drv_flags & IFF_DRV_RUNNING) &&
626 (xfer->actlen >= sizeof(pkt))) {
644 actlen >= sizeof(pkt)) {
627
645
628 usbd_copy_out(xfer->frbuffers, 0, &pkt, sizeof(pkt));
646 pc = usbd_xfer_get_frame(xfer, 0);
647 usbd_copy_out(pc, 0, &pkt, sizeof(pkt));
629
630 ifp->if_ierrors += pkt.rue_rxlost_cnt;
631 ifp->if_ierrors += pkt.rue_crcerr_cnt;
632 ifp->if_collisions += pkt.rue_col_cnt;
633 }
634 /* FALLTHROUGH */
635 case USB_ST_SETUP:
636tr_setup:
648
649 ifp->if_ierrors += pkt.rue_rxlost_cnt;
650 ifp->if_ierrors += pkt.rue_crcerr_cnt;
651 ifp->if_collisions += pkt.rue_col_cnt;
652 }
653 /* FALLTHROUGH */
654 case USB_ST_SETUP:
655tr_setup:
637 xfer->frlengths[0] = xfer->max_data_length;
656 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
638 usbd_transfer_submit(xfer);
639 return;
640
641 default: /* Error */
657 usbd_transfer_submit(xfer);
658 return;
659
660 default: /* Error */
642 if (xfer->error != USB_ERR_CANCELLED) {
661 if (error != USB_ERR_CANCELLED) {
643 /* try to clear stall first */
662 /* try to clear stall first */
644 xfer->flags.stall_pipe = 1;
663 usbd_xfer_set_stall(xfer);
645 goto tr_setup;
646 }
647 return;
648 }
649}
650
651static void
664 goto tr_setup;
665 }
666 return;
667 }
668}
669
670static void
652rue_bulk_read_callback(struct usb_xfer *xfer)
671rue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
653{
672{
654 struct rue_softc *sc = xfer->priv_sc;
673 struct rue_softc *sc = usbd_xfer_softc(xfer);
655 struct usb_ether *ue = &sc->sc_ue;
656 struct ifnet *ifp = uether_getifp(ue);
674 struct usb_ether *ue = &sc->sc_ue;
675 struct ifnet *ifp = uether_getifp(ue);
676 struct usb_page_cache *pc;
657 uint16_t status;
677 uint16_t status;
678 int actlen;
658
679
680 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
681
659 switch (USB_GET_STATE(xfer)) {
660 case USB_ST_TRANSFERRED:
661
682 switch (USB_GET_STATE(xfer)) {
683 case USB_ST_TRANSFERRED:
684
662 if (xfer->actlen < 4) {
685 if (actlen < 4) {
663 ifp->if_ierrors++;
664 goto tr_setup;
665 }
686 ifp->if_ierrors++;
687 goto tr_setup;
688 }
666 usbd_copy_out(xfer->frbuffers, xfer->actlen - 4,
667 &status, sizeof(status));
668 xfer->actlen -= 4;
689 pc = usbd_xfer_get_frame(xfer, 0);
690 usbd_copy_out(pc, actlen - 4, &status, sizeof(status));
691 actlen -= 4;
669
670 /* check recieve packet was valid or not */
671 status = le16toh(status);
672 if ((status & RUE_RXSTAT_VALID) == 0) {
673 ifp->if_ierrors++;
674 goto tr_setup;
675 }
692
693 /* check recieve packet was valid or not */
694 status = le16toh(status);
695 if ((status & RUE_RXSTAT_VALID) == 0) {
696 ifp->if_ierrors++;
697 goto tr_setup;
698 }
676 uether_rxbuf(ue, xfer->frbuffers, 0, xfer->actlen);
699 uether_rxbuf(ue, pc, 0, actlen);
677 /* FALLTHROUGH */
678 case USB_ST_SETUP:
679tr_setup:
700 /* FALLTHROUGH */
701 case USB_ST_SETUP:
702tr_setup:
680 xfer->frlengths[0] = xfer->max_data_length;
703 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
681 usbd_transfer_submit(xfer);
682 uether_rxflush(ue);
683 return;
684
685 default: /* Error */
686 DPRINTF("bulk read error, %s\n",
704 usbd_transfer_submit(xfer);
705 uether_rxflush(ue);
706 return;
707
708 default: /* Error */
709 DPRINTF("bulk read error, %s\n",
687 usbd_errstr(xfer->error));
710 usbd_errstr(error));
688
711
689 if (xfer->error != USB_ERR_CANCELLED) {
712 if (error != USB_ERR_CANCELLED) {
690 /* try to clear stall first */
713 /* try to clear stall first */
691 xfer->flags.stall_pipe = 1;
714 usbd_xfer_set_stall(xfer);
692 goto tr_setup;
693 }
694 return;
695 }
696}
697
698static void
715 goto tr_setup;
716 }
717 return;
718 }
719}
720
721static void
699rue_bulk_write_callback(struct usb_xfer *xfer)
722rue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
700{
723{
701 struct rue_softc *sc = xfer->priv_sc;
724 struct rue_softc *sc = usbd_xfer_softc(xfer);
702 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
725 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
726 struct usb_page_cache *pc;
703 struct mbuf *m;
704 int temp_len;
705
706 switch (USB_GET_STATE(xfer)) {
707 case USB_ST_TRANSFERRED:
708 DPRINTFN(11, "transfer complete\n");
709 ifp->if_opackets++;
710

--- 9 unchanged lines hidden (view full) ---

720 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
721
722 if (m == NULL)
723 return;
724 if (m->m_pkthdr.len > MCLBYTES)
725 m->m_pkthdr.len = MCLBYTES;
726 temp_len = m->m_pkthdr.len;
727
727 struct mbuf *m;
728 int temp_len;
729
730 switch (USB_GET_STATE(xfer)) {
731 case USB_ST_TRANSFERRED:
732 DPRINTFN(11, "transfer complete\n");
733 ifp->if_opackets++;
734

--- 9 unchanged lines hidden (view full) ---

744 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
745
746 if (m == NULL)
747 return;
748 if (m->m_pkthdr.len > MCLBYTES)
749 m->m_pkthdr.len = MCLBYTES;
750 temp_len = m->m_pkthdr.len;
751
728 usbd_m_copy_in(xfer->frbuffers, 0,
729 m, 0, m->m_pkthdr.len);
752 pc = usbd_xfer_get_frame(xfer, 0);
753 usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
730
731 /*
732 * This is an undocumented behavior.
733 * RTL8150 chip doesn't send frame length smaller than
734 * RUE_MIN_FRAMELEN (60) byte packet.
735 */
736 if (temp_len < RUE_MIN_FRAMELEN) {
754
755 /*
756 * This is an undocumented behavior.
757 * RTL8150 chip doesn't send frame length smaller than
758 * RUE_MIN_FRAMELEN (60) byte packet.
759 */
760 if (temp_len < RUE_MIN_FRAMELEN) {
737 usbd_frame_zero(xfer->frbuffers, temp_len,
761 usbd_frame_zero(pc, temp_len,
738 RUE_MIN_FRAMELEN - temp_len);
739 temp_len = RUE_MIN_FRAMELEN;
740 }
762 RUE_MIN_FRAMELEN - temp_len);
763 temp_len = RUE_MIN_FRAMELEN;
764 }
741 xfer->frlengths[0] = temp_len;
765 usbd_xfer_set_frame_len(xfer, 0, temp_len);
742
743 /*
744 * if there's a BPF listener, bounce a copy
745 * of this frame to him:
746 */
747 BPF_MTAP(ifp, m);
748
749 m_freem(m);
750
751 usbd_transfer_submit(xfer);
752
753 return;
754
755 default: /* Error */
756 DPRINTFN(11, "transfer error, %s\n",
766
767 /*
768 * if there's a BPF listener, bounce a copy
769 * of this frame to him:
770 */
771 BPF_MTAP(ifp, m);
772
773 m_freem(m);
774
775 usbd_transfer_submit(xfer);
776
777 return;
778
779 default: /* Error */
780 DPRINTFN(11, "transfer error, %s\n",
757 usbd_errstr(xfer->error));
781 usbd_errstr(error));
758
759 ifp->if_oerrors++;
760
782
783 ifp->if_oerrors++;
784
761 if (xfer->error != USB_ERR_CANCELLED) {
785 if (error != USB_ERR_CANCELLED) {
762 /* try to clear stall first */
786 /* try to clear stall first */
763 xfer->flags.stall_pipe = 1;
787 usbd_xfer_set_stall(xfer);
764 goto tr_setup;
765 }
766 return;
767 }
768}
769
770static void
771rue_tick(struct usb_ether *ue)

--- 52 unchanged lines hidden (view full) ---

824 /* Load the multicast filter */
825 rue_setpromisc(ue);
826 /* Load the multicast filter. */
827 rue_setmulti(ue);
828
829 /* Enable RX and TX */
830 rue_csr_write_1(sc, RUE_CR, (RUE_CR_TE | RUE_CR_RE | RUE_CR_EP3CLREN));
831
788 goto tr_setup;
789 }
790 return;
791 }
792}
793
794static void
795rue_tick(struct usb_ether *ue)

--- 52 unchanged lines hidden (view full) ---

848 /* Load the multicast filter */
849 rue_setpromisc(ue);
850 /* Load the multicast filter. */
851 rue_setmulti(ue);
852
853 /* Enable RX and TX */
854 rue_csr_write_1(sc, RUE_CR, (RUE_CR_TE | RUE_CR_RE | RUE_CR_EP3CLREN));
855
832 usbd_transfer_set_stall(sc->sc_xfer[RUE_BULK_DT_WR]);
856 usbd_xfer_set_stall(sc->sc_xfer[RUE_BULK_DT_WR]);
833
834 ifp->if_drv_flags |= IFF_DRV_RUNNING;
835 rue_start(ue);
836}
837
838/*
839 * Set media options.
840 */

--- 57 unchanged lines hidden ---
857
858 ifp->if_drv_flags |= IFF_DRV_RUNNING;
859 rue_start(ue);
860}
861
862/*
863 * Set media options.
864 */

--- 57 unchanged lines hidden ---