if_axe.c (196219) | if_axe.c (197566) |
---|---|
1/*- 2 * Copyright (c) 1997, 1998, 1999, 2000-2003 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1997, 1998, 1999, 2000-2003 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/dev/usb/net/if_axe.c 196219 2009-08-14 20:03:53Z jhb $"); | 34__FBSDID("$FreeBSD: head/sys/dev/usb/net/if_axe.c 197566 2009-09-28 08:03:52Z thompsa $"); |
35 36/* 37 * ASIX Electronics AX88172/AX88178/AX88778 USB 2.0 ethernet driver. 38 * Used in the LinkSys USB200M and various other adapters. 39 * 40 * Manuals available from: 41 * http://www.asix.com.tw/datasheet/mac/Ax88172.PDF 42 * Note: you need the manual for the AX88170 chip (USB 1.x ethernet --- 157 unchanged lines hidden (view full) --- 200 .callback = axe_bulk_write_callback, 201 .timeout = 10000, /* 10 seconds */ 202 }, 203 204 [AXE_BULK_DT_RD] = { 205 .type = UE_BULK, 206 .endpoint = UE_ADDR_ANY, 207 .direction = UE_DIR_IN, | 35 36/* 37 * ASIX Electronics AX88172/AX88178/AX88778 USB 2.0 ethernet driver. 38 * Used in the LinkSys USB200M and various other adapters. 39 * 40 * Manuals available from: 41 * http://www.asix.com.tw/datasheet/mac/Ax88172.PDF 42 * Note: you need the manual for the AX88170 chip (USB 1.x ethernet --- 157 unchanged lines hidden (view full) --- 200 .callback = axe_bulk_write_callback, 201 .timeout = 10000, /* 10 seconds */ 202 }, 203 204 [AXE_BULK_DT_RD] = { 205 .type = UE_BULK, 206 .endpoint = UE_ADDR_ANY, 207 .direction = UE_DIR_IN, |
208#if (MCLBYTES < 2048) 209#error "(MCLBYTES < 2048)" 210#endif 211 .bufsize = MCLBYTES, | 208 .bufsize = 16384, /* bytes */ |
212 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 213 .callback = axe_bulk_read_callback, 214 .timeout = 0, /* no timeout */ 215 }, 216 217 [AXE_INTR_DT_RD] = { 218 .type = UE_INTERRUPT, 219 .endpoint = UE_ADDR_ANY, --- 552 unchanged lines hidden (view full) --- 772static void 773axe_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error) 774{ 775 struct axe_softc *sc = usbd_xfer_softc(xfer); 776 struct usb_ether *ue = &sc->sc_ue; 777 struct ifnet *ifp = uether_getifp(ue); 778 struct axe_sframe_hdr hdr; 779 struct usb_page_cache *pc; | 209 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 210 .callback = axe_bulk_read_callback, 211 .timeout = 0, /* no timeout */ 212 }, 213 214 [AXE_INTR_DT_RD] = { 215 .type = UE_INTERRUPT, 216 .endpoint = UE_ADDR_ANY, --- 552 unchanged lines hidden (view full) --- 769static void 770axe_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error) 771{ 772 struct axe_softc *sc = usbd_xfer_softc(xfer); 773 struct usb_ether *ue = &sc->sc_ue; 774 struct ifnet *ifp = uether_getifp(ue); 775 struct axe_sframe_hdr hdr; 776 struct usb_page_cache *pc; |
780 int err, pos, len, adjust; | 777 int err, pos, len; |
781 int actlen; 782 783 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 784 785 switch (USB_GET_STATE(xfer)) { 786 case USB_ST_TRANSFERRED: 787 pos = 0; | 778 int actlen; 779 780 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 781 782 switch (USB_GET_STATE(xfer)) { 783 case USB_ST_TRANSFERRED: 784 pos = 0; |
785 len = 0; 786 err = 0; 787 |
|
788 pc = usbd_xfer_get_frame(xfer, 0); | 788 pc = usbd_xfer_get_frame(xfer, 0); |
789 while (1) { 790 if (sc->sc_flags & (AXE_FLAG_772 | AXE_FLAG_178)) { 791 if (actlen < sizeof(hdr)) { | 789 if (sc->sc_flags & (AXE_FLAG_772 | AXE_FLAG_178)) { 790 while (pos < actlen) { 791 if ((pos + sizeof(hdr)) > actlen) { |
792 /* too little data */ | 792 /* too little data */ |
793 err = EINVAL; |
|
793 break; 794 } 795 usbd_copy_out(pc, pos, &hdr, sizeof(hdr)); 796 797 if ((hdr.len ^ hdr.ilen) != 0xFFFF) { 798 /* we lost sync */ | 794 break; 795 } 796 usbd_copy_out(pc, pos, &hdr, sizeof(hdr)); 797 798 if ((hdr.len ^ hdr.ilen) != 0xFFFF) { 799 /* we lost sync */ |
800 err = EINVAL; |
|
799 break; 800 } | 801 break; 802 } |
801 actlen -= sizeof(hdr); | |
802 pos += sizeof(hdr); 803 804 len = le16toh(hdr.len); | 803 pos += sizeof(hdr); 804 805 len = le16toh(hdr.len); |
805 if (len > actlen) { | 806 if ((pos + len) > actlen) { |
806 /* invalid length */ | 807 /* invalid length */ |
808 err = EINVAL; |
|
807 break; 808 } | 809 break; 810 } |
809 adjust = (len & 1); | 811 err = uether_rxbuf(ue, pc, pos, len); |
810 | 812 |
811 } else { 812 len = actlen; 813 adjust = 0; | 813 pos += len + (len % 2); |
814 } | 814 } |
815 err = uether_rxbuf(ue, pc, pos, len); 816 if (err) 817 break; 818 819 pos += len; 820 actlen -= len; 821 822 if (actlen <= adjust) { 823 /* we are finished */ 824 goto tr_setup; 825 } 826 pos += adjust; 827 actlen -= adjust; | 815 } else { 816 err = uether_rxbuf(ue, pc, 0, actlen); |
828 } 829 | 817 } 818 |
830 /* count an error */ 831 ifp->if_ierrors++; | 819 if (err != 0) 820 ifp->if_ierrors++; |
832 833 /* FALLTHROUGH */ 834 case USB_ST_SETUP: 835tr_setup: 836 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 837 usbd_transfer_submit(xfer); 838 uether_rxflush(ue); 839 return; --- 166 unchanged lines hidden (view full) --- 1006 axe_cmd(sc, AXE_172_CMD_WRITE_IPG0, 0, sc->sc_ipgs[0], NULL); 1007 axe_cmd(sc, AXE_172_CMD_WRITE_IPG1, 0, sc->sc_ipgs[1], NULL); 1008 axe_cmd(sc, AXE_172_CMD_WRITE_IPG2, 0, sc->sc_ipgs[2], NULL); 1009 } 1010 1011 /* Enable receiver, set RX mode */ 1012 rxmode = (AXE_RXCMD_MULTICAST | AXE_RXCMD_ENABLE); 1013 if (sc->sc_flags & (AXE_FLAG_178 | AXE_FLAG_772)) { | 821 822 /* FALLTHROUGH */ 823 case USB_ST_SETUP: 824tr_setup: 825 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 826 usbd_transfer_submit(xfer); 827 uether_rxflush(ue); 828 return; --- 166 unchanged lines hidden (view full) --- 995 axe_cmd(sc, AXE_172_CMD_WRITE_IPG0, 0, sc->sc_ipgs[0], NULL); 996 axe_cmd(sc, AXE_172_CMD_WRITE_IPG1, 0, sc->sc_ipgs[1], NULL); 997 axe_cmd(sc, AXE_172_CMD_WRITE_IPG2, 0, sc->sc_ipgs[2], NULL); 998 } 999 1000 /* Enable receiver, set RX mode */ 1001 rxmode = (AXE_RXCMD_MULTICAST | AXE_RXCMD_ENABLE); 1002 if (sc->sc_flags & (AXE_FLAG_178 | AXE_FLAG_772)) { |
1003#if 0 |
|
1014 rxmode |= AXE_178_RXCMD_MFB_2048; /* chip default */ | 1004 rxmode |= AXE_178_RXCMD_MFB_2048; /* chip default */ |
1005#else 1006 /* 1007 * Default Rx buffer size is too small to get 1008 * maximum performance. 1009 */ 1010 rxmode |= AXE_178_RXCMD_MFB_16384; 1011#endif |
|
1015 } else { 1016 rxmode |= AXE_172_RXCMD_UNICAST; 1017 } 1018 1019 /* If we want promiscuous mode, set the allframes bit. */ 1020 if (ifp->if_flags & IFF_PROMISC) 1021 rxmode |= AXE_RXCMD_PROMISC; 1022 --- 56 unchanged lines hidden --- | 1012 } else { 1013 rxmode |= AXE_172_RXCMD_UNICAST; 1014 } 1015 1016 /* If we want promiscuous mode, set the allframes bit. */ 1017 if (ifp->if_flags & IFF_PROMISC) 1018 rxmode |= AXE_RXCMD_PROMISC; 1019 --- 56 unchanged lines hidden --- |