if_aue.c (187970) | if_aue.c (188412) |
---|---|
1/*- 2 * Copyright (c) 1997, 1998, 1999, 2000 3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 4 * | 1/*- 2 * Copyright (c) 1997, 1998, 1999, 2000 3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 4 * |
5 * Copyright (c) 2006 6 * Alfred Perlstein <alfred@freebsd.org>. All rights reserved. 7 * |
|
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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. --- 13 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> | 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. --- 13 unchanged lines hidden (view full) --- 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 * THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/dev/usb2/ethernet/if_aue2.c 187970 2009-02-01 00:51:25Z thompsa $"); | 37__FBSDID("$FreeBSD: head/sys/dev/usb2/ethernet/if_aue2.c 188412 2009-02-09 22:02:38Z thompsa $"); |
35 36/* 37 * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver. 38 * Datasheet is available from http://www.admtek.com.tw. 39 * 40 * Written by Bill Paul <wpaul@ee.columbia.edu> 41 * Electrical Engineering Department 42 * Columbia University, New York City | 38 39/* 40 * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver. 41 * Datasheet is available from http://www.admtek.com.tw. 42 * 43 * Written by Bill Paul <wpaul@ee.columbia.edu> 44 * Electrical Engineering Department 45 * Columbia University, New York City |
46 * 47 * SMP locking by Alfred Perlstein <alfred@freebsd.org>. 48 * RED Inc. |
|
43 */ 44 45/* 46 * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet 47 * support: the control endpoint for reading/writing registers, burst 48 * read endpoint for packet reception, burst write for packet transmission 49 * and one for "interrupts." The chip uses the same RX filter scheme 50 * as the other ADMtek ethernet parts: one perfect filter entry for the 51 * the station address and a 64-bit multicast hash table. The chip supports 52 * both MII and HomePNA attachments. 53 * 54 * Since the maximum data transfer speed of USB is supposed to be 12Mbps, 55 * you're never really going to get 100Mbps speeds from this device. I 56 * think the idea is to allow the device to connect to 10 or 100Mbps 57 * networks, not necessarily to provide 100Mbps performance. Also, since 58 * the controller uses an external PHY chip, it's possible that board 59 * designers might simply choose a 10Mbps PHY. 60 * | 49 */ 50 51/* 52 * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet 53 * support: the control endpoint for reading/writing registers, burst 54 * read endpoint for packet reception, burst write for packet transmission 55 * and one for "interrupts." The chip uses the same RX filter scheme 56 * as the other ADMtek ethernet parts: one perfect filter entry for the 57 * the station address and a 64-bit multicast hash table. The chip supports 58 * both MII and HomePNA attachments. 59 * 60 * Since the maximum data transfer speed of USB is supposed to be 12Mbps, 61 * you're never really going to get 100Mbps speeds from this device. I 62 * think the idea is to allow the device to connect to 10 or 100Mbps 63 * networks, not necessarily to provide 100Mbps performance. Also, since 64 * the controller uses an external PHY chip, it's possible that board 65 * designers might simply choose a 10Mbps PHY. 66 * |
61 * Registers are accessed using usb2_do_request(). Packet transfers are 62 * done using usb2_transfer() and friends. | 67 * Registers are accessed using usb2_ether_do_request(). Packet 68 * transfers are done using usb2_transfer() and friends. |
63 */ 64 | 69 */ 70 |
65/* 66 * NOTE: all function names beginning like "aue_cfg_" can only 67 * be called from within the config thread function ! 68 */ 69 | |
70#include <dev/usb2/include/usb2_devid.h> 71#include <dev/usb2/include/usb2_standard.h> 72#include <dev/usb2/include/usb2_mfunc.h> 73#include <dev/usb2/include/usb2_error.h> 74 | 71#include <dev/usb2/include/usb2_devid.h> 72#include <dev/usb2/include/usb2_standard.h> 73#include <dev/usb2/include/usb2_mfunc.h> 74#include <dev/usb2/include/usb2_error.h> 75 |
75#define usb2_config_td_cc usb2_ether_cc 76#define usb2_config_td_softc aue_softc 77 | |
78#define USB_DEBUG_VAR aue_debug 79 80#include <dev/usb2/core/usb2_core.h> 81#include <dev/usb2/core/usb2_lookup.h> 82#include <dev/usb2/core/usb2_process.h> | 76#define USB_DEBUG_VAR aue_debug 77 78#include <dev/usb2/core/usb2_core.h> 79#include <dev/usb2/core/usb2_lookup.h> 80#include <dev/usb2/core/usb2_process.h> |
83#include <dev/usb2/core/usb2_config_td.h> | |
84#include <dev/usb2/core/usb2_debug.h> 85#include <dev/usb2/core/usb2_request.h> 86#include <dev/usb2/core/usb2_busdma.h> 87#include <dev/usb2/core/usb2_util.h> 88 89#include <dev/usb2/ethernet/usb2_ethernet.h> 90#include <dev/usb2/ethernet/if_auereg.h> 91 | 81#include <dev/usb2/core/usb2_debug.h> 82#include <dev/usb2/core/usb2_request.h> 83#include <dev/usb2/core/usb2_busdma.h> 84#include <dev/usb2/core/usb2_util.h> 85 86#include <dev/usb2/ethernet/usb2_ethernet.h> 87#include <dev/usb2/ethernet/if_auereg.h> 88 |
92MODULE_DEPEND(aue, usb2_ethernet, 1, 1, 1); 93MODULE_DEPEND(aue, usb2_core, 1, 1, 1); 94MODULE_DEPEND(aue, ether, 1, 1, 1); 95MODULE_DEPEND(aue, miibus, 1, 1, 1); 96 | |
97#if USB_DEBUG 98static int aue_debug = 0; 99 100SYSCTL_NODE(_hw_usb2, OID_AUTO, aue, CTLFLAG_RW, 0, "USB aue"); 101SYSCTL_INT(_hw_usb2_aue, OID_AUTO, debug, CTLFLAG_RW, &aue_debug, 0, 102 "Debug level"); 103#endif 104 105/* 106 * Various supported device vendors/products. 107 */ 108static const struct usb2_device_id aue_devs[] = { | 89#if USB_DEBUG 90static int aue_debug = 0; 91 92SYSCTL_NODE(_hw_usb2, OID_AUTO, aue, CTLFLAG_RW, 0, "USB aue"); 93SYSCTL_INT(_hw_usb2_aue, OID_AUTO, debug, CTLFLAG_RW, &aue_debug, 0, 94 "Debug level"); 95#endif 96 97/* 98 * Various supported device vendors/products. 99 */ 100static const struct usb2_device_id aue_devs[] = { |
109 {USB_VPI(USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B, AUE_FLAG_PII)}, 110 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA, 0)}, 111 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000, AUE_FLAG_LSYS)}, 112 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10, 0)}, 113 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1, AUE_FLAG_PNA | AUE_FLAG_PII)}, 114 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2, AUE_FLAG_PII)}, 115 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4, AUE_FLAG_PNA)}, 116 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5, AUE_FLAG_PNA)}, 117 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6, AUE_FLAG_PII)}, 118 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7, AUE_FLAG_PII)}, 119 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8, AUE_FLAG_PII)}, 120 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9, AUE_FLAG_PNA)}, 121 {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001, AUE_FLAG_PII)}, 122 {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC, 0)}, 123 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2, AUE_FLAG_PII)}, 124 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_3, AUE_FLAG_PII)}, 125 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_4, AUE_FLAG_PII)}, 126 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII, AUE_FLAG_PII)}, 127 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, AUE_FLAG_PNA | AUE_FLAG_DUAL_PHY)}, 128 {USB_VPI(USB_VENDOR_AEI, USB_PRODUCT_AEI_FASTETHERNET, AUE_FLAG_PII)}, 129 {USB_VPI(USB_VENDOR_ALLIEDTELESYN, USB_PRODUCT_ALLIEDTELESYN_ATUSB100, AUE_FLAG_PII)}, 130 {USB_VPI(USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC110T, AUE_FLAG_PII)}, 131 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN, AUE_FLAG_PII)}, 132 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, 0)}, 133 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100, AUE_FLAG_PII)}, 134 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100, 0)}, 135 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100, AUE_FLAG_PNA)}, 136 {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS, AUE_FLAG_PII)}, 137 {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX, 0)}, 138 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1, AUE_FLAG_LSYS)}, 139 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 140 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 141 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 142 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA, AUE_FLAG_PNA)}, 143 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX, AUE_FLAG_LSYS)}, 144 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650, AUE_FLAG_LSYS)}, 145 {USB_VPI(USB_VENDOR_ELCON, USB_PRODUCT_ELCON_PLAN, AUE_FLAG_PNA | AUE_FLAG_PII)}, 146 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSB20, AUE_FLAG_PII)}, 147 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX, AUE_FLAG_PII)}, 148 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0, 0)}, 149 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1, AUE_FLAG_LSYS)}, 150 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2, 0)}, 151 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3, AUE_FLAG_LSYS)}, 152 {USB_VPI(USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET, 0)}, 153 {USB_VPI(USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNBR402W, 0)}, 154 {USB_VPI(USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100, AUE_FLAG_PII)}, 155 {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_HN210E, AUE_FLAG_PII)}, 156 {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS, AUE_FLAG_PII)}, 157 {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX, 0)}, 158 {USB_VPI(USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX, 0)}, 159 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1, AUE_FLAG_LSYS | AUE_FLAG_PNA)}, 160 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX, AUE_FLAG_LSYS)}, 161 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA, AUE_FLAG_LSYS)}, 162 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 163 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 164 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T, AUE_FLAG_LSYS)}, 165 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5, AUE_FLAG_PII)}, 166 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1, 0)}, 167 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5, 0)}, 168 {USB_VPI(USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110, AUE_FLAG_PII)}, 169 {USB_VPI(USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101, AUE_FLAG_PII)}, 170 {USB_VPI(USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM, AUE_FLAG_PII)}, 171 {USB_VPI(USB_VENDOR_SIIG2, USB_PRODUCT_SIIG2_USBTOETHER, AUE_FLAG_PII)}, 172 {USB_VPI(USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC, AUE_FLAG_PII)}, 173 {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB, 0)}, 174 {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB, AUE_FLAG_PII)}, 175 {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100, 0)}, 176 {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB110, AUE_FLAG_PII)}, | 101 {USB_VPI(USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B, AUE_FLAG_PII)}, 102 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA, 0)}, 103 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000, AUE_FLAG_LSYS)}, 104 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10, 0)}, 105 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1, AUE_FLAG_PNA | AUE_FLAG_PII)}, 106 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2, AUE_FLAG_PII)}, 107 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4, AUE_FLAG_PNA)}, 108 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5, AUE_FLAG_PNA)}, 109 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6, AUE_FLAG_PII)}, 110 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7, AUE_FLAG_PII)}, 111 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8, AUE_FLAG_PII)}, 112 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9, AUE_FLAG_PNA)}, 113 {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001, AUE_FLAG_PII)}, 114 {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC, 0)}, 115 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2, AUE_FLAG_PII)}, 116 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_3, AUE_FLAG_PII)}, 117 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_4, AUE_FLAG_PII)}, 118 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII, AUE_FLAG_PII)}, 119 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, AUE_FLAG_PNA | AUE_FLAG_DUAL_PHY)}, 120 {USB_VPI(USB_VENDOR_AEI, USB_PRODUCT_AEI_FASTETHERNET, AUE_FLAG_PII)}, 121 {USB_VPI(USB_VENDOR_ALLIEDTELESYN, USB_PRODUCT_ALLIEDTELESYN_ATUSB100, AUE_FLAG_PII)}, 122 {USB_VPI(USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC110T, AUE_FLAG_PII)}, 123 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN, AUE_FLAG_PII)}, 124 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, 0)}, 125 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100, AUE_FLAG_PII)}, 126 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100, 0)}, 127 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100, AUE_FLAG_PNA)}, 128 {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS, AUE_FLAG_PII)}, 129 {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX, 0)}, 130 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1, AUE_FLAG_LSYS)}, 131 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 132 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 133 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 134 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA, AUE_FLAG_PNA)}, 135 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX, AUE_FLAG_LSYS)}, 136 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650, AUE_FLAG_LSYS)}, 137 {USB_VPI(USB_VENDOR_ELCON, USB_PRODUCT_ELCON_PLAN, AUE_FLAG_PNA | AUE_FLAG_PII)}, 138 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSB20, AUE_FLAG_PII)}, 139 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX, AUE_FLAG_PII)}, 140 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0, 0)}, 141 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1, AUE_FLAG_LSYS)}, 142 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2, 0)}, 143 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3, AUE_FLAG_LSYS)}, 144 {USB_VPI(USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET, 0)}, 145 {USB_VPI(USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNBR402W, 0)}, 146 {USB_VPI(USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100, AUE_FLAG_PII)}, 147 {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_HN210E, AUE_FLAG_PII)}, 148 {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS, AUE_FLAG_PII)}, 149 {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX, 0)}, 150 {USB_VPI(USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX, 0)}, 151 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1, AUE_FLAG_LSYS | AUE_FLAG_PNA)}, 152 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX, AUE_FLAG_LSYS)}, 153 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA, AUE_FLAG_LSYS)}, 154 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 155 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 156 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T, AUE_FLAG_LSYS)}, 157 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5, AUE_FLAG_PII)}, 158 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1, 0)}, 159 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5, 0)}, 160 {USB_VPI(USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110, AUE_FLAG_PII)}, 161 {USB_VPI(USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101, AUE_FLAG_PII)}, 162 {USB_VPI(USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM, AUE_FLAG_PII)}, 163 {USB_VPI(USB_VENDOR_SIIG2, USB_PRODUCT_SIIG2_USBTOETHER, AUE_FLAG_PII)}, 164 {USB_VPI(USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC, AUE_FLAG_PII)}, 165 {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB, 0)}, 166 {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB, AUE_FLAG_PII)}, 167 {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100, 0)}, 168 {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB110, AUE_FLAG_PII)}, |
177}; 178 179/* prototypes */ 180 181static device_probe_t aue_probe; 182static device_attach_t aue_attach; 183static device_detach_t aue_detach; 184static device_shutdown_t aue_shutdown; | 169}; 170 171/* prototypes */ 172 173static device_probe_t aue_probe; 174static device_attach_t aue_attach; 175static device_detach_t aue_detach; 176static device_shutdown_t aue_shutdown; |
177static miibus_readreg_t aue_miibus_readreg; 178static miibus_writereg_t aue_miibus_writereg; 179static miibus_statchg_t aue_miibus_statchg; |
|
185 | 180 |
186static usb2_callback_t aue_intr_clear_stall_callback; | |
187static usb2_callback_t aue_intr_callback; | 181static usb2_callback_t aue_intr_callback; |
188static usb2_callback_t aue_bulk_read_clear_stall_callback; | |
189static usb2_callback_t aue_bulk_read_callback; | 182static usb2_callback_t aue_bulk_read_callback; |
190static usb2_callback_t aue_bulk_write_clear_stall_callback; | |
191static usb2_callback_t aue_bulk_write_callback; 192 | 183static usb2_callback_t aue_bulk_write_callback; 184 |
193static void aue_cfg_do_request(struct aue_softc *, 194 struct usb2_device_request *, void *); 195static uint8_t aue_cfg_csr_read_1(struct aue_softc *, uint16_t); 196static uint16_t aue_cfg_csr_read_2(struct aue_softc *, uint16_t); 197static void aue_cfg_csr_write_1(struct aue_softc *, uint16_t, uint8_t); 198static void aue_cfg_csr_write_2(struct aue_softc *, uint16_t, uint16_t); 199static void aue_cfg_eeprom_getword(struct aue_softc *, uint8_t, uint8_t *); 200static void aue_cfg_read_eeprom(struct aue_softc *, uint8_t *, uint16_t, | 185static usb2_ether_fn_t aue_attach_post; 186static usb2_ether_fn_t aue_init; 187static usb2_ether_fn_t aue_stop; 188static usb2_ether_fn_t aue_start; 189static usb2_ether_fn_t aue_tick; 190static usb2_ether_fn_t aue_setmulti; 191static usb2_ether_fn_t aue_setpromisc; 192 193static uint8_t aue_csr_read_1(struct aue_softc *, uint16_t); 194static uint16_t aue_csr_read_2(struct aue_softc *, uint16_t); 195static void aue_csr_write_1(struct aue_softc *, uint16_t, uint8_t); 196static void aue_csr_write_2(struct aue_softc *, uint16_t, uint16_t); 197static void aue_eeprom_getword(struct aue_softc *, int, uint16_t *); 198static void aue_read_eeprom(struct aue_softc *, uint8_t *, uint16_t, |
201 uint16_t); | 199 uint16_t); |
200static void aue_reset(struct aue_softc *); 201static void aue_reset_pegasus_II(struct aue_softc *); |
|
202 | 202 |
203static miibus_readreg_t aue_cfg_miibus_readreg; 204static miibus_writereg_t aue_cfg_miibus_writereg; 205static miibus_statchg_t aue_cfg_miibus_statchg; | 203static int aue_ifmedia_upd(struct ifnet *); 204static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *); |
206 | 205 |
207static usb2_config_td_command_t aue_cfg_setmulti; 208static usb2_config_td_command_t aue_cfg_first_time_setup; 209static usb2_config_td_command_t aue_config_copy; 210static usb2_config_td_command_t aue_cfg_tick; 211static usb2_config_td_command_t aue_cfg_pre_init; 212static usb2_config_td_command_t aue_cfg_init; 213static usb2_config_td_command_t aue_cfg_promisc_upd; 214static usb2_config_td_command_t aue_cfg_ifmedia_upd; 215static usb2_config_td_command_t aue_cfg_pre_stop; 216static usb2_config_td_command_t aue_cfg_stop; 217 218static void aue_cfg_reset_pegasus_II(struct aue_softc *); 219static void aue_cfg_reset(struct aue_softc *); 220static void aue_start_cb(struct ifnet *); 221static void aue_init_cb(void *); 222static void aue_start_transfers(struct aue_softc *); 223static int aue_ifmedia_upd_cb(struct ifnet *); 224static void aue_ifmedia_sts_cb(struct ifnet *, struct ifmediareq *); 225static int aue_ioctl_cb(struct ifnet *, u_long, caddr_t); 226static void aue_watchdog(void *); 227 | |
228static const struct usb2_config aue_config[AUE_N_TRANSFER] = { 229 230 [AUE_BULK_DT_WR] = { 231 .type = UE_BULK, 232 .endpoint = UE_ADDR_ANY, 233 .direction = UE_DIR_OUT, 234 .mh.bufsize = (MCLBYTES + 2), 235 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,}, | 206static const struct usb2_config aue_config[AUE_N_TRANSFER] = { 207 208 [AUE_BULK_DT_WR] = { 209 .type = UE_BULK, 210 .endpoint = UE_ADDR_ANY, 211 .direction = UE_DIR_OUT, 212 .mh.bufsize = (MCLBYTES + 2), 213 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,}, |
236 .mh.callback = &aue_bulk_write_callback, | 214 .mh.callback = aue_bulk_write_callback, |
237 .mh.timeout = 10000, /* 10 seconds */ 238 }, 239 240 [AUE_BULK_DT_RD] = { 241 .type = UE_BULK, 242 .endpoint = UE_ADDR_ANY, 243 .direction = UE_DIR_IN, 244 .mh.bufsize = (MCLBYTES + 4 + ETHER_CRC_LEN), 245 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, | 215 .mh.timeout = 10000, /* 10 seconds */ 216 }, 217 218 [AUE_BULK_DT_RD] = { 219 .type = UE_BULK, 220 .endpoint = UE_ADDR_ANY, 221 .direction = UE_DIR_IN, 222 .mh.bufsize = (MCLBYTES + 4 + ETHER_CRC_LEN), 223 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, |
246 .mh.callback = &aue_bulk_read_callback, | 224 .mh.callback = aue_bulk_read_callback, |
247 }, 248 | 225 }, 226 |
249 [AUE_BULK_CS_WR] = { 250 .type = UE_CONTROL, 251 .endpoint = 0x00, /* Control pipe */ 252 .direction = UE_DIR_ANY, 253 .mh.bufsize = sizeof(struct usb2_device_request), 254 .mh.flags = {}, 255 .mh.callback = &aue_bulk_write_clear_stall_callback, 256 .mh.timeout = 1000, /* 1 second */ 257 .mh.interval = 50, /* 50ms */ 258 }, 259 260 [AUE_BULK_CS_RD] = { 261 .type = UE_CONTROL, 262 .endpoint = 0x00, /* Control pipe */ 263 .direction = UE_DIR_ANY, 264 .mh.bufsize = sizeof(struct usb2_device_request), 265 .mh.flags = {}, 266 .mh.callback = &aue_bulk_read_clear_stall_callback, 267 .mh.timeout = 1000, /* 1 second */ 268 .mh.interval = 50, /* 50ms */ 269 }, 270 | |
271 [AUE_INTR_DT_RD] = { 272 .type = UE_INTERRUPT, 273 .endpoint = UE_ADDR_ANY, 274 .direction = UE_DIR_IN, 275 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 276 .mh.bufsize = 0, /* use wMaxPacketSize */ | 227 [AUE_INTR_DT_RD] = { 228 .type = UE_INTERRUPT, 229 .endpoint = UE_ADDR_ANY, 230 .direction = UE_DIR_IN, 231 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 232 .mh.bufsize = 0, /* use wMaxPacketSize */ |
277 .mh.callback = &aue_intr_callback, | 233 .mh.callback = aue_intr_callback, |
278 }, | 234 }, |
279 280 [AUE_INTR_CS_RD] = { 281 .type = UE_CONTROL, 282 .endpoint = 0x00, /* Control pipe */ 283 .direction = UE_DIR_ANY, 284 .mh.bufsize = sizeof(struct usb2_device_request), 285 .mh.flags = {}, 286 .mh.callback = &aue_intr_clear_stall_callback, 287 .mh.timeout = 1000, /* 1 second */ 288 .mh.interval = 50, /* 50ms */ 289 }, | |
290}; 291 292static device_method_t aue_methods[] = { 293 /* Device interface */ 294 DEVMETHOD(device_probe, aue_probe), 295 DEVMETHOD(device_attach, aue_attach), 296 DEVMETHOD(device_detach, aue_detach), 297 DEVMETHOD(device_shutdown, aue_shutdown), 298 299 /* bus interface */ 300 DEVMETHOD(bus_print_child, bus_generic_print_child), 301 DEVMETHOD(bus_driver_added, bus_generic_driver_added), 302 303 /* MII interface */ | 235}; 236 237static device_method_t aue_methods[] = { 238 /* Device interface */ 239 DEVMETHOD(device_probe, aue_probe), 240 DEVMETHOD(device_attach, aue_attach), 241 DEVMETHOD(device_detach, aue_detach), 242 DEVMETHOD(device_shutdown, aue_shutdown), 243 244 /* bus interface */ 245 DEVMETHOD(bus_print_child, bus_generic_print_child), 246 DEVMETHOD(bus_driver_added, bus_generic_driver_added), 247 248 /* MII interface */ |
304 DEVMETHOD(miibus_readreg, aue_cfg_miibus_readreg), 305 DEVMETHOD(miibus_writereg, aue_cfg_miibus_writereg), 306 DEVMETHOD(miibus_statchg, aue_cfg_miibus_statchg), | 249 DEVMETHOD(miibus_readreg, aue_miibus_readreg), 250 DEVMETHOD(miibus_writereg, aue_miibus_writereg), 251 DEVMETHOD(miibus_statchg, aue_miibus_statchg), |
307 308 {0, 0} 309}; 310 311static driver_t aue_driver = { 312 .name = "aue", 313 .methods = aue_methods, 314 .size = sizeof(struct aue_softc) 315}; 316 317static devclass_t aue_devclass; 318 319DRIVER_MODULE(aue, ushub, aue_driver, aue_devclass, NULL, 0); 320DRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0); | 252 253 {0, 0} 254}; 255 256static driver_t aue_driver = { 257 .name = "aue", 258 .methods = aue_methods, 259 .size = sizeof(struct aue_softc) 260}; 261 262static devclass_t aue_devclass; 263 264DRIVER_MODULE(aue, ushub, aue_driver, aue_devclass, NULL, 0); 265DRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0); |
266MODULE_DEPEND(aue, usb2_ethernet, 1, 1, 1); 267MODULE_DEPEND(aue, usb2_core, 1, 1, 1); 268MODULE_DEPEND(aue, ether, 1, 1, 1); 269MODULE_DEPEND(aue, miibus, 1, 1, 1); |
|
321 | 270 |
322static void 323aue_cfg_do_request(struct aue_softc *sc, struct usb2_device_request *req, 324 void *data) 325{ 326 uint16_t length; 327 usb2_error_t err; | 271static const struct usb2_ether_methods aue_ue_methods = { 272 .ue_attach_post = aue_attach_post, 273 .ue_start = aue_start, 274 .ue_init = aue_init, 275 .ue_stop = aue_stop, 276 .ue_tick = aue_tick, 277 .ue_setmulti = aue_setmulti, 278 .ue_setpromisc = aue_setpromisc, 279 .ue_mii_upd = aue_ifmedia_upd, 280 .ue_mii_sts = aue_ifmedia_sts, 281}; |
328 | 282 |
329 if (usb2_config_td_is_gone(&sc->sc_config_td)) { 330 goto error; 331 } 332 err = usb2_do_request_flags 333 (sc->sc_udev, &sc->sc_mtx, req, data, 0, NULL, 1000); | 283#define AUE_SETBIT(sc, reg, x) \ 284 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x)) |
334 | 285 |
335 if (err) { | 286#define AUE_CLRBIT(sc, reg, x) \ 287 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x)) |
336 | 288 |
337 DPRINTF("device request failed, err=%s " 338 "(ignored)\n", usb2_errstr(err)); 339 340error: 341 length = UGETW(req->wLength); 342 343 if ((req->bmRequestType & UT_READ) && length) { 344 bzero(data, length); 345 } 346 } 347} 348 349#define AUE_CFG_SETBIT(sc, reg, x) \ 350 aue_cfg_csr_write_1(sc, reg, aue_cfg_csr_read_1(sc, reg) | (x)) 351 352#define AUE_CFG_CLRBIT(sc, reg, x) \ 353 aue_cfg_csr_write_1(sc, reg, aue_cfg_csr_read_1(sc, reg) & ~(x)) 354 | |
355static uint8_t | 289static uint8_t |
356aue_cfg_csr_read_1(struct aue_softc *sc, uint16_t reg) | 290aue_csr_read_1(struct aue_softc *sc, uint16_t reg) |
357{ 358 struct usb2_device_request req; | 291{ 292 struct usb2_device_request req; |
293 usb2_error_t err; |
|
359 uint8_t val; 360 361 req.bmRequestType = UT_READ_VENDOR_DEVICE; 362 req.bRequest = AUE_UR_READREG; 363 USETW(req.wValue, 0); 364 USETW(req.wIndex, reg); 365 USETW(req.wLength, 1); 366 | 294 uint8_t val; 295 296 req.bmRequestType = UT_READ_VENDOR_DEVICE; 297 req.bRequest = AUE_UR_READREG; 298 USETW(req.wValue, 0); 299 USETW(req.wIndex, reg); 300 USETW(req.wLength, 1); 301 |
367 aue_cfg_do_request(sc, &req, &val); | 302 err = usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000); 303 if (err) 304 return (0); |
368 return (val); 369} 370 371static uint16_t | 305 return (val); 306} 307 308static uint16_t |
372aue_cfg_csr_read_2(struct aue_softc *sc, uint16_t reg) | 309aue_csr_read_2(struct aue_softc *sc, uint16_t reg) |
373{ 374 struct usb2_device_request req; | 310{ 311 struct usb2_device_request req; |
312 usb2_error_t err; |
|
375 uint16_t val; 376 377 req.bmRequestType = UT_READ_VENDOR_DEVICE; 378 req.bRequest = AUE_UR_READREG; 379 USETW(req.wValue, 0); 380 USETW(req.wIndex, reg); 381 USETW(req.wLength, 2); 382 | 313 uint16_t val; 314 315 req.bmRequestType = UT_READ_VENDOR_DEVICE; 316 req.bRequest = AUE_UR_READREG; 317 USETW(req.wValue, 0); 318 USETW(req.wIndex, reg); 319 USETW(req.wLength, 2); 320 |
383 aue_cfg_do_request(sc, &req, &val); | 321 err = usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000); 322 if (err) 323 return (0); |
384 return (le16toh(val)); 385} 386 387static void | 324 return (le16toh(val)); 325} 326 327static void |
388aue_cfg_csr_write_1(struct aue_softc *sc, uint16_t reg, uint8_t val) | 328aue_csr_write_1(struct aue_softc *sc, uint16_t reg, uint8_t val) |
389{ 390 struct usb2_device_request req; 391 392 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 393 req.bRequest = AUE_UR_WRITEREG; 394 req.wValue[0] = val; 395 req.wValue[1] = 0; 396 USETW(req.wIndex, reg); 397 USETW(req.wLength, 1); 398 | 329{ 330 struct usb2_device_request req; 331 332 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 333 req.bRequest = AUE_UR_WRITEREG; 334 req.wValue[0] = val; 335 req.wValue[1] = 0; 336 USETW(req.wIndex, reg); 337 USETW(req.wLength, 1); 338 |
399 aue_cfg_do_request(sc, &req, &val); | 339 if (usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000)) { 340 /* error ignored */ 341 } |
400} 401 402static void | 342} 343 344static void |
403aue_cfg_csr_write_2(struct aue_softc *sc, uint16_t reg, uint16_t val) | 345aue_csr_write_2(struct aue_softc *sc, uint16_t reg, uint16_t val) |
404{ 405 struct usb2_device_request req; 406 407 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 408 req.bRequest = AUE_UR_WRITEREG; 409 USETW(req.wValue, val); 410 USETW(req.wIndex, reg); 411 USETW(req.wLength, 2); 412 413 val = htole16(val); 414 | 346{ 347 struct usb2_device_request req; 348 349 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 350 req.bRequest = AUE_UR_WRITEREG; 351 USETW(req.wValue, val); 352 USETW(req.wIndex, reg); 353 USETW(req.wLength, 2); 354 355 val = htole16(val); 356 |
415 aue_cfg_do_request(sc, &req, &val); | 357 if (usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000)) { 358 /* error ignored */ 359 } |
416} 417 418/* 419 * Read a word of data stored in the EEPROM at address 'addr.' 420 */ 421static void | 360} 361 362/* 363 * Read a word of data stored in the EEPROM at address 'addr.' 364 */ 365static void |
422aue_cfg_eeprom_getword(struct aue_softc *sc, uint8_t addr, 423 uint8_t *dest) | 366aue_eeprom_getword(struct aue_softc *sc, int addr, uint16_t *dest) |
424{ | 367{ |
425 uint16_t i; | 368 int i; 369 uint16_t word = 0; |
426 | 370 |
427 aue_cfg_csr_write_1(sc, AUE_EE_REG, addr); 428 aue_cfg_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ); | 371 aue_csr_write_1(sc, AUE_EE_REG, addr); 372 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ); |
429 | 373 |
430 for (i = 0;; i++) { 431 432 if (i < AUE_TIMEOUT) { 433 434 if (aue_cfg_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE) { 435 break; 436 } 437 if (usb2_config_td_sleep(&sc->sc_config_td, hz / 100)) { 438 break; 439 } 440 } else { 441 DPRINTF("EEPROM read timed out!\n"); | 374 for (i = 0; i != AUE_TIMEOUT; i++) { 375 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE) |
442 break; | 376 break; |
443 } | 377 if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 378 break; |
444 } 445 | 379 } 380 |
446 i = aue_cfg_csr_read_2(sc, AUE_EE_DATA); | 381 if (i == AUE_TIMEOUT) 382 device_printf(sc->sc_ue.ue_dev, "EEPROM read timed out\n"); |
447 | 383 |
448 dest[0] = (i & 0xFF); 449 dest[1] = (i >> 8); | 384 word = aue_csr_read_2(sc, AUE_EE_DATA); 385 *dest = word; |
450} 451 452/* 453 * Read a sequence of words from the EEPROM. 454 */ 455static void | 386} 387 388/* 389 * Read a sequence of words from the EEPROM. 390 */ 391static void |
456aue_cfg_read_eeprom(struct aue_softc *sc, uint8_t *dest, | 392aue_read_eeprom(struct aue_softc *sc, uint8_t *dest, |
457 uint16_t off, uint16_t len) 458{ | 393 uint16_t off, uint16_t len) 394{ |
459 uint16_t i; | 395 uint16_t *ptr = (uint16_t *)dest; 396 int i; |
460 | 397 |
461 for (i = 0; i < len; i++) { 462 aue_cfg_eeprom_getword(sc, off + i, dest + (i * 2)); 463 } | 398 for (i = 0; i != len; i++, ptr++) 399 aue_eeprom_getword(sc, off + i, ptr); |
464} 465 466static int | 400} 401 402static int |
467aue_cfg_miibus_readreg(device_t dev, int phy, int reg) | 403aue_miibus_readreg(device_t dev, int phy, int reg) |
468{ 469 struct aue_softc *sc = device_get_softc(dev); | 404{ 405 struct aue_softc *sc = device_get_softc(dev); |
470 uint16_t i; 471 uint8_t do_unlock; | 406 int i, locked; 407 uint16_t val = 0; |
472 | 408 |
473 /* avoid recursive locking */ 474 if (mtx_owned(&sc->sc_mtx)) { 475 do_unlock = 0; 476 } else { 477 mtx_lock(&sc->sc_mtx); 478 do_unlock = 1; 479 } | 409 locked = mtx_owned(&sc->sc_mtx); 410 if (!locked) 411 AUE_LOCK(sc); |
480 481 /* | 412 413 /* |
482 * The Am79C901 HomePNA PHY actually contains 483 * two transceivers: a 1Mbps HomePNA PHY and a 484 * 10Mbps full/half duplex ethernet PHY with 485 * NWAY autoneg. However in the ADMtek adapter, 486 * only the 1Mbps PHY is actually connected to 487 * anything, so we ignore the 10Mbps one. It 488 * happens to be configured for MII address 3, 489 * so we filter that out. | 414 * The Am79C901 HomePNA PHY actually contains two transceivers: a 1Mbps 415 * HomePNA PHY and a 10Mbps full/half duplex ethernet PHY with NWAY 416 * autoneg. However in the ADMtek adapter, only the 1Mbps PHY is 417 * actually connected to anything, so we ignore the 10Mbps one. It 418 * happens to be configured for MII address 3, so we filter that out. |
490 */ 491 if (sc->sc_flags & AUE_FLAG_DUAL_PHY) { | 419 */ 420 if (sc->sc_flags & AUE_FLAG_DUAL_PHY) { |
492 493 if (phy == 3) { 494 i = 0; | 421 if (phy == 3) |
495 goto done; | 422 goto done; |
496 } | |
497#if 0 | 423#if 0 |
498 if (phy != 1) { 499 i = 0; | 424 if (phy != 1) |
500 goto done; | 425 goto done; |
501 } | |
502#endif 503 } | 426#endif 427 } |
504 aue_cfg_csr_write_1(sc, AUE_PHY_ADDR, phy); 505 aue_cfg_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); | 428 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 429 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); |
506 | 430 |
507 for (i = 0;; i++) { 508 509 if (i < AUE_TIMEOUT) { 510 511 if (aue_cfg_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) { 512 break; 513 } 514 if (usb2_config_td_sleep(&sc->sc_config_td, hz / 100)) { 515 break; 516 } 517 } else { 518 DPRINTF("MII read timed out\n"); | 431 for (i = 0; i != AUE_TIMEOUT; i++) { 432 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) |
519 break; | 433 break; |
520 } | 434 if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 435 break; |
521 } 522 | 436 } 437 |
523 i = aue_cfg_csr_read_2(sc, AUE_PHY_DATA); | 438 if (i == AUE_TIMEOUT) 439 device_printf(sc->sc_ue.ue_dev, "MII read timed out\n"); |
524 | 440 |
441 val = aue_csr_read_2(sc, AUE_PHY_DATA); 442 |
|
525done: | 443done: |
526 if (do_unlock) { 527 mtx_unlock(&sc->sc_mtx); 528 } 529 return (i); | 444 if (!locked) 445 AUE_UNLOCK(sc); 446 return (val); |
530} 531 532static int | 447} 448 449static int |
533aue_cfg_miibus_writereg(device_t dev, int phy, int reg, int data) | 450aue_miibus_writereg(device_t dev, int phy, int reg, int data) |
534{ 535 struct aue_softc *sc = device_get_softc(dev); | 451{ 452 struct aue_softc *sc = device_get_softc(dev); |
536 uint16_t i; 537 uint8_t do_unlock; | 453 int i; 454 int locked; |
538 | 455 |
539 if (phy == 3) { | 456 if (phy == 3) |
540 return (0); | 457 return (0); |
541 } 542 /* avoid recursive locking */ 543 if (mtx_owned(&sc->sc_mtx)) { 544 do_unlock = 0; 545 } else { 546 mtx_lock(&sc->sc_mtx); 547 do_unlock = 1; 548 } | |
549 | 458 |
550 aue_cfg_csr_write_2(sc, AUE_PHY_DATA, data); 551 aue_cfg_csr_write_1(sc, AUE_PHY_ADDR, phy); 552 aue_cfg_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); | 459 locked = mtx_owned(&sc->sc_mtx); 460 if (!locked) 461 AUE_LOCK(sc); |
553 | 462 |
554 for (i = 0;; i++) { | 463 aue_csr_write_2(sc, AUE_PHY_DATA, data); 464 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 465 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); |
555 | 466 |
556 if (i < AUE_TIMEOUT) { 557 if (aue_cfg_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) { 558 break; 559 } 560 if (usb2_config_td_sleep(&sc->sc_config_td, hz / 100)) { 561 break; 562 } 563 } else { 564 DPRINTF("MII write timed out\n"); | 467 for (i = 0; i != AUE_TIMEOUT; i++) { 468 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) |
565 break; | 469 break; |
566 } | 470 if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 471 break; |
567 } 568 | 472 } 473 |
569 if (do_unlock) { 570 mtx_unlock(&sc->sc_mtx); 571 } | 474 if (i == AUE_TIMEOUT) 475 device_printf(sc->sc_ue.ue_dev, "MII read timed out\n"); 476 477 if (!locked) 478 AUE_UNLOCK(sc); |
572 return (0); 573} 574 575static void | 479 return (0); 480} 481 482static void |
576aue_cfg_miibus_statchg(device_t dev) | 483aue_miibus_statchg(device_t dev) |
577{ 578 struct aue_softc *sc = device_get_softc(dev); 579 struct mii_data *mii = GET_MII(sc); | 484{ 485 struct aue_softc *sc = device_get_softc(dev); 486 struct mii_data *mii = GET_MII(sc); |
580 uint8_t do_unlock; | 487 int locked; |
581 | 488 |
582 /* avoid recursive locking */ 583 if (mtx_owned(&sc->sc_mtx)) { 584 do_unlock = 0; 585 } else { 586 mtx_lock(&sc->sc_mtx); 587 do_unlock = 1; 588 } | 489 locked = mtx_owned(&sc->sc_mtx); 490 if (!locked) 491 AUE_LOCK(sc); |
589 | 492 |
590 AUE_CFG_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); | 493 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 494 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) 495 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 496 else 497 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); |
591 | 498 |
592 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) { 593 AUE_CFG_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 594 } else { 595 AUE_CFG_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 596 } | 499 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) 500 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 501 else 502 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); |
597 | 503 |
598 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) { 599 AUE_CFG_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 600 } else { 601 AUE_CFG_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 602 } | 504 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); |
603 | 505 |
604 AUE_CFG_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 605 | |
606 /* 607 * Set the LED modes on the LinkSys adapter. 608 * This turns on the 'dual link LED' bin in the auxmode 609 * register of the Broadcom PHY. 610 */ 611 if (sc->sc_flags & AUE_FLAG_LSYS) { 612 uint16_t auxmode; 613 | 506 /* 507 * Set the LED modes on the LinkSys adapter. 508 * This turns on the 'dual link LED' bin in the auxmode 509 * register of the Broadcom PHY. 510 */ 511 if (sc->sc_flags & AUE_FLAG_LSYS) { 512 uint16_t auxmode; 513 |
614 auxmode = aue_cfg_miibus_readreg(dev, 0, 0x1b); 615 aue_cfg_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04); | 514 auxmode = aue_miibus_readreg(dev, 0, 0x1b); 515 aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04); |
616 } | 516 } |
617 if (do_unlock) { 618 mtx_unlock(&sc->sc_mtx); 619 } | 517 if (!locked) 518 AUE_UNLOCK(sc); |
620} 621 | 519} 520 |
521#define AUE_BITS 6 |
|
622static void | 522static void |
623aue_cfg_setmulti(struct aue_softc *sc, 624 struct usb2_config_td_cc *cc, uint16_t refcount) | 523aue_setmulti(struct usb2_ether *ue) |
625{ | 524{ |
626 uint16_t i; | 525 struct aue_softc *sc = usb2_ether_getsc(ue); 526 struct ifnet *ifp = usb2_ether_getifp(ue); 527 struct ifmultiaddr *ifma; 528 uint32_t h = 0; 529 uint32_t i; 530 uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
627 | 531 |
628 if ((cc->if_flags & IFF_ALLMULTI) || 629 (cc->if_flags & IFF_PROMISC)) { 630 AUE_CFG_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); | 532 AUE_LOCK_ASSERT(sc, MA_OWNED); 533 534 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 535 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); |
631 return; 632 } | 536 return; 537 } |
633 AUE_CFG_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); | |
634 | 538 |
635 /* clear existing ones */ 636 for (i = 0; i < 8; i++) { 637 aue_cfg_csr_write_1(sc, AUE_MAR0 + i, 0); 638 } | 539 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); |
639 640 /* now program new ones */ | 540 541 /* now program new ones */ |
641 for (i = 0; i < 8; i++) { 642 aue_cfg_csr_write_1(sc, AUE_MAR0 + i, cc->if_hash[i]); | 542 IF_ADDR_LOCK(ifp); 543 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 544 if (ifma->ifma_addr->sa_family != AF_LINK) 545 continue; 546 h = ether_crc32_le(LLADDR((struct sockaddr_dl *) 547 ifma->ifma_addr), ETHER_ADDR_LEN) & ((1 << AUE_BITS) - 1); 548 hashtbl[(h >> 3)] |= 1 << (h & 0x7); |
643 } | 549 } |
550 IF_ADDR_UNLOCK(ifp); 551 552 /* write the hashtable */ 553 for (i = 0; i != 8; i++) 554 aue_csr_write_1(sc, AUE_MAR0 + i, hashtbl[i]); |
|
644} 645 646static void | 555} 556 557static void |
647aue_cfg_reset_pegasus_II(struct aue_softc *sc) | 558aue_reset_pegasus_II(struct aue_softc *sc) |
648{ 649 /* Magic constants taken from Linux driver. */ | 559{ 560 /* Magic constants taken from Linux driver. */ |
650 aue_cfg_csr_write_1(sc, AUE_REG_1D, 0); 651 aue_cfg_csr_write_1(sc, AUE_REG_7B, 2); | 561 aue_csr_write_1(sc, AUE_REG_1D, 0); 562 aue_csr_write_1(sc, AUE_REG_7B, 2); |
652#if 0 653 if ((sc->sc_flags & HAS_HOME_PNA) && mii_mode) | 563#if 0 564 if ((sc->sc_flags & HAS_HOME_PNA) && mii_mode) |
654 aue_cfg_csr_write_1(sc, AUE_REG_81, 6); | 565 aue_csr_write_1(sc, AUE_REG_81, 6); |
655 else 656#endif | 566 else 567#endif |
657 aue_cfg_csr_write_1(sc, AUE_REG_81, 2); | 568 aue_csr_write_1(sc, AUE_REG_81, 2); |
658} 659 660static void | 569} 570 571static void |
661aue_cfg_reset(struct aue_softc *sc) | 572aue_reset(struct aue_softc *sc) |
662{ | 573{ |
663 uint16_t i; | 574 int i; |
664 | 575 |
665 AUE_CFG_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); | 576 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); |
666 | 577 |
667 for (i = 0;; i++) { 668 669 if (i < AUE_TIMEOUT) { 670 671 if (!(aue_cfg_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) { 672 break; 673 } 674 if (usb2_config_td_sleep(&sc->sc_config_td, hz / 100)) { 675 break; 676 } 677 } else { 678 DPRINTF("reset timed out\n"); | 578 for (i = 0; i != AUE_TIMEOUT; i++) { 579 if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) |
679 break; | 580 break; |
680 } | 581 if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 582 break; |
681 } 682 | 583 } 584 |
585 if (i == AUE_TIMEOUT) 586 device_printf(sc->sc_ue.ue_dev, "reset failed\n"); 587 |
|
683 /* 684 * The PHY(s) attached to the Pegasus chip may be held 685 * in reset until we flip on the GPIO outputs. Make sure 686 * to set the GPIO pins high so that the PHY(s) will 687 * be enabled. 688 * 689 * Note: We force all of the GPIO pins low first, *then* 690 * enable the ones we want. 691 */ | 588 /* 589 * The PHY(s) attached to the Pegasus chip may be held 590 * in reset until we flip on the GPIO outputs. Make sure 591 * to set the GPIO pins high so that the PHY(s) will 592 * be enabled. 593 * 594 * Note: We force all of the GPIO pins low first, *then* 595 * enable the ones we want. 596 */ |
692 aue_cfg_csr_write_1(sc, AUE_GPIO0, (AUE_GPIO_OUT0 | AUE_GPIO_SEL0)); 693 aue_cfg_csr_write_1(sc, AUE_GPIO0, (AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | 694 AUE_GPIO_SEL1)); | 597 aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0); 598 aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0|AUE_GPIO_SEL1); |
695 696 if (sc->sc_flags & AUE_FLAG_LSYS) { 697 /* Grrr. LinkSys has to be different from everyone else. */ | 599 600 if (sc->sc_flags & AUE_FLAG_LSYS) { 601 /* Grrr. LinkSys has to be different from everyone else. */ |
698 aue_cfg_csr_write_1(sc, AUE_GPIO0, 699 (AUE_GPIO_SEL0 | AUE_GPIO_SEL1)); 700 aue_cfg_csr_write_1(sc, AUE_GPIO0, 701 (AUE_GPIO_SEL0 | 702 AUE_GPIO_SEL1 | 703 AUE_GPIO_OUT0)); | 602 aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0|AUE_GPIO_SEL1); 603 aue_csr_write_1(sc, AUE_GPIO0, 604 AUE_GPIO_SEL0|AUE_GPIO_SEL1|AUE_GPIO_OUT0); |
704 } | 605 } |
705 if (sc->sc_flags & AUE_FLAG_PII) { 706 aue_cfg_reset_pegasus_II(sc); 707 } 708 /* wait a little while for the chip to get its brains in order: */ 709 usb2_config_td_sleep(&sc->sc_config_td, hz / 100); | 606 if (sc->sc_flags & AUE_FLAG_PII) 607 aue_reset_pegasus_II(sc); 608 609 /* Wait a little while for the chip to get its brains in order: */ 610 usb2_ether_pause(&sc->sc_ue, hz / 100); |
710} 711 | 611} 612 |
613static void 614aue_attach_post(struct usb2_ether *ue) 615{ 616 struct aue_softc *sc = usb2_ether_getsc(ue); 617 618 /* reset the adapter */ 619 aue_reset(sc); 620 621 /* get station address from the EEPROM */ 622 aue_read_eeprom(sc, ue->ue_eaddr, 0, 3); 623} 624 |
|
712/* 713 * Probe for a Pegasus chip. 714 */ 715static int 716aue_probe(device_t dev) 717{ 718 struct usb2_attach_arg *uaa = device_get_ivars(dev); 719 | 625/* 626 * Probe for a Pegasus chip. 627 */ 628static int 629aue_probe(device_t dev) 630{ 631 struct usb2_attach_arg *uaa = device_get_ivars(dev); 632 |
720 if (uaa->usb2_mode != USB_MODE_HOST) { | 633 if (uaa->usb2_mode != USB_MODE_HOST) |
721 return (ENXIO); | 634 return (ENXIO); |
722 } 723 if (uaa->info.bConfigIndex != AUE_CONFIG_INDEX) { | 635 if (uaa->info.bConfigIndex != AUE_CONFIG_INDEX) |
724 return (ENXIO); | 636 return (ENXIO); |
725 } 726 if (uaa->info.bIfaceIndex != AUE_IFACE_IDX) { | 637 if (uaa->info.bIfaceIndex != AUE_IFACE_IDX) |
727 return (ENXIO); | 638 return (ENXIO); |
728 } | |
729 /* | 639 /* |
730 * Belkin USB Bluetooth dongles of the F8T012xx1 model series 731 * conflict with older Belkin USB2LAN adapters. Skip if_aue if 732 * we detect one of the devices that look like Bluetooth 733 * adapters. | 640 * Belkin USB Bluetooth dongles of the F8T012xx1 model series conflict 641 * with older Belkin USB2LAN adapters. Skip if_aue if we detect one of 642 * the devices that look like Bluetooth adapters. |
734 */ | 643 */ |
735 if ((uaa->info.idVendor == USB_VENDOR_BELKIN) && 736 (uaa->info.idProduct == USB_PRODUCT_BELKIN_F8T012) && 737 (uaa->info.bcdDevice == 0x0413)) { | 644 if (uaa->info.idVendor == USB_VENDOR_BELKIN && 645 uaa->info.idProduct == USB_PRODUCT_BELKIN_F8T012 && 646 uaa->info.bcdDevice == 0x0413) |
738 return (ENXIO); | 647 return (ENXIO); |
739 } | 648 |
740 return (usb2_lookup_id_by_uaa(aue_devs, sizeof(aue_devs), uaa)); 741} 742 743/* 744 * Attach the interface. Allocate softc structures, do ifmedia 745 * setup and ethernet/BPF attach. 746 */ 747static int 748aue_attach(device_t dev) 749{ 750 struct usb2_attach_arg *uaa = device_get_ivars(dev); 751 struct aue_softc *sc = device_get_softc(dev); | 649 return (usb2_lookup_id_by_uaa(aue_devs, sizeof(aue_devs), uaa)); 650} 651 652/* 653 * Attach the interface. Allocate softc structures, do ifmedia 654 * setup and ethernet/BPF attach. 655 */ 656static int 657aue_attach(device_t dev) 658{ 659 struct usb2_attach_arg *uaa = device_get_ivars(dev); 660 struct aue_softc *sc = device_get_softc(dev); |
752 int32_t error; | 661 struct usb2_ether *ue = &sc->sc_ue; |
753 uint8_t iface_index; | 662 uint8_t iface_index; |
663 int error; |
|
754 | 664 |
755 sc->sc_udev = uaa->device; 756 sc->sc_dev = dev; 757 sc->sc_unit = device_get_unit(dev); | |
758 sc->sc_flags = USB_GET_DRIVER_INFO(uaa); 759 760 if (uaa->info.bcdDevice >= 0x0201) { | 665 sc->sc_flags = USB_GET_DRIVER_INFO(uaa); 666 667 if (uaa->info.bcdDevice >= 0x0201) { |
761 sc->sc_flags |= AUE_FLAG_VER_2; /* XXX currently undocumented */ | 668 /* XXX currently undocumented */ 669 sc->sc_flags |= AUE_FLAG_VER_2; |
762 } | 670 } |
671 |
|
763 device_set_usb2_desc(dev); | 672 device_set_usb2_desc(dev); |
673 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); |
|
764 | 674 |
765 snprintf(sc->sc_name, sizeof(sc->sc_name), "%s", 766 device_get_nameunit(dev)); 767 768 mtx_init(&sc->sc_mtx, "aue lock", NULL, MTX_DEF | MTX_RECURSE); 769 770 usb2_callout_init_mtx(&sc->sc_watchdog, &sc->sc_mtx, 0); 771 | |
772 iface_index = AUE_IFACE_IDX; 773 error = usb2_transfer_setup(uaa->device, &iface_index, 774 sc->sc_xfer, aue_config, AUE_N_TRANSFER, 775 sc, &sc->sc_mtx); 776 if (error) { | 675 iface_index = AUE_IFACE_IDX; 676 error = usb2_transfer_setup(uaa->device, &iface_index, 677 sc->sc_xfer, aue_config, AUE_N_TRANSFER, 678 sc, &sc->sc_mtx); 679 if (error) { |
777 device_printf(dev, "allocating USB " 778 "transfers failed!\n"); | 680 device_printf(dev, "allocating USB transfers failed!\n"); |
779 goto detach; 780 } | 681 goto detach; 682 } |
781 error = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_mtx, 782 NULL, sizeof(struct usb2_config_td_cc), 16); | 683 684 ue->ue_sc = sc; 685 ue->ue_dev = dev; 686 ue->ue_udev = uaa->device; 687 ue->ue_mtx = &sc->sc_mtx; 688 ue->ue_methods = &aue_ue_methods; 689 690 error = usb2_ether_ifattach(ue); |
783 if (error) { | 691 if (error) { |
784 device_printf(dev, "could not setup config " 785 "thread!\n"); | 692 device_printf(dev, "could not attach interface\n"); |
786 goto detach; 787 } | 693 goto detach; 694 } |
788 mtx_lock(&sc->sc_mtx); 789 790 sc->sc_flags |= AUE_FLAG_WAIT_LINK; 791 792 /* start setup */ 793 794 usb2_config_td_queue_command 795 (&sc->sc_config_td, NULL, &aue_cfg_first_time_setup, 0, 0); 796 797 aue_watchdog(sc); 798 mtx_unlock(&sc->sc_mtx); | |
799 return (0); /* success */ 800 801detach: 802 aue_detach(dev); 803 return (ENXIO); /* failure */ 804} 805 | 695 return (0); /* success */ 696 697detach: 698 aue_detach(dev); 699 return (ENXIO); /* failure */ 700} 701 |
806static void 807aue_cfg_first_time_setup(struct aue_softc *sc, 808 struct usb2_config_td_cc *cc, uint16_t refcount) 809{ 810 struct ifnet *ifp; 811 int error; 812 uint8_t eaddr[min(ETHER_ADDR_LEN, 6)]; 813 814 /* reset the adapter */ 815 aue_cfg_reset(sc); 816 817 /* set default value */ 818 bzero(eaddr, sizeof(eaddr)); 819 820 /* get station address from the EEPROM */ 821 aue_cfg_read_eeprom(sc, eaddr, 0, 3); 822 823 mtx_unlock(&sc->sc_mtx); 824 825 ifp = if_alloc(IFT_ETHER); 826 827 mtx_lock(&sc->sc_mtx); 828 829 if (ifp == NULL) { 830 printf("%s: could not if_alloc()\n", 831 sc->sc_name); 832 goto done; 833 } 834 835 ifp->if_softc = sc; 836 if_initname(ifp, "aue", sc->sc_unit); 837 ifp->if_mtu = ETHERMTU; 838 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 839 ifp->if_ioctl = aue_ioctl_cb; 840 ifp->if_start = aue_start_cb; 841 ifp->if_watchdog = NULL; 842 ifp->if_init = aue_init_cb; 843 IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); 844 ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN; 845 IFQ_SET_READY(&ifp->if_snd); 846 847 /* 848 * XXX need Giant when accessing the device structures ! 849 */ 850 851 mtx_unlock(&sc->sc_mtx); 852 853 mtx_lock(&Giant); 854 855 error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, 856 &aue_ifmedia_upd_cb, 857 &aue_ifmedia_sts_cb); 858 859 mtx_unlock(&Giant); 860 861 mtx_lock(&sc->sc_mtx); 862 863 /* 864 * Do MII setup. 865 * NOTE: Doing this causes child devices to be attached to us, 866 * which we would normally disconnect at in the detach routine 867 * using device_delete_child(). However the USB code is set up 868 * such that when this driver is removed, all children devices 869 * are removed as well. In effect, the USB code ends up detaching 870 * all of our children for us, so we don't have to do is ourselves 871 * in aue_detach(). It's important to point this out since if 872 * we *do* try to detach the child devices ourselves, we will 873 * end up getting the children deleted twice, which will crash 874 * the system. 875 */ 876 if (error) { 877 printf("%s: MII without any PHY!\n", 878 sc->sc_name); 879 if_free(ifp); 880 goto done; 881 } 882 sc->sc_ifp = ifp; 883 884 mtx_unlock(&sc->sc_mtx); 885 886 /* 887 * Call MI attach routine. 888 */ 889 ether_ifattach(ifp, eaddr); 890 891 mtx_lock(&sc->sc_mtx); 892 893done: 894 return; 895} 896 | |
897static int 898aue_detach(device_t dev) 899{ 900 struct aue_softc *sc = device_get_softc(dev); | 702static int 703aue_detach(device_t dev) 704{ 705 struct aue_softc *sc = device_get_softc(dev); |
901 struct ifnet *ifp; | 706 struct usb2_ether *ue = &sc->sc_ue; |
902 | 707 |
903 usb2_config_td_drain(&sc->sc_config_td); 904 905 mtx_lock(&sc->sc_mtx); 906 907 usb2_callout_stop(&sc->sc_watchdog); 908 909 aue_cfg_pre_stop(sc, NULL, 0); 910 911 ifp = sc->sc_ifp; 912 913 mtx_unlock(&sc->sc_mtx); 914 915 /* stop all USB transfers first */ | |
916 usb2_transfer_unsetup(sc->sc_xfer, AUE_N_TRANSFER); | 708 usb2_transfer_unsetup(sc->sc_xfer, AUE_N_TRANSFER); |
917 918 /* get rid of any late children */ 919 bus_generic_detach(dev); 920 921 if (ifp) { 922 ether_ifdetach(ifp); 923 if_free(ifp); 924 } 925 usb2_config_td_unsetup(&sc->sc_config_td); 926 927 usb2_callout_drain(&sc->sc_watchdog); 928 | 709 usb2_ether_ifdetach(ue); |
929 mtx_destroy(&sc->sc_mtx); 930 931 return (0); 932} 933 934static void | 710 mtx_destroy(&sc->sc_mtx); 711 712 return (0); 713} 714 715static void |
935aue_intr_clear_stall_callback(struct usb2_xfer *xfer) 936{ 937 struct aue_softc *sc = xfer->priv_sc; 938 struct usb2_xfer *xfer_other = sc->sc_xfer[AUE_INTR_DT_RD]; 939 940 if (usb2_clear_stall_callback(xfer, xfer_other)) { 941 DPRINTF("stall cleared\n"); 942 sc->sc_flags &= ~AUE_FLAG_INTR_STALL; 943 usb2_transfer_start(xfer_other); 944 } 945} 946 947static void | |
948aue_intr_callback(struct usb2_xfer *xfer) 949{ 950 struct aue_softc *sc = xfer->priv_sc; | 716aue_intr_callback(struct usb2_xfer *xfer) 717{ 718 struct aue_softc *sc = xfer->priv_sc; |
951 struct ifnet *ifp = sc->sc_ifp; | 719 struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue); |
952 struct aue_intrpkt pkt; 953 954 switch (USB_GET_STATE(xfer)) { 955 case USB_ST_TRANSFERRED: 956 | 720 struct aue_intrpkt pkt; 721 722 switch (USB_GET_STATE(xfer)) { 723 case USB_ST_TRANSFERRED: 724 |
957 if (ifp && (ifp->if_drv_flags & IFF_DRV_RUNNING) && 958 (xfer->actlen >= sizeof(pkt))) { | 725 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) && 726 xfer->actlen >= sizeof(pkt)) { |
959 960 usb2_copy_out(xfer->frbuffers, 0, &pkt, sizeof(pkt)); 961 | 727 728 usb2_copy_out(xfer->frbuffers, 0, &pkt, sizeof(pkt)); 729 |
962 if (pkt.aue_txstat0) { | 730 if (pkt.aue_txstat0) |
963 ifp->if_oerrors++; | 731 ifp->if_oerrors++; |
964 } | |
965 if (pkt.aue_txstat0 & (AUE_TXSTAT0_LATECOLL & | 732 if (pkt.aue_txstat0 & (AUE_TXSTAT0_LATECOLL & |
966 AUE_TXSTAT0_EXCESSCOLL)) { | 733 AUE_TXSTAT0_EXCESSCOLL)) |
967 ifp->if_collisions++; | 734 ifp->if_collisions++; |
968 } | |
969 } | 735 } |
736 /* FALLTHROUGH */ |
|
970 case USB_ST_SETUP: | 737 case USB_ST_SETUP: |
971 if (sc->sc_flags & AUE_FLAG_INTR_STALL) { 972 usb2_transfer_start(sc->sc_xfer[AUE_INTR_CS_RD]); 973 } else { 974 xfer->frlengths[0] = xfer->max_data_length; 975 usb2_start_hardware(xfer); 976 } | 738tr_setup: 739 xfer->frlengths[0] = xfer->max_data_length; 740 usb2_start_hardware(xfer); |
977 return; 978 979 default: /* Error */ 980 if (xfer->error != USB_ERR_CANCELLED) { | 741 return; 742 743 default: /* Error */ 744 if (xfer->error != USB_ERR_CANCELLED) { |
981 /* start clear stall */ 982 sc->sc_flags |= AUE_FLAG_INTR_STALL; 983 usb2_transfer_start(sc->sc_xfer[AUE_INTR_CS_RD]); | 745 /* try to clear stall first */ 746 xfer->flags.stall_pipe = 1; 747 goto tr_setup; |
984 } 985 return; 986 } 987} 988 989static void | 748 } 749 return; 750 } 751} 752 753static void |
990aue_bulk_read_clear_stall_callback(struct usb2_xfer *xfer) 991{ 992 struct aue_softc *sc = xfer->priv_sc; 993 struct usb2_xfer *xfer_other = sc->sc_xfer[AUE_BULK_DT_RD]; 994 995 if (usb2_clear_stall_callback(xfer, xfer_other)) { 996 DPRINTF("stall cleared\n"); 997 sc->sc_flags &= ~AUE_FLAG_READ_STALL; 998 usb2_transfer_start(xfer_other); 999 } 1000} 1001 1002static void | |
1003aue_bulk_read_callback(struct usb2_xfer *xfer) 1004{ 1005 struct aue_softc *sc = xfer->priv_sc; | 754aue_bulk_read_callback(struct usb2_xfer *xfer) 755{ 756 struct aue_softc *sc = xfer->priv_sc; |
1006 struct ifnet *ifp = sc->sc_ifp; 1007 struct mbuf *m = NULL; | 757 struct usb2_ether *ue = &sc->sc_ue; 758 struct ifnet *ifp = usb2_ether_getifp(ue); 759 struct aue_rxpkt stat; |
1008 1009 switch (USB_GET_STATE(xfer)) { 1010 case USB_ST_TRANSFERRED: 1011 DPRINTFN(11, "received %d bytes\n", xfer->actlen); 1012 1013 if (sc->sc_flags & AUE_FLAG_VER_2) { 1014 1015 if (xfer->actlen == 0) { 1016 ifp->if_ierrors++; 1017 goto tr_setup; 1018 } 1019 } else { 1020 | 760 761 switch (USB_GET_STATE(xfer)) { 762 case USB_ST_TRANSFERRED: 763 DPRINTFN(11, "received %d bytes\n", xfer->actlen); 764 765 if (sc->sc_flags & AUE_FLAG_VER_2) { 766 767 if (xfer->actlen == 0) { 768 ifp->if_ierrors++; 769 goto tr_setup; 770 } 771 } else { 772 |
1021 if (xfer->actlen <= (4 + ETHER_CRC_LEN)) { | 773 if (xfer->actlen <= (sizeof(stat) + ETHER_CRC_LEN)) { |
1022 ifp->if_ierrors++; 1023 goto tr_setup; 1024 } | 774 ifp->if_ierrors++; 775 goto tr_setup; 776 } |
1025 usb2_copy_out(xfer->frbuffers, xfer->actlen - 4, &sc->sc_rxpkt, 1026 sizeof(sc->sc_rxpkt)); | 777 usb2_copy_out(xfer->frbuffers, 778 xfer->actlen - sizeof(stat), &stat, sizeof(stat)); |
1027 1028 /* 1029 * turn off all the non-error bits in the rx status 1030 * word: 1031 */ | 779 780 /* 781 * turn off all the non-error bits in the rx status 782 * word: 783 */ |
1032 sc->sc_rxpkt.aue_rxstat &= AUE_RXSTAT_MASK; 1033 1034 if (sc->sc_rxpkt.aue_rxstat) { | 784 stat.aue_rxstat &= AUE_RXSTAT_MASK; 785 if (stat.aue_rxstat) { |
1035 ifp->if_ierrors++; 1036 goto tr_setup; 1037 } 1038 /* No errors; receive the packet. */ | 786 ifp->if_ierrors++; 787 goto tr_setup; 788 } 789 /* No errors; receive the packet. */ |
1039 xfer->actlen -= (4 + ETHER_CRC_LEN); | 790 xfer->actlen -= (sizeof(stat) + ETHER_CRC_LEN); |
1040 } | 791 } |
792 usb2_ether_rxbuf(ue, xfer->frbuffers, 0, xfer->actlen); |
|
1041 | 793 |
1042 m = usb2_ether_get_mbuf(); 1043 1044 if (m == NULL) { 1045 ifp->if_ierrors++; 1046 goto tr_setup; 1047 } 1048 xfer->actlen = min(xfer->actlen, m->m_len); 1049 1050 usb2_copy_out(xfer->frbuffers, 0, m->m_data, xfer->actlen); 1051 1052 ifp->if_ipackets++; 1053 m->m_pkthdr.rcvif = ifp; 1054 m->m_pkthdr.len = m->m_len = xfer->actlen; 1055 | 794 /* FALLTHROUGH */ |
1056 case USB_ST_SETUP: 1057tr_setup: | 795 case USB_ST_SETUP: 796tr_setup: |
1058 1059 if (sc->sc_flags & AUE_FLAG_READ_STALL) { 1060 usb2_transfer_start(sc->sc_xfer[AUE_BULK_CS_RD]); 1061 } else { 1062 xfer->frlengths[0] = xfer->max_data_length; 1063 usb2_start_hardware(xfer); 1064 } 1065 1066 /* 1067 * At the end of a USB callback it is always safe to unlock 1068 * the private mutex of a device! That is why we do the 1069 * "if_input" here, and not some lines up! 1070 */ 1071 if (m) { 1072 mtx_unlock(&sc->sc_mtx); 1073 (ifp->if_input) (ifp, m); 1074 mtx_lock(&sc->sc_mtx); 1075 } | 797 xfer->frlengths[0] = xfer->max_data_length; 798 usb2_start_hardware(xfer); 799 usb2_ether_rxflush(ue); |
1076 return; 1077 1078 default: /* Error */ | 800 return; 801 802 default: /* Error */ |
803 DPRINTF("bulk read error, %s\n", 804 usb2_errstr(xfer->error)); 805 |
|
1079 if (xfer->error != USB_ERR_CANCELLED) { 1080 /* try to clear stall first */ | 806 if (xfer->error != USB_ERR_CANCELLED) { 807 /* try to clear stall first */ |
1081 sc->sc_flags |= AUE_FLAG_READ_STALL; 1082 usb2_transfer_start(sc->sc_xfer[AUE_BULK_CS_RD]); | 808 xfer->flags.stall_pipe = 1; 809 goto tr_setup; |
1083 } | 810 } |
1084 DPRINTF("bulk read error, %s\n", 1085 usb2_errstr(xfer->error)); | |
1086 return; | 811 return; |
1087 | |
1088 } 1089} 1090 1091static void | 812 } 813} 814 815static void |
1092aue_bulk_write_clear_stall_callback(struct usb2_xfer *xfer) 1093{ 1094 struct aue_softc *sc = xfer->priv_sc; 1095 struct usb2_xfer *xfer_other = sc->sc_xfer[AUE_BULK_DT_WR]; 1096 1097 if (usb2_clear_stall_callback(xfer, xfer_other)) { 1098 DPRINTF("stall cleared\n"); 1099 sc->sc_flags &= ~AUE_FLAG_WRITE_STALL; 1100 usb2_transfer_start(xfer_other); 1101 } 1102} 1103 1104static void | |
1105aue_bulk_write_callback(struct usb2_xfer *xfer) 1106{ 1107 struct aue_softc *sc = xfer->priv_sc; | 816aue_bulk_write_callback(struct usb2_xfer *xfer) 817{ 818 struct aue_softc *sc = xfer->priv_sc; |
1108 struct ifnet *ifp = sc->sc_ifp; | 819 struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue); |
1109 struct mbuf *m; 1110 uint8_t buf[2]; 1111 1112 switch (USB_GET_STATE(xfer)) { 1113 case USB_ST_TRANSFERRED: 1114 DPRINTFN(11, "transfer of %d bytes complete\n", xfer->actlen); | 820 struct mbuf *m; 821 uint8_t buf[2]; 822 823 switch (USB_GET_STATE(xfer)) { 824 case USB_ST_TRANSFERRED: 825 DPRINTFN(11, "transfer of %d bytes complete\n", xfer->actlen); |
1115 | |
1116 ifp->if_opackets++; 1117 | 826 ifp->if_opackets++; 827 |
828 /* FALLTHROUGH */ |
|
1118 case USB_ST_SETUP: | 829 case USB_ST_SETUP: |
1119 1120 if (sc->sc_flags & AUE_FLAG_WRITE_STALL) { 1121 usb2_transfer_start(sc->sc_xfer[AUE_BULK_CS_WR]); 1122 goto done; 1123 } 1124 if (sc->sc_flags & AUE_FLAG_WAIT_LINK) { | 830tr_setup: 831 if ((sc->sc_flags & AUE_FLAG_LINK) == 0) { |
1125 /* 1126 * don't send anything if there is no link ! 1127 */ | 832 /* 833 * don't send anything if there is no link ! 834 */ |
1128 goto done; | 835 return; |
1129 } 1130 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 1131 | 836 } 837 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 838 |
1132 if (m == NULL) { 1133 goto done; 1134 } 1135 if (m->m_pkthdr.len > MCLBYTES) { | 839 if (m == NULL) 840 return; 841 if (m->m_pkthdr.len > MCLBYTES) |
1136 m->m_pkthdr.len = MCLBYTES; | 842 m->m_pkthdr.len = MCLBYTES; |
1137 } | |
1138 if (sc->sc_flags & AUE_FLAG_VER_2) { 1139 1140 xfer->frlengths[0] = m->m_pkthdr.len; 1141 1142 usb2_m_copy_in(xfer->frbuffers, 0, 1143 m, 0, m->m_pkthdr.len); 1144 1145 } else { 1146 1147 xfer->frlengths[0] = (m->m_pkthdr.len + 2); 1148 1149 /* | 843 if (sc->sc_flags & AUE_FLAG_VER_2) { 844 845 xfer->frlengths[0] = m->m_pkthdr.len; 846 847 usb2_m_copy_in(xfer->frbuffers, 0, 848 m, 0, m->m_pkthdr.len); 849 850 } else { 851 852 xfer->frlengths[0] = (m->m_pkthdr.len + 2); 853 854 /* |
1150 * The ADMtek documentation says that the packet length is 1151 * supposed to be specified in the first two bytes of the 1152 * transfer, however it actually seems to ignore this info 1153 * and base the frame size on the bulk transfer length. | 855 * The ADMtek documentation says that the 856 * packet length is supposed to be specified 857 * in the first two bytes of the transfer, 858 * however it actually seems to ignore this 859 * info and base the frame size on the bulk 860 * transfer length. |
1154 */ 1155 buf[0] = (uint8_t)(m->m_pkthdr.len); 1156 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 1157 1158 usb2_copy_in(xfer->frbuffers, 0, buf, 2); 1159 1160 usb2_m_copy_in(xfer->frbuffers, 2, 1161 m, 0, m->m_pkthdr.len); 1162 } 1163 1164 /* 1165 * if there's a BPF listener, bounce a copy 1166 * of this frame to him: 1167 */ 1168 BPF_MTAP(ifp, m); 1169 1170 m_freem(m); 1171 1172 usb2_start_hardware(xfer); | 861 */ 862 buf[0] = (uint8_t)(m->m_pkthdr.len); 863 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 864 865 usb2_copy_in(xfer->frbuffers, 0, buf, 2); 866 867 usb2_m_copy_in(xfer->frbuffers, 2, 868 m, 0, m->m_pkthdr.len); 869 } 870 871 /* 872 * if there's a BPF listener, bounce a copy 873 * of this frame to him: 874 */ 875 BPF_MTAP(ifp, m); 876 877 m_freem(m); 878 879 usb2_start_hardware(xfer); |
1173 1174done: | |
1175 return; 1176 1177 default: /* Error */ 1178 DPRINTFN(11, "transfer error, %s\n", 1179 usb2_errstr(xfer->error)); 1180 | 880 return; 881 882 default: /* Error */ 883 DPRINTFN(11, "transfer error, %s\n", 884 usb2_errstr(xfer->error)); 885 |
886 ifp->if_oerrors++; 887 |
|
1181 if (xfer->error != USB_ERR_CANCELLED) { 1182 /* try to clear stall first */ | 888 if (xfer->error != USB_ERR_CANCELLED) { 889 /* try to clear stall first */ |
1183 sc->sc_flags |= AUE_FLAG_WRITE_STALL; 1184 usb2_transfer_start(sc->sc_xfer[AUE_BULK_CS_WR]); | 890 xfer->flags.stall_pipe = 1; 891 goto tr_setup; |
1185 } | 892 } |
1186 ifp->if_oerrors++; | |
1187 return; | 893 return; |
1188 | |
1189 } 1190} 1191 | 894 } 895} 896 |
1192#define AUE_BITS 6 1193 | |
1194static void | 897static void |
1195aue_mchash(struct usb2_config_td_cc *cc, const uint8_t *ptr) | 898aue_tick(struct usb2_ether *ue) |
1196{ | 899{ |
1197 uint8_t h; 1198 1199 h = ether_crc32_le(ptr, ETHER_ADDR_LEN) & 1200 ((1 << AUE_BITS) - 1); 1201 cc->if_hash[(h >> 3)] |= (1 << (h & 7)); 1202} 1203 1204static void 1205aue_config_copy(struct aue_softc *sc, 1206 struct usb2_config_td_cc *cc, uint16_t refcount) 1207{ 1208 bzero(cc, sizeof(*cc)); 1209 usb2_ether_cc(sc->sc_ifp, &aue_mchash, cc); 1210} 1211 1212static void 1213aue_cfg_tick(struct aue_softc *sc, 1214 struct usb2_config_td_cc *cc, uint16_t refcount) 1215{ 1216 struct ifnet *ifp = sc->sc_ifp; | 900 struct aue_softc *sc = usb2_ether_getsc(ue); |
1217 struct mii_data *mii = GET_MII(sc); 1218 | 901 struct mii_data *mii = GET_MII(sc); 902 |
1219 if ((ifp == NULL) || 1220 (mii == NULL)) { 1221 /* not ready */ 1222 return; 1223 } 1224 mii_tick(mii); | 903 AUE_LOCK_ASSERT(sc, MA_OWNED); |
1225 | 904 |
1226 mii_pollstat(mii); 1227 1228 if ((sc->sc_flags & AUE_FLAG_WAIT_LINK) && 1229 (mii->mii_media_status & IFM_ACTIVE) && 1230 (IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE)) { 1231 sc->sc_flags &= ~AUE_FLAG_WAIT_LINK; | 905 mii_tick(mii); 906 if ((sc->sc_flags & AUE_FLAG_LINK) == 0 907 && mii->mii_media_status & IFM_ACTIVE && 908 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 909 sc->sc_flags |= AUE_FLAG_LINK; 910 aue_start(ue); |
1232 } | 911 } |
1233 sc->sc_media_active = mii->mii_media_active; 1234 sc->sc_media_status = mii->mii_media_status; 1235 1236 /* start stopped transfers, if any */ 1237 1238 aue_start_transfers(sc); | |
1239} 1240 1241static void | 912} 913 914static void |
1242aue_start_cb(struct ifnet *ifp) | 915aue_start(struct usb2_ether *ue) |
1243{ | 916{ |
1244 struct aue_softc *sc = ifp->if_softc; | 917 struct aue_softc *sc = usb2_ether_getsc(ue); |
1245 | 918 |
1246 mtx_lock(&sc->sc_mtx); 1247 1248 aue_start_transfers(sc); 1249 1250 mtx_unlock(&sc->sc_mtx); | 919 /* 920 * start the USB transfers, if not already started: 921 */ 922 usb2_transfer_start(sc->sc_xfer[AUE_INTR_DT_RD]); 923 usb2_transfer_start(sc->sc_xfer[AUE_BULK_DT_RD]); 924 usb2_transfer_start(sc->sc_xfer[AUE_BULK_DT_WR]); |
1251} 1252 1253static void | 925} 926 927static void |
1254aue_init_cb(void *arg) | 928aue_init(struct usb2_ether *ue) |
1255{ | 929{ |
1256 struct aue_softc *sc = arg; | 930 struct aue_softc *sc = usb2_ether_getsc(ue); 931 struct ifnet *ifp = usb2_ether_getifp(ue); 932 int i; |
1257 | 933 |
1258 mtx_lock(&sc->sc_mtx); 1259 usb2_config_td_queue_command 1260 (&sc->sc_config_td, &aue_cfg_pre_init, &aue_cfg_init, 0, 0); 1261 mtx_unlock(&sc->sc_mtx); 1262} | 934 AUE_LOCK_ASSERT(sc, MA_OWNED); |
1263 | 935 |
1264static void 1265aue_start_transfers(struct aue_softc *sc) 1266{ 1267 if ((sc->sc_flags & AUE_FLAG_LL_READY) && 1268 (sc->sc_flags & AUE_FLAG_HL_READY)) { 1269 1270 /* 1271 * start the USB transfers, if not already started: 1272 */ 1273 usb2_transfer_start(sc->sc_xfer[AUE_INTR_DT_RD]); 1274 usb2_transfer_start(sc->sc_xfer[AUE_BULK_DT_RD]); 1275 usb2_transfer_start(sc->sc_xfer[AUE_BULK_DT_WR]); 1276 } 1277} 1278 1279static void 1280aue_cfg_pre_init(struct aue_softc *sc, 1281 struct usb2_config_td_cc *cc, uint16_t refcount) 1282{ 1283 struct ifnet *ifp = sc->sc_ifp; 1284 1285 /* immediate configuration */ 1286 1287 aue_cfg_pre_stop(sc, cc, 0); 1288 1289 ifp->if_drv_flags |= IFF_DRV_RUNNING; 1290 1291 sc->sc_flags |= AUE_FLAG_HL_READY; 1292} 1293 1294static void 1295aue_cfg_init(struct aue_softc *sc, 1296 struct usb2_config_td_cc *cc, uint16_t refcount) 1297{ 1298 struct mii_data *mii = GET_MII(sc); 1299 uint8_t i; 1300 | |
1301 /* 1302 * Cancel pending I/O 1303 */ | 936 /* 937 * Cancel pending I/O 938 */ |
1304 aue_cfg_stop(sc, cc, 0); | 939 aue_reset(sc); |
1305 1306 /* Set MAC address */ | 940 941 /* Set MAC address */ |
1307 for (i = 0; i < ETHER_ADDR_LEN; i++) { 1308 aue_cfg_csr_write_1(sc, AUE_PAR0 + i, cc->if_lladdr[i]); 1309 } | 942 for (i = 0; i != ETHER_ADDR_LEN; i++) 943 aue_csr_write_1(sc, AUE_PAR0 + i, IF_LLADDR(ifp)[i]); |
1310 1311 /* update promiscuous setting */ | 944 945 /* update promiscuous setting */ |
1312 aue_cfg_promisc_upd(sc, cc, 0); | 946 aue_setpromisc(ue); |
1313 | 947 |
1314 /* load the multicast filter */ 1315 aue_cfg_setmulti(sc, cc, 0); | 948 /* Load the multicast filter. */ 949 aue_setmulti(ue); |
1316 | 950 |
1317 /* enable RX and TX */ 1318 aue_cfg_csr_write_1(sc, AUE_CTL0, 1319 (AUE_CTL0_RXSTAT_APPEND | 1320 AUE_CTL0_RX_ENB)); | 951 /* Enable RX and TX */ 952 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB); 953 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB); 954 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR); |
1321 | 955 |
1322 AUE_CFG_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB); 1323 AUE_CFG_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR); | 956 usb2_transfer_set_stall(sc->sc_xfer[AUE_BULK_DT_WR]); |
1324 | 957 |
1325 mii_mediachg(mii); 1326 1327 sc->sc_flags |= (AUE_FLAG_READ_STALL | 1328 AUE_FLAG_WRITE_STALL | 1329 AUE_FLAG_LL_READY); 1330 1331 aue_start_transfers(sc); | 958 ifp->if_drv_flags |= IFF_DRV_RUNNING; 959 aue_start(ue); |
1332} 1333 1334static void | 960} 961 962static void |
1335aue_cfg_promisc_upd(struct aue_softc *sc, 1336 struct usb2_config_td_cc *cc, uint16_t refcount) | 963aue_setpromisc(struct usb2_ether *ue) |
1337{ | 964{ |
965 struct aue_softc *sc = usb2_ether_getsc(ue); 966 struct ifnet *ifp = usb2_ether_getifp(ue); 967 968 AUE_LOCK_ASSERT(sc, MA_OWNED); 969 |
|
1338 /* if we want promiscuous mode, set the allframes bit: */ | 970 /* if we want promiscuous mode, set the allframes bit: */ |
1339 if (cc->if_flags & IFF_PROMISC) { 1340 AUE_CFG_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 1341 } else { 1342 AUE_CFG_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 1343 } | 971 if (ifp->if_flags & IFF_PROMISC) 972 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 973 else 974 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); |
1344} 1345 1346/* 1347 * Set media options. 1348 */ 1349static int | 975} 976 977/* 978 * Set media options. 979 */ 980static int |
1350aue_ifmedia_upd_cb(struct ifnet *ifp) | 981aue_ifmedia_upd(struct ifnet *ifp) |
1351{ 1352 struct aue_softc *sc = ifp->if_softc; | 982{ 983 struct aue_softc *sc = ifp->if_softc; |
1353 1354 mtx_lock(&sc->sc_mtx); 1355 usb2_config_td_queue_command 1356 (&sc->sc_config_td, NULL, &aue_cfg_ifmedia_upd, 0, 0); 1357 mtx_unlock(&sc->sc_mtx); 1358 1359 return (0); 1360} 1361 1362static void 1363aue_cfg_ifmedia_upd(struct aue_softc *sc, 1364 struct usb2_config_td_cc *cc, uint16_t refcount) 1365{ 1366 struct ifnet *ifp = sc->sc_ifp; | |
1367 struct mii_data *mii = GET_MII(sc); 1368 | 984 struct mii_data *mii = GET_MII(sc); 985 |
1369 if ((ifp == NULL) || 1370 (mii == NULL)) { 1371 /* not ready */ 1372 return; 1373 } 1374 sc->sc_flags |= AUE_FLAG_WAIT_LINK; | 986 AUE_LOCK_ASSERT(sc, MA_OWNED); |
1375 | 987 |
988 sc->sc_flags &= ~AUE_FLAG_LINK; |
|
1376 if (mii->mii_instance) { 1377 struct mii_softc *miisc; 1378 | 989 if (mii->mii_instance) { 990 struct mii_softc *miisc; 991 |
1379 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) { | 992 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) |
1380 mii_phy_reset(miisc); | 993 mii_phy_reset(miisc); |
1381 } | |
1382 } 1383 mii_mediachg(mii); | 994 } 995 mii_mediachg(mii); |
996 return (0); |
|
1384} 1385 1386/* 1387 * Report current media status. 1388 */ 1389static void | 997} 998 999/* 1000 * Report current media status. 1001 */ 1002static void |
1390aue_ifmedia_sts_cb(struct ifnet *ifp, struct ifmediareq *ifmr) | 1003aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) |
1391{ 1392 struct aue_softc *sc = ifp->if_softc; | 1004{ 1005 struct aue_softc *sc = ifp->if_softc; |
1006 struct mii_data *mii = GET_MII(sc); |
|
1393 | 1007 |
1394 mtx_lock(&sc->sc_mtx); 1395 1396 ifmr->ifm_active = sc->sc_media_active; 1397 ifmr->ifm_status = sc->sc_media_status; 1398 1399 mtx_unlock(&sc->sc_mtx); | 1008 AUE_LOCK(sc); 1009 mii_pollstat(mii); 1010 AUE_UNLOCK(sc); 1011 ifmr->ifm_active = mii->mii_media_active; 1012 ifmr->ifm_status = mii->mii_media_status; |
1400} 1401 | 1013} 1014 |
1402static int 1403aue_ioctl_cb(struct ifnet *ifp, u_long command, caddr_t data) 1404{ 1405 struct aue_softc *sc = ifp->if_softc; 1406 struct mii_data *mii; 1407 int error = 0; 1408 1409 switch (command) { 1410 case SIOCSIFFLAGS: 1411 mtx_lock(&sc->sc_mtx); 1412 if (ifp->if_flags & IFF_UP) { 1413 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 1414 usb2_config_td_queue_command 1415 (&sc->sc_config_td, &aue_config_copy, 1416 &aue_cfg_promisc_upd, 0, 0); 1417 } else { 1418 usb2_config_td_queue_command 1419 (&sc->sc_config_td, &aue_cfg_pre_init, 1420 &aue_cfg_init, 0, 0); 1421 } 1422 } else { 1423 if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 1424 usb2_config_td_queue_command 1425 (&sc->sc_config_td, &aue_cfg_pre_stop, 1426 &aue_cfg_stop, 0, 0); 1427 } 1428 } 1429 mtx_unlock(&sc->sc_mtx); 1430 break; 1431 1432 case SIOCADDMULTI: 1433 case SIOCDELMULTI: 1434 mtx_lock(&sc->sc_mtx); 1435 usb2_config_td_queue_command 1436 (&sc->sc_config_td, &aue_config_copy, 1437 &aue_cfg_setmulti, 0, 0); 1438 mtx_unlock(&sc->sc_mtx); 1439 break; 1440 1441 case SIOCGIFMEDIA: 1442 case SIOCSIFMEDIA: 1443 mii = GET_MII(sc); 1444 if (mii == NULL) { 1445 error = EINVAL; 1446 } else { 1447 error = ifmedia_ioctl 1448 (ifp, (void *)data, &mii->mii_media, command); 1449 } 1450 break; 1451 1452 default: 1453 error = ether_ioctl(ifp, command, data); 1454 break; 1455 } 1456 return (error); 1457} 1458 1459static void 1460aue_watchdog(void *arg) 1461{ 1462 struct aue_softc *sc = arg; 1463 1464 mtx_assert(&sc->sc_mtx, MA_OWNED); 1465 1466 usb2_config_td_queue_command 1467 (&sc->sc_config_td, NULL, &aue_cfg_tick, 0, 0); 1468 1469 usb2_callout_reset(&sc->sc_watchdog, 1470 hz, &aue_watchdog, sc); 1471} 1472 | |
1473/* 1474 * Stop the adapter and free any mbufs allocated to the 1475 * RX and TX lists. | 1015/* 1016 * Stop the adapter and free any mbufs allocated to the 1017 * RX and TX lists. |
1476 * 1477 * NOTE: can be called when "ifp" is NULL | |
1478 */ 1479static void | 1018 */ 1019static void |
1480aue_cfg_pre_stop(struct aue_softc *sc, 1481 struct usb2_config_td_cc *cc, uint16_t refcount) | 1020aue_stop(struct usb2_ether *ue) |
1482{ | 1021{ |
1483 struct ifnet *ifp = sc->sc_ifp; | 1022 struct aue_softc *sc = usb2_ether_getsc(ue); 1023 struct ifnet *ifp = usb2_ether_getifp(ue); |
1484 | 1024 |
1485 if (cc) { 1486 /* copy the needed configuration */ 1487 aue_config_copy(sc, cc, refcount); 1488 } 1489 /* immediate configuration */ | 1025 AUE_LOCK_ASSERT(sc, MA_OWNED); |
1490 | 1026 |
1491 if (ifp) { 1492 /* clear flags */ 1493 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 1494 } 1495 sc->sc_flags &= ~(AUE_FLAG_HL_READY | 1496 AUE_FLAG_LL_READY); | 1027 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 1028 sc->sc_flags &= ~AUE_FLAG_LINK; |
1497 | 1029 |
1498 sc->sc_flags |= AUE_FLAG_WAIT_LINK; 1499 | |
1500 /* 1501 * stop all the transfers, if not already stopped: 1502 */ 1503 usb2_transfer_stop(sc->sc_xfer[AUE_BULK_DT_WR]); 1504 usb2_transfer_stop(sc->sc_xfer[AUE_BULK_DT_RD]); | 1030 /* 1031 * stop all the transfers, if not already stopped: 1032 */ 1033 usb2_transfer_stop(sc->sc_xfer[AUE_BULK_DT_WR]); 1034 usb2_transfer_stop(sc->sc_xfer[AUE_BULK_DT_RD]); |
1505 usb2_transfer_stop(sc->sc_xfer[AUE_BULK_CS_WR]); 1506 usb2_transfer_stop(sc->sc_xfer[AUE_BULK_CS_RD]); | |
1507 usb2_transfer_stop(sc->sc_xfer[AUE_INTR_DT_RD]); | 1035 usb2_transfer_stop(sc->sc_xfer[AUE_INTR_DT_RD]); |
1508 usb2_transfer_stop(sc->sc_xfer[AUE_INTR_CS_RD]); 1509} | |
1510 | 1036 |
1511static void 1512aue_cfg_stop(struct aue_softc *sc, 1513 struct usb2_config_td_cc *cc, uint16_t refcount) 1514{ 1515 aue_cfg_csr_write_1(sc, AUE_CTL0, 0); 1516 aue_cfg_csr_write_1(sc, AUE_CTL1, 0); 1517 aue_cfg_reset(sc); | 1037 aue_csr_write_1(sc, AUE_CTL0, 0); 1038 aue_csr_write_1(sc, AUE_CTL1, 0); 1039 aue_reset(sc); |
1518} 1519 1520/* 1521 * Stop all chip I/O so that the kernel's probe routines don't 1522 * get confused by errant DMAs when rebooting. 1523 */ 1524static int 1525aue_shutdown(device_t dev) 1526{ 1527 struct aue_softc *sc = device_get_softc(dev); 1528 | 1040} 1041 1042/* 1043 * Stop all chip I/O so that the kernel's probe routines don't 1044 * get confused by errant DMAs when rebooting. 1045 */ 1046static int 1047aue_shutdown(device_t dev) 1048{ 1049 struct aue_softc *sc = device_get_softc(dev); 1050 |
1529 mtx_lock(&sc->sc_mtx); | 1051 usb2_ether_ifshutdown(&sc->sc_ue); |
1530 | 1052 |
1531 usb2_config_td_queue_command 1532 (&sc->sc_config_td, &aue_cfg_pre_stop, 1533 &aue_cfg_stop, 0, 0); 1534 1535 mtx_unlock(&sc->sc_mtx); 1536 | |
1537 return (0); 1538} | 1053 return (0); 1054} |