Date: Sat, 8 Jun 2013 16:02:32 +0000 (UTC) From: Rui Paulo <rpaulo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r251538 - in head: share/man/man4 sys/conf sys/dev/usb sys/dev/usb/wlan sys/modules/usb sys/modules/usb/urtwn Message-ID: <201306081602.r58G2WcG014325@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rpaulo Date: Sat Jun 8 16:02:31 2013 New Revision: 251538 URL: http://svnweb.freebsd.org/changeset/base/251538 Log: Import Kevin Lo's port of urtwn(4) from OpenBSD. urtwn(4) is a driver for the Realtek RTL8188CU/RTL8192CU USB IEEE 802.11b/g/n wireless cards. This driver requires microcode which is available in FreeBSD ports: net/urtwn-firmware-kmod. Hiren ported the urtwn(4) man page from OpenBSD and Glen just commited a port for the firmware. TODO: - 802.11n support - Stability fixes - the driver can sustain lots of traffic but has trouble coping with simultaneous iperf sessions. - fix debugging MFC after: 2 months Tested by: kevlo, hiren, gjb Added: head/share/man/man4/urtwn.4 (contents, props changed) head/sys/dev/usb/wlan/if_urtwn.c (contents, props changed) head/sys/dev/usb/wlan/if_urtwnreg.h (contents, props changed) head/sys/modules/usb/urtwn/ head/sys/modules/usb/urtwn/Makefile (contents, props changed) Modified: head/share/man/man4/Makefile head/sys/conf/NOTES head/sys/conf/files head/sys/dev/usb/usbdevs head/sys/modules/usb/Makefile Modified: head/share/man/man4/Makefile ============================================================================== --- head/share/man/man4/Makefile Sat Jun 8 15:48:29 2013 (r251537) +++ head/share/man/man4/Makefile Sat Jun 8 16:02:31 2013 (r251538) @@ -516,6 +516,7 @@ MAN= aac.4 \ ural.4 \ urio.4 \ ${_urtw.4} \ + urtwn.4 \ usb.4 \ usb_quirk.4 \ uslcom.4 \ Added: head/share/man/man4/urtwn.4 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/share/man/man4/urtwn.4 Sat Jun 8 16:02:31 2013 (r251538) @@ -0,0 +1,140 @@ +.\" $OpenBSD: urtwn.4,v 1.20 2013/05/16 10:02:59 sthen Exp $ +.\" $FreeBSD$ +.\" +.\" Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd July 7, 2013 +.Dt URTWN 4 +.Os +.Sh NAME +.Nm urtwn +.Nd Realtek RTL8188CU/RTL8192CU USB IEEE 802.11b/g/n wireless network device +.Sh SYNOPSIS +To compile this driver into the kernel, +place the following lines in your +kernel configuration file: +.Bd -ragged -offset indent +.Cd "device ehci" +.Cd "device uhci" +.Cd "device ohci" +.Cd "device usb" +.Cd "device urtwn" +.Cd "device wlan" +.Ed +.Pp +Alternatively, to load the driver as a +module at boot time, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +if_urtwn_load="YES" +.Ed +.Sh DESCRIPTION +The +.Nm +driver supports USB 2.0 wireless network devices based on Realtek +RTL8188CUS, RTL8188CE-VAU, RTL8188RU and RTL8192CU chipsets. +.Pp +The RTL8188CUS is a highly integrated 802.11n adapter that combines +a MAC, a 1T1R capable baseband and an RF in a single chip. +It operates in the 2GHz spectrum only. +The RTL8188RU is a high-power variant of the RTL8188CUS. +The RTL8188CE-VAU is a PCI Express Mini Card adapter that attaches +to the USB interface. +.Pp +The RTL8192CU is a highly integrated multiple-in, multiple-out (MIMO) +802.11n adapter that combines a MAC, a 2T2R capable baseband and an +RF in a single chip. +It operates in the 2GHz spectrum only. +.Pp +The driver needs at least version 1.1p0 of the following firmware files, +which are loaded when an interface is attached: +.Pp +.Bl -tag -width Ds -offset indent -compact +.It urtwn-rtl8192cfwT +.It urtwn-rtl8192cfwU +.It urtwn-rtl8723fw +.El +.Pp +The firmware is available as part of the FreeBSD Ports collection in +net/urtwn-firmware-kmod. +.Sh HARDWARE +The following adapters should work: +.Pp +.Bl -tag -width Ds -offset indent -compact +.It Belkin F7D1102 Surf Wireless Micro +.It Edimax EW-7811Un +.It Netgear WNA1000M +.It Realtek RTL8192CU +.It Realtek RTL8188CUS +.El +.Sh EXAMPLES +Join an existing BSS network (i.e., connect to an access point): +.Bd -literal -offset indent +ifconfig wlan create wlandev urtwn0 inet 192.168.0.20 \e + netmask 0xffffff00 +.Ed +.Pp +Join a specific BSS network with network name +.Dq Li my_net : +.Pp +.Dl "ifconfig wlan create wlandev urtwn0 ssid my_net up" +.Pp +Join a specific BSS network with 64-bit WEP encryption: +.Bd -literal -offset indent +ifconfig wlan create wlandev urtwn0 ssid my_net \e + wepmode on wepkey 0x1234567890 weptxkey 1 up +.Ed +.Sh DIAGNOSTICS +.Bl -diag +.It "urtwn%d: error %d, could not read firmware %s" +For some reason, the driver was unable to read the microcode file from the +filesystem. +The file might be missing or corrupted. +.It "urtwn%d: device timeout" +A frame dispatched to the hardware for transmission did not complete in time. +The driver will reset the hardware. +This should not happen. +.El +.Sh SEE ALSO +.Xr intro 4 , +.Xr netintro 4 , +.Xr usb 4 , +.Xr wlan 4 , +.Xr wlan_ccmp 4 , +.Xr wlan_tkip 4 , +.Xr wlan_wep 4 , +.Xr ifconfig 8, +.Xr wpa_supplicant 8 +.Rs +.%T Realtek +.%U http://www.realtek.com.tw +.Re +.Sh HISTORY +The +.Nm +driver first appeared in +.Ox 4.9 +and +.Fx 10.0 . +.Sh AUTHORS +The +.Nm +driver was written by +.An Damien Bergamini Aq damien@openbsd.org . +.Sh CAVEATS +The +.Nm +driver does not support any of the 802.11n capabilities offered by the +adapters. Modified: head/sys/conf/NOTES ============================================================================== --- head/sys/conf/NOTES Sat Jun 8 15:48:29 2013 (r251537) +++ head/sys/conf/NOTES Sat Jun 8 16:02:31 2013 (r251538) @@ -2747,6 +2747,9 @@ device ural # Realtek RTL8187B/L wireless driver device urtw # +# Realtek RTL8188CU/RTL8192CU wireless driver +device urtwn +# # ZyDas ZD1211/ZD1211B wireless driver device zyd # Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Sat Jun 8 15:48:29 2013 (r251537) +++ head/sys/conf/files Sat Jun 8 16:02:31 2013 (r251538) @@ -2292,6 +2292,7 @@ dev/usb/wlan/if_uath.c optional uath dev/usb/wlan/if_upgt.c optional upgt dev/usb/wlan/if_ural.c optional ural dev/usb/wlan/if_urtw.c optional urtw +dev/usb/wlan/if_urtwn.c optional urtwn dev/usb/wlan/if_zyd.c optional zyd # # USB serial and parallel port drivers Modified: head/sys/dev/usb/usbdevs ============================================================================== --- head/sys/dev/usb/usbdevs Sat Jun 8 15:48:29 2013 (r251537) +++ head/sys/dev/usb/usbdevs Sat Jun 8 16:02:31 2013 (r251538) @@ -571,6 +571,7 @@ vendor KONTRON 0x0fe6 Kontron AG vendor QUALCOMM 0x1004 Qualcomm vendor APACER 0x1005 Apacer vendor MOTOROLA4 0x100d Motorola +vendor HP3 0x103c Hewlett Packard vendor AIRPLUS 0x1011 Airplus vendor DESKNOTE 0x1019 Desknote vendor NEC3 0x1033 NEC @@ -720,6 +721,7 @@ vendor ENCORE 0x203d Encore vendor QIHARDWARE 0x20b7 QI-hardware vendor PARA 0x20b8 PARA Industrial vendor SIMTEC 0x20df Simtec Electronics +vendor TRENDNET 0x20f4 TRENDnet vendor RTSYSTEMS 0x2100 RTSYSTEMS vendor VIALABS 0x2109 VIA Labs vendor ERICSSON 0x2282 Ericsson @@ -742,6 +744,7 @@ vendor IRIVER 0x4102 iRiver vendor DELL 0x413c Dell vendor WCH 0x4348 QinHeng Electronics vendor ACEECA 0x4766 Aceeca +vendor FEIXUN 0x4855 FeiXun Communication vendor PAPOUCH 0x5050 Papouch products vendor AVERATEC 0x50c2 Averatec vendor SWEEX 0x5173 Sweex @@ -757,6 +760,7 @@ vendor INTEL2 0x8087 Intel vendor ALLWIN 0x8516 ALLWIN Tech vendor SITECOM2 0x9016 Sitecom vendor MOSCHIP 0x9710 MosChip Semiconductor +vendor NETGEAR4 0x9846 Netgear vendor MARVELL 0x9e88 Marvell Technology Group Ltd. vendor 3COM3 0xa727 3Com vendor EVOLUTION 0xdeee Evolution Robotics products @@ -814,6 +818,9 @@ product ABOCOM HWU54DM 0xb21b HWU54DM product ABOCOM RT2573_2 0xb21c RT2573 product ABOCOM RT2573_3 0xb21d RT2573 product ABOCOM RT2573_4 0xb21e RT2573 +product ABOCOM RTL8188CU_1 0x8188 RTL8188CU +product ABOCOM RTL8188CU_2 0x8189 RTL8188CU +product ABOCOM RTL8192CU 0x8178 RTL8192CU product ABOCOM WUG2700 0xb21f WUG2700 /* Acton Research Corp. */ @@ -1126,6 +1133,7 @@ product ASUS RT2870_4 0x1760 RT2870 product ASUS RT2870_5 0x1761 RT2870 product ASUS USBN13 0x1784 USB-N13 product ASUS RT3070_1 0x1790 RT3070 +product ASUS RTL8192CU 0x17ab RTL8192CU product ASUS A730W 0x4202 ASUS MyPal A730W product ASUS P535 0x420f ASUS P535 PDA product ASUS GMSC 0x422f ASUS Generic Mass Storage @@ -1173,6 +1181,10 @@ product AZUREWAVE RT2870_2 0x3262 RT2870 product AZUREWAVE RT3070_1 0x3273 RT3070 product AZUREWAVE RT3070_2 0x3284 RT3070 product AZUREWAVE RT3070_3 0x3305 RT3070 +product AZUREWAVE RTL8188CU 0x3357 RTL8188CU +product AZUREWAVE RTL8188CE_1 0x3358 RTL8188CE +product AZUREWAVE RTL8188CE_2 0x3359 RTL8188CE + /* Baltech products */ product BALTECH CARDREADER 0x9999 Card reader @@ -1215,6 +1227,9 @@ product BELKIN F5U257 0x0257 F5U257 Ser product BELKIN F5U409 0x0409 F5U409 Serial product BELKIN F6C550AVR 0x0551 F6C550-AVR UPS product BELKIN F5U120 0x1203 F5U120-PC Hub +product BELKIN RTL8188CU 0x1102 RTL8188CU Wireless Adapter +product BELKIN RTL8192CU 0x2102 RTL8192CU Wireless Adapter +product BELKIN F7D2102 0x2103 F7D2102 Wireless Adapter product BELKIN ZD1211B 0x4050 ZD1211B product BELKIN F5D5055 0x5055 F5D5055 product BELKIN F5D7050 0x7050 F5D7050 Wireless Adapter @@ -1294,6 +1309,11 @@ product CHIC CYPRESS 0x0003 Cypress USB product CHICONY KB8933 0x0001 KB-8933 keyboard product CHICONY KU0325 0x0116 KU-0325 keyboard product CHICONY CNF7129 0xb071 Notebook Web Camera +product CHICONY RTL8188CUS_1 0xaff7 RTL8188CUS +product CHICONY RTL8188CUS_2 0xaff8 RTL8188CUS +product CHICONY RTL8188CUS_3 0xaff9 RTL8188CUS +product CHICONY RTL8188CUS_4 0xaffa RTL8188CUS +product CHICONY RTL8188CUS_5 0xaffa RTL8188CUS product CHICONY2 TWINKLECAM 0x600d TwinkleCam USB camera /* CH Products */ @@ -1383,6 +1403,7 @@ product COREGA RT2870_2 0x003c RT2870 product COREGA RT2870_3 0x003f RT2870 product COREGA RT3070 0x0041 RT3070 product COREGA CGWLUSB300GNM 0x0042 CG-WLUSB300GNM +product COREGA RTL8192CU 0x0056 RTL8192CU product COREGA WLUSB_11_STICK 0x7613 WLAN USB Stick 11 product COREGA FETHER_USB_TXC 0x9601 FEther USB-TXC @@ -1519,6 +1540,10 @@ product DLINK DSB650 0xabc1 10/100 Ethe product DLINK DUBH7 0xf103 DUB-H7 USB 2.0 7-Port Hub product DLINK DWR510_CD 0xa805 DWR-510 CD-ROM Mode product DLINK DWR510 0x7e12 DWR-510 +product DLINK RTL8188CU 0x3308 RTL8188CU +product DLINK RTL8192CU_1 0x3307 RTL8192CU +product DLINK RTL8192CU_2 0x3309 RTL8192CU +product DLINK RTL8192CU_3 0x330a RTL8192CU product DLINK2 DWA120 0x3a0c DWA-120 product DLINK2 DWA120_NF 0x3a0d DWA-120 (no firmware) product DLINK2 DWLG122C1 0x3c03 DWL-G122 c1 @@ -1559,6 +1584,7 @@ product EDIMAX RT2870_1 0x7711 RT2870 product EDIMAX EW7717 0x7717 EW-7717 product EDIMAX EW7718 0x7718 EW-7718 product EDIMAX EW7811UN 0x7811 EW-7811Un +product EDIMAX RTL8192CU 0x7822 RTL8192CU /* eGalax Products */ product EGALAX TPANEL 0x0001 Touch Panel @@ -1691,6 +1717,10 @@ product FEIYA 5IN1 0x1132 5-in-1 Card R product FEIYA ELANGO 0x6200 MicroSDHC Card Reader product FEIYA AC110 0x6300 AC-110 Card Reader +/* FeiXun Communication products */ +product FEIXUN RTL8188CU 0x0090 RTL8188CU +product FEIXUN RTL8192CU 0x0091 RTL8192CU + /* Festo */ product FESTO CPX_USB 0x0102 CPX-USB product FESTO CMSP 0x0501 CMSP @@ -2043,6 +2073,7 @@ product GUILLEMOT HWGUSB254 0xe000 HWGUS product GUILLEMOT HWGUSB254LB 0xe010 HWGUSB2-54-LB product GUILLEMOT HWGUSB254V2AP 0xe020 HWGUSB2-54V2-AP product GUILLEMOT HWNU300 0xe030 HWNU-300 +product GUILLEMOT HWNUP150 0xe033 HWNUP-150 /* Hagiwara products */ product HAGIWARA FGSM 0x0002 FlashGate SmartMedia Card Reader @@ -2066,6 +2097,7 @@ product HAWKING RT2870_1 0x0001 RT2870 product HAWKING RT2870_2 0x0003 RT2870 product HAWKING HWUN2 0x0009 HWUN2 product HAWKING RT3070 0x000b RT3070 +product HAWKING RTL8192CU 0x0019 RTL8192CU product HAWKING UF100 0x400c 10/100 USB Ethernet /* HID Global GmbH products */ @@ -2115,6 +2147,7 @@ product HP 5400C 0x1005 Scanjet 5400C product HP 2215 0x1016 iPAQ 22xx/Jornada 548 product HP 568J 0x1116 Jornada 568 product HP 930C 0x1204 DeskJet 930c +product HP3 RTL8188CU 0x1629 RTL8188CU product HP P2000U 0x1801 Inkjet P-2000U product HP HS2300 0x1e1d HS2300 HSDPA (aka MC8775) product HP 640C 0x2004 DeskJet 640c @@ -3024,6 +3057,8 @@ product NETGEAR WG111V3 0x4260 WG111v3 product NETGEAR WG111U 0x4300 WG111U product NETGEAR WG111U_NF 0x4301 WG111U (no firmware) product NETGEAR WG111V2 0x6a00 WG111V2 +product NETGEAR RTL8192CU 0x9021 RTL8192CU +product NETGEAR WNA1000M 0x9041 WNA1000M product NETGEAR2 MA101 0x4100 MA101 product NETGEAR2 MA101B 0x4102 MA101 Rev B product NETGEAR3 WG111T 0x4250 WG111T @@ -3031,6 +3066,7 @@ product NETGEAR3 WG111T_NF 0x4251 WG111T product NETGEAR3 WPN111 0x5f00 WPN111 product NETGEAR3 WPN111_NF 0x5f01 WPN111 (no firmware) product NETGEAR3 WPN111_2 0x5f02 WPN111 +product NETGEAR4 RTL8188CU 0x9041 RTL8188CU /* NetIndex products */ product NETINDEX WS002IN 0x2001 Willcom WS002IN @@ -3046,6 +3082,7 @@ product NIKON D300 0x041a Digital Came /* NovaTech Products */ product NOVATECH NV902 0x9020 NovaTech NV-902W product NOVATECH RT2573 0x9021 RT2573 +product NOVATECH RTL8188CU 0x9071 RTL8188CU /* Nokia products */ product NOKIA N958GB 0x0070 Nokia N95 8GBc @@ -3274,8 +3311,14 @@ product PIENGINEERING PS2USB 0x020b PS2 /* Planex Communications products */ product PLANEX GW_US11H 0x14ea GW-US11H WLAN +product PLANEX2 RTL8188CUS 0x1201 RTL8188CUS product PLANEX2 GW_US11S 0x3220 GW-US11S WLAN product PLANEX2 GW_US54GXS 0x5303 GW-US54GXS WLAN +product PLANEX2 RTL8188CU_1 0xab2a RTL8188CU +product PLANEX2 RTL8188CU_2 0xed17 RTL8188CU +product PLANEX2 RTL8188CU_3 0x4902 RTL8188CU +product PLANEX2 RTL8188CU_4 0xab2e RTL8188CU +product PLANEX2 RTL8192CU 0xab2b RTL8192CU product PLANEX2 GWUS54HP 0xab01 GW-US54HP product PLANEX2 GWUS300MINIS 0xab24 GW-US300MiniS product PLANEX2 RT3070 0xab25 RT3070 @@ -3502,11 +3545,24 @@ product RATOC REXUSB60F 0xb020 USB seri /* Green House and CompUSA OEM this part */ product REALTEK DUMMY 0x0000 Dummy product product REALTEK USB20CRW 0x0158 USB20CRW Card Reader +product REALTEK RTL8188CTV 0x018a RTL8188CTV product REALTEK USBKR100 0x8150 USBKR100 USB Ethernet +product REALTEK RTL8188CE_0 0x8170 RTL8188CE +product REALTEK RTL8188CE_1 0x817e RTL8188CE +product REALTEK RTL8188CU_0 0x8176 RTL8188CU +product REALTEK RTL8188CU_1 0x817a RTL8188CU +product REALTEK RTL8188CU_2 0x817b RTL8188CU product REALTEK RTL8187 0x8187 RTL8187 Wireless Adapter product REALTEK RTL8187B_0 0x8189 RTL8187B Wireless Adapter product REALTEK RTL8187B_1 0x8197 RTL8187B Wireless Adapter product REALTEK RTL8187B_2 0x8198 RTL8187B Wireless Adapter +product REALTEK RTL8188CUS 0x818a RTL8188CUS +product REALTEK RTL8188CU_COMBO 0x8754 RTL8188CU +product REALTEK RTL8191CU 0x8177 RTL8191CU +product REALTEK RTL8192CU 0x8178 RTL8192CU +product REALTEK RTL8192CE 0x817c RTL8192CE +product REALTEK RTL8188RU_1 0x817d RTL8188RU +product REALTEK RTL8188RU_2 0x317f RTL8188RU /* RedOctane products */ product REDOCTANE DUMMY 0x0000 Dummy product @@ -3881,6 +3937,9 @@ product SITECOMEU RT3072_3 0x0047 RT3072 product SITECOMEU RT3072_4 0x0048 RT3072 product SITECOMEU RT3072_5 0x004a RT3072 product SITECOMEU RT3072_6 0x004d RT3072 +product SITECOMEU RTL8188CU_1 0x0052 RTL8188CU +product SITECOMEU RTL8188CU_2 0x005c RTL8188CU +product SITECOMEU RTL8192CU 0x0061 RTL8192CU product SITECOMEU LN028 0x061c LN-028 product SITECOMEU WL113 0x9071 WL-113 product SITECOMEU ZD1211B 0x9075 ZD1211B @@ -4110,6 +4169,10 @@ product TREK THUMBDRIVE 0x1111 ThumbDri product TREK MEMKEY 0x8888 IBM USB Memory Key product TREK THUMBDRIVE_8MB 0x9988 ThumbDrive_8MB +/* TRENDnet products */ +product TRENDNET RTL8192CU 0x624d RTL8192CU +product TRENDNET RTL8188CU 0x648b RTL8188CU + /* Tripp-Lite products */ product TRIPPLITE U209 0x2008 Serial @@ -4319,3 +4382,4 @@ product ZYXEL G220V2 0x340f G-220 v2 product ZYXEL G202 0x3410 G-202 product ZYXEL RT2870_1 0x3416 RT2870 product ZYXEL RT2870_2 0x341a RT2870 +product ZYXEL RTL8192CU 0x341f RTL8192CU Added: head/sys/dev/usb/wlan/if_urtwn.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/usb/wlan/if_urtwn.c Sat Jun 8 16:02:31 2013 (r251538) @@ -0,0 +1,3016 @@ +/* $OpenBSD: if_urtwn.c,v 1.16 2011/02/10 17:26:40 jakemsr Exp $ */ + +/*- + * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * Driver for Realtek RTL8188CE-VAU/RTL8188CUS/RTL8188RU/RTL8192CU. + */ + +#include <sys/param.h> +#include <sys/sockio.h> +#include <sys/sysctl.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <sys/mbuf.h> +#include <sys/kernel.h> +#include <sys/socket.h> +#include <sys/systm.h> +#include <sys/malloc.h> +#include <sys/module.h> +#include <sys/bus.h> +#include <sys/endian.h> +#include <sys/linker.h> +#include <sys/firmware.h> +#include <sys/kdb.h> + +#include <machine/bus.h> +#include <machine/resource.h> +#include <sys/rman.h> + +#include <net/bpf.h> +#include <net/if.h> +#include <net/if_arp.h> +#include <net/ethernet.h> +#include <net/if_dl.h> +#include <net/if_media.h> +#include <net/if_types.h> + +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/in_var.h> +#include <netinet/if_ether.h> +#include <netinet/ip.h> + +#include <net80211/ieee80211_var.h> +#include <net80211/ieee80211_regdomain.h> +#include <net80211/ieee80211_radiotap.h> +#include <net80211/ieee80211_ratectl.h> + +#include <dev/usb/usb.h> +#include <dev/usb/usbdi.h> +#include "usbdevs.h" + +#define USB_DEBUG_VAR urtwn_debug +#include <dev/usb/usb_debug.h> + +#include <dev/usb/wlan/if_urtwnreg.h> + +#ifdef USB_DEBUG +static int urtwn_debug = 0; + +SYSCTL_NODE(_hw_usb, OID_AUTO, urtwn, CTLFLAG_RW, 0, "USB urtwn"); +SYSCTL_INT(_hw_usb_urtwn, OID_AUTO, debug, CTLFLAG_RW, &urtwn_debug, 0, + "Debug level"); +#endif + +#define IEEE80211_HAS_ADDR4(wh) \ + (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS) + +/* various supported device vendors/products */ +static const struct usb_device_id urtwn_devs[] = { +#define URTWN_DEV(v,p) { USB_VP(USB_VENDOR_##v, USB_PRODUCT_##v##_##p) } + URTWN_DEV(ABOCOM, RTL8188CU_1), + URTWN_DEV(ABOCOM, RTL8188CU_2), + URTWN_DEV(ABOCOM, RTL8192CU), + URTWN_DEV(ASUS, RTL8192CU), + URTWN_DEV(AZUREWAVE, RTL8188CE_1), + URTWN_DEV(AZUREWAVE, RTL8188CE_2), + URTWN_DEV(AZUREWAVE, RTL8188CU), + URTWN_DEV(BELKIN, F7D2102), + URTWN_DEV(BELKIN, RTL8188CU), + URTWN_DEV(BELKIN, RTL8192CU), + URTWN_DEV(CHICONY, RTL8188CUS_1), + URTWN_DEV(CHICONY, RTL8188CUS_2), + URTWN_DEV(CHICONY, RTL8188CUS_3), + URTWN_DEV(CHICONY, RTL8188CUS_4), + URTWN_DEV(CHICONY, RTL8188CUS_5), + URTWN_DEV(COREGA, RTL8192CU), + URTWN_DEV(DLINK, RTL8188CU), + URTWN_DEV(DLINK, RTL8192CU_1), + URTWN_DEV(DLINK, RTL8192CU_2), + URTWN_DEV(DLINK, RTL8192CU_3), + URTWN_DEV(EDIMAX, EW7811UN), + URTWN_DEV(EDIMAX, RTL8192CU), + URTWN_DEV(FEIXUN, RTL8188CU), + URTWN_DEV(FEIXUN, RTL8192CU), + URTWN_DEV(GUILLEMOT, HWNUP150), + URTWN_DEV(HAWKING, RTL8192CU), + URTWN_DEV(HP3, RTL8188CU), + URTWN_DEV(NETGEAR, WNA1000M), + URTWN_DEV(NETGEAR, RTL8192CU), + URTWN_DEV(NETGEAR4, RTL8188CU), + URTWN_DEV(NOVATECH, RTL8188CU), + URTWN_DEV(PLANEX2, RTL8188CU_1), + URTWN_DEV(PLANEX2, RTL8188CU_2), + URTWN_DEV(PLANEX2, RTL8188CU_3), + URTWN_DEV(PLANEX2, RTL8188CU_4), + URTWN_DEV(PLANEX2, RTL8188CUS), + URTWN_DEV(PLANEX2, RTL8192CU), + URTWN_DEV(REALTEK, RTL8188CE_0), + URTWN_DEV(REALTEK, RTL8188CE_1), + URTWN_DEV(REALTEK, RTL8188CTV), + URTWN_DEV(REALTEK, RTL8188CU_0), + URTWN_DEV(REALTEK, RTL8188CU_1), + URTWN_DEV(REALTEK, RTL8188CU_2), + URTWN_DEV(REALTEK, RTL8188CU_COMBO), + URTWN_DEV(REALTEK, RTL8188CUS), + URTWN_DEV(REALTEK, RTL8188RU_1), + URTWN_DEV(REALTEK, RTL8188RU_2), + URTWN_DEV(REALTEK, RTL8191CU), + URTWN_DEV(REALTEK, RTL8192CE), + URTWN_DEV(REALTEK, RTL8192CU), + URTWN_DEV(SITECOMEU, RTL8188CU_1), + URTWN_DEV(SITECOMEU, RTL8188CU_2), + URTWN_DEV(SITECOMEU, RTL8192CU), + URTWN_DEV(TRENDNET, RTL8188CU), + URTWN_DEV(TRENDNET, RTL8192CU), + URTWN_DEV(ZYXEL, RTL8192CU), +#undef URTWN_DEV +}; + +static device_probe_t urtwn_match; +static device_attach_t urtwn_attach; +static device_detach_t urtwn_detach; + +static usb_callback_t urtwn_bulk_tx_callback; +static usb_callback_t urtwn_bulk_rx_callback; + +static usb_error_t urtwn_do_request(struct urtwn_softc *sc, + struct usb_device_request *req, void *data); +static struct ieee80211vap *urtwn_vap_create(struct ieee80211com *, + const char [IFNAMSIZ], int, enum ieee80211_opmode, int, + const uint8_t [IEEE80211_ADDR_LEN], + const uint8_t [IEEE80211_ADDR_LEN]); +static void urtwn_vap_delete(struct ieee80211vap *); +static struct mbuf * urtwn_rx_frame(struct urtwn_softc *, uint8_t *, int, + int *); +static struct mbuf * urtwn_rxeof(struct usb_xfer *, struct urtwn_data *, + int *, int8_t *); +static void urtwn_txeof(struct usb_xfer *, struct urtwn_data *); +static int urtwn_alloc_list(struct urtwn_softc *, + struct urtwn_data[], int, int); +static int urtwn_alloc_rx_list(struct urtwn_softc *); +static int urtwn_alloc_tx_list(struct urtwn_softc *); +static void urtwn_free_tx_list(struct urtwn_softc *); +static void urtwn_free_rx_list(struct urtwn_softc *); +static void urtwn_free_list(struct urtwn_softc *, + struct urtwn_data data[], int); +static struct urtwn_data * _urtwn_getbuf(struct urtwn_softc *); +static struct urtwn_data * urtwn_getbuf(struct urtwn_softc *); +static int urtwn_write_region_1(struct urtwn_softc *, uint16_t, + uint8_t *, int); +static void urtwn_write_1(struct urtwn_softc *, uint16_t, uint8_t); +static void urtwn_write_2(struct urtwn_softc *, uint16_t, uint16_t); +static void urtwn_write_4(struct urtwn_softc *, uint16_t, uint32_t); +static int urtwn_read_region_1(struct urtwn_softc *, uint16_t, + uint8_t *, int); +static uint8_t urtwn_read_1(struct urtwn_softc *, uint16_t); +static uint16_t urtwn_read_2(struct urtwn_softc *, uint16_t); +static uint32_t urtwn_read_4(struct urtwn_softc *, uint16_t); +static int urtwn_fw_cmd(struct urtwn_softc *, uint8_t, + const void *, int); +static void urtwn_rf_write(struct urtwn_softc *, int, uint8_t, + uint32_t); +static uint32_t urtwn_rf_read(struct urtwn_softc *, int, uint8_t); +static int urtwn_llt_write(struct urtwn_softc *, uint32_t, + uint32_t); +static uint8_t urtwn_efuse_read_1(struct urtwn_softc *, uint16_t); +static void urtwn_efuse_read(struct urtwn_softc *); +static int urtwn_read_chipid(struct urtwn_softc *); +static void urtwn_read_rom(struct urtwn_softc *); +static int urtwn_ra_init(struct urtwn_softc *); +static void urtwn_tsf_sync_enable(struct urtwn_softc *); +static void urtwn_set_led(struct urtwn_softc *, int, int); +static int urtwn_newstate(struct ieee80211vap *, + enum ieee80211_state, int); +static void urtwn_watchdog(void *); +static void urtwn_update_avgrssi(struct urtwn_softc *, int, int8_t); +static int8_t urtwn_get_rssi(struct urtwn_softc *, int, void *); +static int urtwn_tx_start(struct urtwn_softc *, + struct ieee80211_node *, struct mbuf *, + struct urtwn_data *); +static void urtwn_start(struct ifnet *); +static int urtwn_ioctl(struct ifnet *, u_long, caddr_t); +static int urtwn_power_on(struct urtwn_softc *); +static int urtwn_llt_init(struct urtwn_softc *); +static void urtwn_fw_reset(struct urtwn_softc *); +static int urtwn_fw_loadpage(struct urtwn_softc *, int, + const uint8_t *, int); +static int urtwn_load_firmware(struct urtwn_softc *); +static int urtwn_dma_init(struct urtwn_softc *); +static void urtwn_mac_init(struct urtwn_softc *); +static void urtwn_bb_init(struct urtwn_softc *); +static void urtwn_rf_init(struct urtwn_softc *); +static void urtwn_cam_init(struct urtwn_softc *); +static void urtwn_pa_bias_init(struct urtwn_softc *); +static void urtwn_rxfilter_init(struct urtwn_softc *); +static void urtwn_edca_init(struct urtwn_softc *); +static void urtwn_write_txpower(struct urtwn_softc *, int, + uint16_t[]); +static void urtwn_get_txpower(struct urtwn_softc *, int, + struct ieee80211_channel *, + struct ieee80211_channel *, uint16_t[]); +static void urtwn_set_txpower(struct urtwn_softc *, + struct ieee80211_channel *, + struct ieee80211_channel *); +static void urtwn_scan_start(struct ieee80211com *); +static void urtwn_scan_end(struct ieee80211com *); +static void urtwn_set_channel(struct ieee80211com *); +static void urtwn_set_chan(struct urtwn_softc *, + struct ieee80211_channel *, + struct ieee80211_channel *); +static void urtwn_update_mcast(struct ifnet *); +static void urtwn_iq_calib(struct urtwn_softc *); +static void urtwn_lc_calib(struct urtwn_softc *); +static void urtwn_init(void *); +static void urtwn_init_locked(void *); +static void urtwn_stop(struct ifnet *, int); +static void urtwn_stop_locked(struct ifnet *, int); +static void urtwn_abort_xfers(struct urtwn_softc *); +static int urtwn_raw_xmit(struct ieee80211_node *, struct mbuf *, + const struct ieee80211_bpf_params *); + +/* Aliases. */ +#define urtwn_bb_write urtwn_write_4 +#define urtwn_bb_read urtwn_read_4 + +static const struct usb_config urtwn_config[URTWN_N_TRANSFER] = { + [URTWN_BULK_RX] = { + .type = UE_BULK, + .endpoint = UE_ADDR_ANY, + .direction = UE_DIR_IN, + .bufsize = URTWN_RXBUFSZ, + .flags = { + .pipe_bof = 1, + .short_xfer_ok = 1 + }, + .callback = urtwn_bulk_rx_callback, + }, + [URTWN_BULK_TX_BE] = { + .type = UE_BULK, + .endpoint = 0x03, + .direction = UE_DIR_OUT, + .bufsize = URTWN_TXBUFSZ, + .flags = { + .ext_buffer = 1, + .pipe_bof = 1, + .force_short_xfer = 1 + }, + .callback = urtwn_bulk_tx_callback, + .timeout = URTWN_TX_TIMEOUT, /* ms */ + }, + [URTWN_BULK_TX_BK] = { + .type = UE_BULK, + .endpoint = 0x03, + .direction = UE_DIR_OUT, + .bufsize = URTWN_TXBUFSZ, + .flags = { + .ext_buffer = 1, + .pipe_bof = 1, + .force_short_xfer = 1, + }, + .callback = urtwn_bulk_tx_callback, + .timeout = URTWN_TX_TIMEOUT, /* ms */ + }, + [URTWN_BULK_TX_VI] = { + .type = UE_BULK, + .endpoint = 0x02, + .direction = UE_DIR_OUT, + .bufsize = URTWN_TXBUFSZ, + .flags = { + .ext_buffer = 1, + .pipe_bof = 1, + .force_short_xfer = 1 + }, + .callback = urtwn_bulk_tx_callback, + .timeout = URTWN_TX_TIMEOUT, /* ms */ + }, + [URTWN_BULK_TX_VO] = { + .type = UE_BULK, + .endpoint = 0x02, + .direction = UE_DIR_OUT, + .bufsize = URTWN_TXBUFSZ, + .flags = { + .ext_buffer = 1, + .pipe_bof = 1, + .force_short_xfer = 1 + }, + .callback = urtwn_bulk_tx_callback, + .timeout = URTWN_TX_TIMEOUT, /* ms */ + }, +}; + +static int +urtwn_match(device_t self) +{ + struct usb_attach_arg *uaa = device_get_ivars(self); + + if (uaa->usb_mode != USB_MODE_HOST) + return (ENXIO); + if (uaa->info.bConfigIndex != URTWN_CONFIG_INDEX) + return (ENXIO); + if (uaa->info.bIfaceIndex != URTWN_IFACE_INDEX) + return (ENXIO); + + return (usbd_lookup_id_by_uaa(urtwn_devs, sizeof(urtwn_devs), uaa)); +} + +static int +urtwn_attach(device_t self) +{ + struct usb_attach_arg *uaa = device_get_ivars(self); + struct urtwn_softc *sc = device_get_softc(self); + struct ifnet *ifp; + struct ieee80211com *ic; + uint8_t iface_index, bands; + int error; + + device_set_usb_desc(self); + sc->sc_udev = uaa->device; + sc->sc_dev = self; + + mtx_init(&sc->sc_mtx, device_get_nameunit(self), + MTX_NETWORK_LOCK, MTX_DEF); + callout_init(&sc->sc_watchdog_ch, 0); + + iface_index = URTWN_IFACE_INDEX; + error = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, + urtwn_config, URTWN_N_TRANSFER, sc, &sc->sc_mtx); + if (error) { + device_printf(self, "could not allocate USB transfers, " + "err=%s\n", usbd_errstr(error)); + goto detach; + } + + URTWN_LOCK(sc); + + error = urtwn_read_chipid(sc); + if (error) { + device_printf(sc->sc_dev, "unsupported test chip\n"); + URTWN_UNLOCK(sc); + goto detach; + } + + /* Determine number of Tx/Rx chains. */ + if (sc->chip & URTWN_CHIP_92C) { + sc->ntxchains = (sc->chip & URTWN_CHIP_92C_1T2R) ? 1 : 2; + sc->nrxchains = 2; + } else { + sc->ntxchains = 1; + sc->nrxchains = 1; + } + urtwn_read_rom(sc); + + device_printf(sc->sc_dev, "MAC/BB RTL%s, RF 6052 %dT%dR\n", + (sc->chip & URTWN_CHIP_92C) ? "8192CU" : + (sc->board_type == R92C_BOARD_TYPE_HIGHPA) ? "8188RU" : + (sc->board_type == R92C_BOARD_TYPE_MINICARD) ? "8188CE-VAU" : + "8188CUS", sc->ntxchains, sc->nrxchains); + + URTWN_UNLOCK(sc); + + ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); + if (ifp == NULL) { + device_printf(sc->sc_dev, "can not if_alloc()\n"); + goto detach; + } + ic = ifp->if_l2com; + + ifp->if_softc = sc; + if_initname(ifp, "urtwn", device_get_unit(sc->sc_dev)); + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_init = urtwn_init; + ifp->if_ioctl = urtwn_ioctl; + ifp->if_start = urtwn_start; + IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); + ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; + IFQ_SET_READY(&ifp->if_snd); + + ic->ic_ifp = ifp; + ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */ + ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */ + + /* set device capabilities */ + ic->ic_caps = + IEEE80211_C_STA /* station mode */ + | IEEE80211_C_MONITOR /* monitor mode */ + | IEEE80211_C_SHPREAMBLE /* short preamble supported */ + | IEEE80211_C_SHSLOT /* short slot time supported */ + | IEEE80211_C_BGSCAN /* capable of bg scanning */ + | IEEE80211_C_WPA /* 802.11i */ + ; + + bands = 0; + setbit(&bands, IEEE80211_MODE_11B); + setbit(&bands, IEEE80211_MODE_11G); + ieee80211_init_channels(ic, NULL, &bands); + + ieee80211_ifattach(ic, sc->sc_bssid); + ic->ic_raw_xmit = urtwn_raw_xmit; + ic->ic_scan_start = urtwn_scan_start; + ic->ic_scan_end = urtwn_scan_end; + ic->ic_set_channel = urtwn_set_channel; + + ic->ic_vap_create = urtwn_vap_create; + ic->ic_vap_delete = urtwn_vap_delete; + ic->ic_update_mcast = urtwn_update_mcast; + + ieee80211_radiotap_attach(ic, &sc->sc_txtap.wt_ihdr, + sizeof(sc->sc_txtap), URTWN_TX_RADIOTAP_PRESENT, + &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap), + URTWN_RX_RADIOTAP_PRESENT); + + if (bootverbose) + ieee80211_announce(ic); + + return (0); + +detach: + urtwn_detach(self); + return (ENXIO); /* failure */ +} + +static int +urtwn_detach(device_t self) +{ + struct urtwn_softc *sc = device_get_softc(self); + struct ifnet *ifp = sc->sc_ifp; + struct ieee80211com *ic = ifp->if_l2com; + + if (!device_is_attached(self)) + return (0); + + urtwn_stop(ifp, 1); + + callout_drain(&sc->sc_watchdog_ch); + + /* stop all USB transfers */ + usbd_transfer_unsetup(sc->sc_xfer, URTWN_N_TRANSFER); + ieee80211_ifdetach(ic); + + urtwn_free_tx_list(sc); + urtwn_free_rx_list(sc); + + if_free(ifp); + mtx_destroy(&sc->sc_mtx); + + return (0); +} + +static void +urtwn_free_tx_list(struct urtwn_softc *sc) +{ + urtwn_free_list(sc, sc->sc_tx, URTWN_TX_LIST_COUNT); +} + +static void +urtwn_free_rx_list(struct urtwn_softc *sc) +{ + urtwn_free_list(sc, sc->sc_rx, URTWN_RX_LIST_COUNT); +} + +static void +urtwn_free_list(struct urtwn_softc *sc, struct urtwn_data data[], int ndata) +{ + int i; + + for (i = 0; i < ndata; i++) { + struct urtwn_data *dp = &data[i]; + + if (dp->buf != NULL) { + free(dp->buf, M_USBDEV); + dp->buf = NULL; + } + if (dp->ni != NULL) { + ieee80211_free_node(dp->ni); + dp->ni = NULL; + } + } +} + +static usb_error_t +urtwn_do_request(struct urtwn_softc *sc, struct usb_device_request *req, + void *data) +{ + usb_error_t err; + int ntries = 10; + + URTWN_ASSERT_LOCKED(sc); + + while (ntries--) { + err = usbd_do_request_flags(sc->sc_udev, &sc->sc_mtx, + req, data, 0, NULL, 250 /* ms */); + if (err == 0) + break; + + DPRINTFN(1, "Control request failed, %s (retrying)\n", + usbd_errstr(err)); + usb_pause_mtx(&sc->sc_mtx, hz / 100); + } + return (err); +} + +static struct ieee80211vap * +urtwn_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], int unit, + enum ieee80211_opmode opmode, int flags, + const uint8_t bssid[IEEE80211_ADDR_LEN], + const uint8_t mac[IEEE80211_ADDR_LEN]) +{ + struct urtwn_vap *uvp; + struct ieee80211vap *vap; + + if (!TAILQ_EMPTY(&ic->ic_vaps)) /* only one at a time */ + return (NULL); + + uvp = (struct urtwn_vap *) malloc(sizeof(struct urtwn_vap), + M_80211_VAP, M_NOWAIT | M_ZERO); + if (uvp == NULL) + return (NULL); + vap = &uvp->vap; + /* enable s/w bmiss handling for sta mode */ + ieee80211_vap_setup(ic, vap, name, unit, opmode, + flags | IEEE80211_CLONE_NOBEACONS, bssid, mac); + + /* override state transition machine */ + uvp->newstate = vap->iv_newstate; + vap->iv_newstate = urtwn_newstate; + + /* complete setup */ + ieee80211_vap_attach(vap, ieee80211_media_change, + ieee80211_media_status); + ic->ic_opmode = opmode; + return (vap); +} + +static void +urtwn_vap_delete(struct ieee80211vap *vap) +{ + struct urtwn_vap *uvp = URTWN_VAP(vap); + + ieee80211_vap_detach(vap); + free(uvp, M_80211_VAP); +} + +static struct mbuf * +urtwn_rx_frame(struct urtwn_softc *sc, uint8_t *buf, int pktlen, int *rssi_p) +{ + struct ifnet *ifp = sc->sc_ifp; + struct ieee80211com *ic = ifp->if_l2com; + struct ieee80211_frame *wh; + struct mbuf *m; + struct r92c_rx_stat *stat; + uint32_t rxdw0, rxdw3; + uint8_t rate; + int8_t rssi = 0; + int infosz; + + /* *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306081602.r58G2WcG014325>