| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | /******************************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-01-07 20:46:42 -06:00
										 |  |  |  * Copyright(c) 2009-2012  Realtek Corporation. All rights reserved. | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify it | 
					
						
							|  |  |  |  * under the terms of version 2 of the GNU General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, but WITHOUT | 
					
						
							|  |  |  |  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for | 
					
						
							|  |  |  |  * more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License along with | 
					
						
							|  |  |  |  * this program; if not, write to the Free Software Foundation, Inc., | 
					
						
							|  |  |  |  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The full GNU General Public License is included in this distribution in the | 
					
						
							|  |  |  |  * file called LICENSE. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contact Information: | 
					
						
							|  |  |  |  * wlanfae <wlanfae@realtek.com> | 
					
						
							|  |  |  |  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, | 
					
						
							|  |  |  |  * Hsinchu 300, Taiwan. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2011-07-20 08:51:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | #include "wifi.h"
 | 
					
						
							| 
									
										
										
										
											2012-01-27 13:59:25 -06:00
										 |  |  | #include "core.h"
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | #include "usb.h"
 | 
					
						
							|  |  |  | #include "base.h"
 | 
					
						
							|  |  |  | #include "ps.h"
 | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:42 -06:00
										 |  |  | #include "rtl8192c/fw_common.h"
 | 
					
						
							| 
									
										
										
										
											2012-01-27 13:59:25 -06:00
										 |  |  | #include <linux/export.h>
 | 
					
						
							| 
									
										
										
										
											2013-07-12 15:32:15 -05:00
										 |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MODULE_AUTHOR("lizhaoming	<chaoming_li@realsil.com.cn>"); | 
					
						
							|  |  |  | MODULE_AUTHOR("Realtek WlanFAE	<wlanfae@realtek.com>"); | 
					
						
							|  |  |  | MODULE_AUTHOR("Larry Finger	<Larry.FInger@lwfinger.net>"); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); | 
					
						
							|  |  |  | MODULE_DESCRIPTION("USB basic driver for rtlwifi"); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define	REALTEK_USB_VENQT_READ			0xC0
 | 
					
						
							|  |  |  | #define	REALTEK_USB_VENQT_WRITE			0x40
 | 
					
						
							|  |  |  | #define REALTEK_USB_VENQT_CMD_REQ		0x05
 | 
					
						
							|  |  |  | #define	REALTEK_USB_VENQT_CMD_IDX		0x00
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:42 -06:00
										 |  |  | #define MAX_USBCTRL_VENDORREQ_TIMES		10
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void usbctrl_async_callback(struct urb *urb) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-02-18 10:29:30 +02:00
										 |  |  | 	if (urb) { | 
					
						
							|  |  |  | 		/* free dr */ | 
					
						
							|  |  |  | 		kfree(urb->setup_packet); | 
					
						
							|  |  |  | 		/* free databuf */ | 
					
						
							|  |  |  | 		kfree(urb->transfer_buffer); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int _usbctrl_vendorreq_async_write(struct usb_device *udev, u8 request, | 
					
						
							|  |  |  | 					  u16 value, u16 index, void *pdata, | 
					
						
							|  |  |  | 					  u16 len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int rc; | 
					
						
							|  |  |  | 	unsigned int pipe; | 
					
						
							|  |  |  | 	u8 reqtype; | 
					
						
							|  |  |  | 	struct usb_ctrlrequest *dr; | 
					
						
							|  |  |  | 	struct urb *urb; | 
					
						
							| 
									
										
										
										
											2013-02-18 10:29:30 +02:00
										 |  |  | 	const u16 databuf_maxlen = REALTEK_USB_VENQT_MAX_BUF_SIZE; | 
					
						
							|  |  |  | 	u8 *databuf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (WARN_ON_ONCE(len > databuf_maxlen)) | 
					
						
							|  |  |  | 		len = databuf_maxlen; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	pipe = usb_sndctrlpipe(udev, 0); /* write_out */ | 
					
						
							|  |  |  | 	reqtype =  REALTEK_USB_VENQT_WRITE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-18 10:29:30 +02:00
										 |  |  | 	dr = kmalloc(sizeof(*dr), GFP_ATOMIC); | 
					
						
							|  |  |  | 	if (!dr) | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-18 10:29:30 +02:00
										 |  |  | 	databuf = kmalloc(databuf_maxlen, GFP_ATOMIC); | 
					
						
							|  |  |  | 	if (!databuf) { | 
					
						
							|  |  |  | 		kfree(dr); | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	urb = usb_alloc_urb(0, GFP_ATOMIC); | 
					
						
							|  |  |  | 	if (!urb) { | 
					
						
							| 
									
										
										
										
											2013-02-18 10:29:30 +02:00
										 |  |  | 		kfree(databuf); | 
					
						
							|  |  |  | 		kfree(dr); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dr->bRequestType = reqtype; | 
					
						
							|  |  |  | 	dr->bRequest = request; | 
					
						
							|  |  |  | 	dr->wValue = cpu_to_le16(value); | 
					
						
							|  |  |  | 	dr->wIndex = cpu_to_le16(index); | 
					
						
							|  |  |  | 	dr->wLength = cpu_to_le16(len); | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 	/* data are already in little-endian order */ | 
					
						
							| 
									
										
										
										
											2013-02-18 10:29:30 +02:00
										 |  |  | 	memcpy(databuf, pdata, len); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	usb_fill_control_urb(urb, udev, pipe, | 
					
						
							| 
									
										
										
										
											2013-02-18 10:29:30 +02:00
										 |  |  | 			     (unsigned char *)dr, databuf, len, | 
					
						
							|  |  |  | 			     usbctrl_async_callback, NULL); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	rc = usb_submit_urb(urb, GFP_ATOMIC); | 
					
						
							| 
									
										
										
										
											2013-02-18 10:29:30 +02:00
										 |  |  | 	if (rc < 0) { | 
					
						
							|  |  |  | 		kfree(databuf); | 
					
						
							|  |  |  | 		kfree(dr); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	usb_free_urb(urb); | 
					
						
							|  |  |  | 	return rc; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int _usbctrl_vendorreq_sync_read(struct usb_device *udev, u8 request, | 
					
						
							|  |  |  | 					u16 value, u16 index, void *pdata, | 
					
						
							|  |  |  | 					u16 len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned int pipe; | 
					
						
							|  |  |  | 	int status; | 
					
						
							|  |  |  | 	u8 reqtype; | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:42 -06:00
										 |  |  | 	int vendorreq_times = 0; | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 	static int count; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	pipe = usb_rcvctrlpipe(udev, 0); /* read_in */ | 
					
						
							|  |  |  | 	reqtype =  REALTEK_USB_VENQT_READ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-21 16:37:26 -05:00
										 |  |  | 	do { | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:42 -06:00
										 |  |  | 		status = usb_control_msg(udev, pipe, request, reqtype, value, | 
					
						
							|  |  |  | 					 index, pdata, len, 0); /*max. timeout*/ | 
					
						
							|  |  |  | 		if (status < 0) { | 
					
						
							|  |  |  | 			/* firmware download is checksumed, don't retry */ | 
					
						
							|  |  |  | 			if ((value >= FW_8192C_START_ADDRESS && | 
					
						
							|  |  |  | 			    value <= FW_8192C_END_ADDRESS)) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-11-21 16:37:26 -05:00
										 |  |  | 	} while (++vendorreq_times < MAX_USBCTRL_VENDORREQ_TIMES); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 	if (status < 0 && count++ < 4) | 
					
						
							| 
									
										
										
										
											2011-07-20 08:51:35 -07:00
										 |  |  | 		pr_err("reg 0x%x, usbctrl_vendorreq TimeOut! status:0x%x value=0x%x\n", | 
					
						
							| 
									
										
										
										
											2012-08-31 15:39:00 -05:00
										 |  |  | 		       value, status, *(u32 *)pdata); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-19 15:44:31 -05:00
										 |  |  | static u32 _usb_read_sync(struct rtl_priv *rtlpriv, u32 addr, u16 len) | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-19 15:44:31 -05:00
										 |  |  | 	struct device *dev = rtlpriv->io.dev; | 
					
						
							|  |  |  | 	struct usb_device *udev = to_usb_device(dev); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	u8 request; | 
					
						
							|  |  |  | 	u16 wvalue; | 
					
						
							|  |  |  | 	u16 index; | 
					
						
							| 
									
										
										
										
											2012-07-11 14:37:28 -05:00
										 |  |  | 	__le32 *data; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-11 14:37:28 -05:00
										 |  |  | 	spin_lock_irqsave(&rtlpriv->locks.usb_lock, flags); | 
					
						
							|  |  |  | 	if (++rtlpriv->usb_data_index >= RTL_USB_MAX_RX_COUNT) | 
					
						
							|  |  |  | 		rtlpriv->usb_data_index = 0; | 
					
						
							|  |  |  | 	data = &rtlpriv->usb_data[rtlpriv->usb_data_index]; | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&rtlpriv->locks.usb_lock, flags); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	request = REALTEK_USB_VENQT_CMD_REQ; | 
					
						
							|  |  |  | 	index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wvalue = (u16)addr; | 
					
						
							|  |  |  | 	_usbctrl_vendorreq_sync_read(udev, request, wvalue, index, data, len); | 
					
						
							| 
									
										
										
										
											2012-03-19 15:44:31 -05:00
										 |  |  | 	return le32_to_cpu(*data); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u8 _usb_read8_sync(struct rtl_priv *rtlpriv, u32 addr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-19 15:44:31 -05:00
										 |  |  | 	return (u8)_usb_read_sync(rtlpriv, addr, 1); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u16 _usb_read16_sync(struct rtl_priv *rtlpriv, u32 addr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-19 15:44:31 -05:00
										 |  |  | 	return (u16)_usb_read_sync(rtlpriv, addr, 2); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u32 _usb_read32_sync(struct rtl_priv *rtlpriv, u32 addr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-19 15:44:31 -05:00
										 |  |  | 	return _usb_read_sync(rtlpriv, addr, 4); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _usb_write_async(struct usb_device *udev, u32 addr, u32 val, | 
					
						
							|  |  |  | 			     u16 len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8 request; | 
					
						
							|  |  |  | 	u16 wvalue; | 
					
						
							|  |  |  | 	u16 index; | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 	__le32 data; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	request = REALTEK_USB_VENQT_CMD_REQ; | 
					
						
							|  |  |  | 	index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */ | 
					
						
							|  |  |  | 	wvalue = (u16)(addr&0x0000ffff); | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 	data = cpu_to_le32(val); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	_usbctrl_vendorreq_async_write(udev, request, wvalue, index, &data, | 
					
						
							|  |  |  | 				       len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _usb_write8_async(struct rtl_priv *rtlpriv, u32 addr, u8 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device *dev = rtlpriv->io.dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_usb_write_async(to_usb_device(dev), addr, val, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _usb_write16_async(struct rtl_priv *rtlpriv, u32 addr, u16 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device *dev = rtlpriv->io.dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_usb_write_async(to_usb_device(dev), addr, val, 2); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _usb_write32_async(struct rtl_priv *rtlpriv, u32 addr, u32 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device *dev = rtlpriv->io.dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_usb_write_async(to_usb_device(dev), addr, val, 4); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:43 -06:00
										 |  |  | static void _usb_writeN_sync(struct rtl_priv *rtlpriv, u32 addr, void *data, | 
					
						
							|  |  |  | 			     u16 len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device *dev = rtlpriv->io.dev; | 
					
						
							|  |  |  | 	struct usb_device *udev = to_usb_device(dev); | 
					
						
							|  |  |  | 	u8 request = REALTEK_USB_VENQT_CMD_REQ; | 
					
						
							|  |  |  | 	u8 reqtype =  REALTEK_USB_VENQT_WRITE; | 
					
						
							|  |  |  | 	u16 wvalue; | 
					
						
							|  |  |  | 	u16 index = REALTEK_USB_VENQT_CMD_IDX; | 
					
						
							|  |  |  | 	int pipe = usb_sndctrlpipe(udev, 0); /* write_out */ | 
					
						
							|  |  |  | 	u8 *buffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 16:24:43 +02:00
										 |  |  | 	wvalue = (u16)(addr & 0x0000ffff); | 
					
						
							| 
									
										
										
										
											2013-03-10 15:09:47 +02:00
										 |  |  | 	buffer = kmemdup(data, len, GFP_ATOMIC); | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:43 -06:00
										 |  |  | 	if (!buffer) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	usb_control_msg(udev, pipe, request, reqtype, wvalue, | 
					
						
							|  |  |  | 			index, buffer, len, 50); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-20 16:24:43 +02:00
										 |  |  | 	kfree(buffer); | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:43 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | static void _rtl_usb_io_handler_init(struct device *dev, | 
					
						
							|  |  |  | 				     struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlpriv->io.dev = dev; | 
					
						
							|  |  |  | 	mutex_init(&rtlpriv->io.bb_mutex); | 
					
						
							|  |  |  | 	rtlpriv->io.write8_async	= _usb_write8_async; | 
					
						
							|  |  |  | 	rtlpriv->io.write16_async	= _usb_write16_async; | 
					
						
							|  |  |  | 	rtlpriv->io.write32_async	= _usb_write32_async; | 
					
						
							|  |  |  | 	rtlpriv->io.read8_sync		= _usb_read8_sync; | 
					
						
							|  |  |  | 	rtlpriv->io.read16_sync		= _usb_read16_sync; | 
					
						
							|  |  |  | 	rtlpriv->io.read32_sync		= _usb_read32_sync; | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:43 -06:00
										 |  |  | 	rtlpriv->io.writeN_sync		= _usb_writeN_sync; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_usb_io_handler_release(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-02 18:10:22 -05:00
										 |  |  | 	struct rtl_priv __maybe_unused *rtlpriv = rtl_priv(hw); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mutex_destroy(&rtlpriv->io.bb_mutex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *	Default aggregation handler. Do nothing and just return the oldest skb. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static struct sk_buff *_none_usb_tx_aggregate_hdl(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 						  struct sk_buff_head *list) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return skb_dequeue(list); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define IS_HIGH_SPEED_USB(udev) \
 | 
					
						
							|  |  |  | 		((USB_SPEED_HIGH == (udev)->speed) ? true : false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int _rtl_usb_init_tx(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 i; | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlusb->max_bulk_out_size = IS_HIGH_SPEED_USB(rtlusb->udev) | 
					
						
							|  |  |  | 						    ? USB_HIGH_SPEED_BULK_SIZE | 
					
						
							|  |  |  | 						    : USB_FULL_SPEED_BULK_SIZE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "USB Max Bulk-out Size=%d\n", | 
					
						
							|  |  |  | 		 rtlusb->max_bulk_out_size); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < __RTL_TXQ_NUM; i++) { | 
					
						
							|  |  |  | 		u32 ep_num = rtlusb->ep_map.ep_mapping[i]; | 
					
						
							|  |  |  | 		if (!ep_num) { | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "Invalid endpoint map setting!\n"); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlusb->usb_tx_post_hdl = | 
					
						
							|  |  |  | 		 rtlpriv->cfg->usb_interface_cfg->usb_tx_post_hdl; | 
					
						
							|  |  |  | 	rtlusb->usb_tx_cleanup	= | 
					
						
							|  |  |  | 		 rtlpriv->cfg->usb_interface_cfg->usb_tx_cleanup; | 
					
						
							|  |  |  | 	rtlusb->usb_tx_aggregate_hdl = | 
					
						
							|  |  |  | 		 (rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl) | 
					
						
							|  |  |  | 		 ? rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl | 
					
						
							|  |  |  | 		 : &_none_usb_tx_aggregate_hdl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	init_usb_anchor(&rtlusb->tx_submitted); | 
					
						
							|  |  |  | 	for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) { | 
					
						
							|  |  |  | 		skb_queue_head_init(&rtlusb->tx_skb_queue[i]); | 
					
						
							|  |  |  | 		init_usb_anchor(&rtlusb->tx_pending[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:24 +02:00
										 |  |  | static void _rtl_rx_work(unsigned long param); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | static int _rtl_usb_init_rx(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(usb_priv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlusb->rx_max_size = rtlpriv->cfg->usb_interface_cfg->rx_max_size; | 
					
						
							|  |  |  | 	rtlusb->rx_urb_num = rtlpriv->cfg->usb_interface_cfg->rx_urb_num; | 
					
						
							|  |  |  | 	rtlusb->in_ep = rtlpriv->cfg->usb_interface_cfg->in_ep_num; | 
					
						
							|  |  |  | 	rtlusb->usb_rx_hdl = rtlpriv->cfg->usb_interface_cfg->usb_rx_hdl; | 
					
						
							|  |  |  | 	rtlusb->usb_rx_segregate_hdl = | 
					
						
							|  |  |  | 		rtlpriv->cfg->usb_interface_cfg->usb_rx_segregate_hdl; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-20 08:51:35 -07:00
										 |  |  | 	pr_info("rx_max_size %d, rx_urb_num %d, in_ep %d\n", | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		rtlusb->rx_max_size, rtlusb->rx_urb_num, rtlusb->in_ep); | 
					
						
							|  |  |  | 	init_usb_anchor(&rtlusb->rx_submitted); | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 	init_usb_anchor(&rtlusb->rx_cleanup_urbs); | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	skb_queue_head_init(&rtlusb->rx_queue); | 
					
						
							|  |  |  | 	rtlusb->rx_work_tasklet.func = _rtl_rx_work; | 
					
						
							|  |  |  | 	rtlusb->rx_work_tasklet.data = (unsigned long)rtlusb; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int _rtl_usb_init(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(usb_priv); | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 	u8 epidx; | 
					
						
							|  |  |  | 	struct usb_interface	*usb_intf = rtlusb->intf; | 
					
						
							|  |  |  | 	u8 epnums = usb_intf->cur_altsetting->desc.bNumEndpoints; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlusb->out_ep_nums = rtlusb->in_ep_nums = 0; | 
					
						
							|  |  |  | 	for (epidx = 0; epidx < epnums; epidx++) { | 
					
						
							|  |  |  | 		struct usb_endpoint_descriptor *pep_desc; | 
					
						
							|  |  |  | 		pep_desc = &usb_intf->cur_altsetting->endpoint[epidx].desc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (usb_endpoint_dir_in(pep_desc)) | 
					
						
							|  |  |  | 			rtlusb->in_ep_nums++; | 
					
						
							|  |  |  | 		else if (usb_endpoint_dir_out(pep_desc)) | 
					
						
							|  |  |  | 			rtlusb->out_ep_nums++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "USB EP(0x%02x), MaxPacketSize=%d, Interval=%d\n", | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 			 pep_desc->bEndpointAddress, pep_desc->wMaxPacketSize, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 pep_desc->bInterval); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-02 13:21:22 -06:00
										 |  |  | 	if (rtlusb->in_ep_nums <  rtlpriv->cfg->usb_interface_cfg->in_ep_num) { | 
					
						
							|  |  |  | 		pr_err("Too few input end points found\n"); | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (rtlusb->out_ep_nums == 0) { | 
					
						
							|  |  |  | 		pr_err("No output end points found\n"); | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	/* usb endpoint mapping */ | 
					
						
							|  |  |  | 	err = rtlpriv->cfg->usb_interface_cfg->usb_endpoint_mapping(hw); | 
					
						
							|  |  |  | 	rtlusb->usb_mq_to_hwq =  rtlpriv->cfg->usb_interface_cfg->usb_mq_to_hwq; | 
					
						
							|  |  |  | 	_rtl_usb_init_tx(hw); | 
					
						
							|  |  |  | 	_rtl_usb_init_rx(hw); | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 13:22:46 -06:00
										 |  |  | static void rtl_usb_init_sw(struct ieee80211_hw *hw) | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlhal->hw = hw; | 
					
						
							| 
									
										
										
										
											2011-02-19 16:28:57 -06:00
										 |  |  | 	ppsc->inactiveps = false; | 
					
						
							|  |  |  | 	ppsc->leisure_ps = false; | 
					
						
							|  |  |  | 	ppsc->fwctrl_lps = false; | 
					
						
							|  |  |  | 	ppsc->reg_fwctrl_lps = 3; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	ppsc->reg_max_lps_awakeintvl = 5; | 
					
						
							|  |  |  | 	ppsc->fwctrl_psmode = FW_PS_DTIM_MODE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	 /* IBSS */ | 
					
						
							|  |  |  | 	mac->beacon_interval = 100; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	 /* AMPDU */ | 
					
						
							|  |  |  | 	mac->min_space_cfg = 0; | 
					
						
							|  |  |  | 	mac->max_mss_density = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* set sane AMPDU defaults */ | 
					
						
							|  |  |  | 	mac->current_ampdu_density = 7; | 
					
						
							|  |  |  | 	mac->current_ampdu_factor = 3; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* QOS */ | 
					
						
							|  |  |  | 	rtlusb->acm_method = eAcmWay2_SW; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* IRQ */ | 
					
						
							|  |  |  | 	/* HIMR - turn all on */ | 
					
						
							|  |  |  | 	rtlusb->irq_mask[0] = 0xFFFFFFFF; | 
					
						
							|  |  |  | 	/* HIMR_EX - turn all on */ | 
					
						
							|  |  |  | 	rtlusb->irq_mask[1] = 0xFFFFFFFF; | 
					
						
							|  |  |  | 	rtlusb->disableHWSM =  true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_rx_completed(struct urb *urb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | static int _rtl_prep_rx_urb(struct ieee80211_hw *hw, struct rtl_usb *rtlusb, | 
					
						
							|  |  |  | 			      struct urb *urb, gfp_t gfp_mask) | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 	void *buf; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 	buf = usb_alloc_coherent(rtlusb->udev, rtlusb->rx_max_size, gfp_mask, | 
					
						
							|  |  |  | 				 &urb->transfer_dma); | 
					
						
							|  |  |  | 	if (!buf) { | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 			 "Failed to usb_alloc_coherent!!\n"); | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	usb_fill_bulk_urb(urb, rtlusb->udev, | 
					
						
							|  |  |  | 			  usb_rcvbulkpipe(rtlusb->udev, rtlusb->in_ep), | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 			  buf, rtlusb->rx_max_size, _rtl_rx_completed, rtlusb); | 
					
						
							|  |  |  | 	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_usb_rx_process_agg(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				    struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	u8 *rxdesc = skb->data; | 
					
						
							|  |  |  | 	struct ieee80211_hdr *hdr; | 
					
						
							|  |  |  | 	bool unicast = false; | 
					
						
							| 
									
										
										
										
											2011-02-19 16:29:57 -06:00
										 |  |  | 	__le16 fc; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	struct ieee80211_rx_status rx_status = {0}; | 
					
						
							|  |  |  | 	struct rtl_stats stats = { | 
					
						
							|  |  |  | 		.signal = 0, | 
					
						
							|  |  |  | 		.rate = 0, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb_pull(skb, RTL_RX_DESC_SIZE); | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb); | 
					
						
							|  |  |  | 	skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift)); | 
					
						
							|  |  |  | 	hdr = (struct ieee80211_hdr *)(skb->data); | 
					
						
							| 
									
										
										
										
											2011-02-19 16:29:57 -06:00
										 |  |  | 	fc = hdr->frame_control; | 
					
						
							| 
									
										
										
										
											2011-02-19 16:28:57 -06:00
										 |  |  | 	if (!stats.crc) { | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (is_broadcast_ether_addr(hdr->addr1)) { | 
					
						
							|  |  |  | 			/*TODO*/; | 
					
						
							|  |  |  | 		} else if (is_multicast_ether_addr(hdr->addr1)) { | 
					
						
							|  |  |  | 			/*TODO*/ | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			unicast = true; | 
					
						
							|  |  |  | 			rtlpriv->stats.rxbytesunicast +=  skb->len; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ieee80211_is_data(fc)) { | 
					
						
							|  |  |  | 			rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (unicast) | 
					
						
							|  |  |  | 				rtlpriv->link_info.num_rx_inperiod++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-11-18 11:11:31 -06:00
										 |  |  | 		/* static bcn for roaming */ | 
					
						
							|  |  |  | 		rtl_beacon_statistic(hw, skb); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_usb_rx_process_noagg(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				      struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	u8 *rxdesc = skb->data; | 
					
						
							|  |  |  | 	struct ieee80211_hdr *hdr; | 
					
						
							|  |  |  | 	bool unicast = false; | 
					
						
							| 
									
										
										
										
											2011-02-19 16:29:57 -06:00
										 |  |  | 	__le16 fc; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	struct ieee80211_rx_status rx_status = {0}; | 
					
						
							|  |  |  | 	struct rtl_stats stats = { | 
					
						
							|  |  |  | 		.signal = 0, | 
					
						
							|  |  |  | 		.rate = 0, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb_pull(skb, RTL_RX_DESC_SIZE); | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb); | 
					
						
							|  |  |  | 	skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift)); | 
					
						
							|  |  |  | 	hdr = (struct ieee80211_hdr *)(skb->data); | 
					
						
							| 
									
										
										
										
											2011-02-19 16:29:57 -06:00
										 |  |  | 	fc = hdr->frame_control; | 
					
						
							| 
									
										
										
										
											2011-02-19 16:28:57 -06:00
										 |  |  | 	if (!stats.crc) { | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (is_broadcast_ether_addr(hdr->addr1)) { | 
					
						
							|  |  |  | 			/*TODO*/; | 
					
						
							|  |  |  | 		} else if (is_multicast_ether_addr(hdr->addr1)) { | 
					
						
							|  |  |  | 			/*TODO*/ | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			unicast = true; | 
					
						
							|  |  |  | 			rtlpriv->stats.rxbytesunicast +=  skb->len; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ieee80211_is_data(fc)) { | 
					
						
							|  |  |  | 			rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (unicast) | 
					
						
							|  |  |  | 				rtlpriv->link_info.num_rx_inperiod++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 09:50:28 -05:00
										 |  |  | 		/* static bcn for roaming */ | 
					
						
							|  |  |  | 		rtl_beacon_statistic(hw, skb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:18 +02:00
										 |  |  | 		if (likely(rtl_action_proc(hw, skb, false))) | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:24 +02:00
										 |  |  | 			ieee80211_rx(hw, skb); | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:18 +02:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 			dev_kfree_skb_any(skb); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_rx_pre_process(struct ieee80211_hw *hw, struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *_skb; | 
					
						
							|  |  |  | 	struct sk_buff_head rx_queue; | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb_queue_head_init(&rx_queue); | 
					
						
							|  |  |  | 	if (rtlusb->usb_rx_segregate_hdl) | 
					
						
							|  |  |  | 		rtlusb->usb_rx_segregate_hdl(hw, skb, &rx_queue); | 
					
						
							|  |  |  | 	WARN_ON(skb_queue_empty(&rx_queue)); | 
					
						
							|  |  |  | 	while (!skb_queue_empty(&rx_queue)) { | 
					
						
							|  |  |  | 		_skb = skb_dequeue(&rx_queue); | 
					
						
							| 
									
										
										
										
											2013-01-27 16:24:25 -06:00
										 |  |  | 		_rtl_usb_rx_process_agg(hw, _skb); | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:24 +02:00
										 |  |  | 		ieee80211_rx(hw, _skb); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-18 11:11:30 -06:00
										 |  |  | #define __RX_SKB_MAX_QUEUED	64
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_rx_work(unsigned long param) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = (struct rtl_usb *)param; | 
					
						
							|  |  |  | 	struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf); | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while ((skb = skb_dequeue(&rtlusb->rx_queue))) { | 
					
						
							|  |  |  | 		if (unlikely(IS_USB_STOP(rtlusb))) { | 
					
						
							|  |  |  | 			dev_kfree_skb_any(skb); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (likely(!rtlusb->usb_rx_segregate_hdl)) { | 
					
						
							|  |  |  | 			_rtl_usb_rx_process_noagg(hw, skb); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			/* TO DO */ | 
					
						
							|  |  |  | 			_rtl_rx_pre_process(hw, skb); | 
					
						
							|  |  |  | 			pr_err("rx agg not supported\n"); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:29 +02:00
										 |  |  | static unsigned int _rtl_rx_get_padding(struct ieee80211_hdr *hdr, | 
					
						
							|  |  |  | 					unsigned int len) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-25 12:57:47 -05:00
										 |  |  | #if NET_IP_ALIGN != 0
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:29 +02:00
										 |  |  | 	unsigned int padding = 0; | 
					
						
							| 
									
										
										
										
											2013-09-25 12:57:47 -05:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* make function no-op when possible */ | 
					
						
							|  |  |  | 	if (NET_IP_ALIGN == 0 || len < sizeof(*hdr)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 12:57:47 -05:00
										 |  |  | #if NET_IP_ALIGN != 0
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:29 +02:00
										 |  |  | 	/* alignment calculation as in lbtf_rx() / carl9170_rx_copy_data() */ | 
					
						
							|  |  |  | 	/* TODO: deduplicate common code, define helper function instead? */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ieee80211_is_data_qos(hdr->frame_control)) { | 
					
						
							|  |  |  | 		u8 *qc = ieee80211_get_qos_ctl(hdr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		padding ^= NET_IP_ALIGN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Input might be invalid, avoid accessing memory outside
 | 
					
						
							|  |  |  | 		 * the buffer. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if ((unsigned long)qc - (unsigned long)hdr < len && | 
					
						
							|  |  |  | 		    *qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT) | 
					
						
							|  |  |  | 			padding ^= NET_IP_ALIGN; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ieee80211_has_a4(hdr->frame_control)) | 
					
						
							|  |  |  | 		padding ^= NET_IP_ALIGN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return padding; | 
					
						
							| 
									
										
										
										
											2013-09-25 12:57:47 -05:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | #define __RADIO_TAP_SIZE_RSV	32
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | static void _rtl_rx_completed(struct urb *_urb) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 	struct rtl_usb *rtlusb = (struct rtl_usb *)_urb->context; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf); | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	int err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(IS_USB_STOP(rtlusb))) | 
					
						
							|  |  |  | 		goto free; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (likely(0 == _urb->status)) { | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:29 +02:00
										 |  |  | 		unsigned int padding; | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 		struct sk_buff *skb; | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:24 +02:00
										 |  |  | 		unsigned int qlen; | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 		unsigned int size = _urb->actual_length; | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:29 +02:00
										 |  |  | 		struct ieee80211_hdr *hdr; | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (size < RTL_RX_DESC_SIZE + sizeof(struct ieee80211_hdr)) { | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							|  |  |  | 				 "Too short packet from bulk IN! (len: %d)\n", | 
					
						
							|  |  |  | 				 size); | 
					
						
							|  |  |  | 			goto resubmit; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:24 +02:00
										 |  |  | 		qlen = skb_queue_len(&rtlusb->rx_queue); | 
					
						
							|  |  |  | 		if (qlen >= __RX_SKB_MAX_QUEUED) { | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							|  |  |  | 				 "Pending RX skbuff queue full! (qlen: %d)\n", | 
					
						
							|  |  |  | 				 qlen); | 
					
						
							|  |  |  | 			goto resubmit; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:29 +02:00
										 |  |  | 		hdr = (void *)(_urb->transfer_buffer + RTL_RX_DESC_SIZE); | 
					
						
							|  |  |  | 		padding = _rtl_rx_get_padding(hdr, size - RTL_RX_DESC_SIZE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		skb = dev_alloc_skb(size + __RADIO_TAP_SIZE_RSV + padding); | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 		if (!skb) { | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							|  |  |  | 				 "Can't allocate skb for bulk IN!\n"); | 
					
						
							|  |  |  | 			goto resubmit; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		_rtl_install_trx_info(rtlusb, skb, rtlusb->in_ep); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:29 +02:00
										 |  |  | 		/* Make sure the payload data is 4 byte aligned. */ | 
					
						
							|  |  |  | 		skb_reserve(skb, padding); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 		/* reserve some space for mac80211's radiotap */ | 
					
						
							|  |  |  | 		skb_reserve(skb, __RADIO_TAP_SIZE_RSV); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		memcpy(skb_put(skb, size), _urb->transfer_buffer, size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:24 +02:00
										 |  |  | 		skb_queue_tail(&rtlusb->rx_queue, skb); | 
					
						
							|  |  |  | 		tasklet_schedule(&rtlusb->rx_work_tasklet); | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		goto resubmit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (_urb->status) { | 
					
						
							|  |  |  | 	/* disconnect */ | 
					
						
							|  |  |  | 	case -ENOENT: | 
					
						
							|  |  |  | 	case -ECONNRESET: | 
					
						
							|  |  |  | 	case -ENODEV: | 
					
						
							|  |  |  | 	case -ESHUTDOWN: | 
					
						
							|  |  |  | 		goto free; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | resubmit: | 
					
						
							|  |  |  | 	usb_anchor_urb(_urb, &rtlusb->rx_submitted); | 
					
						
							|  |  |  | 	err = usb_submit_urb(_urb, GFP_ATOMIC); | 
					
						
							|  |  |  | 	if (unlikely(err)) { | 
					
						
							|  |  |  | 		usb_unanchor_urb(_urb); | 
					
						
							|  |  |  | 		goto free; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | free: | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 	/* On some architectures, usb_free_coherent must not be called from
 | 
					
						
							|  |  |  | 	 * hardirq context. Queue urb to cleanup list. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	usb_anchor_urb(_urb, &rtlusb->rx_cleanup_urbs); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef __RADIO_TAP_SIZE_RSV
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_usb_cleanup_rx(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 	struct urb *urb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	usb_kill_anchored_urbs(&rtlusb->rx_submitted); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:24 +02:00
										 |  |  | 	tasklet_kill(&rtlusb->rx_work_tasklet); | 
					
						
							|  |  |  | 	skb_queue_purge(&rtlusb->rx_queue); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 	while ((urb = usb_get_from_anchor(&rtlusb->rx_cleanup_urbs))) { | 
					
						
							|  |  |  | 		usb_free_coherent(urb->dev, urb->transfer_buffer_length, | 
					
						
							|  |  |  | 				urb->transfer_buffer, urb->transfer_dma); | 
					
						
							|  |  |  | 		usb_free_urb(urb); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int _rtl_usb_receive(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct urb *urb; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WARN_ON(0 == rtlusb->rx_urb_num); | 
					
						
							|  |  |  | 	/* 1600 == 1514 + max WLAN header + rtk info */ | 
					
						
							|  |  |  | 	WARN_ON(rtlusb->rx_max_size < 1600); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < rtlusb->rx_urb_num; i++) { | 
					
						
							|  |  |  | 		err = -ENOMEM; | 
					
						
							|  |  |  | 		urb = usb_alloc_urb(0, GFP_KERNEL); | 
					
						
							|  |  |  | 		if (!urb) { | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "Failed to alloc URB!!\n"); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 			goto err_out; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 		err = _rtl_prep_rx_urb(hw, rtlusb, urb, GFP_KERNEL); | 
					
						
							|  |  |  | 		if (err < 0) { | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 			RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "Failed to prep_rx_urb!!\n"); | 
					
						
							| 
									
										
										
										
											2012-12-26 21:51:12 +01:00
										 |  |  | 			usb_free_urb(urb); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 			goto err_out; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		usb_anchor_urb(urb, &rtlusb->rx_submitted); | 
					
						
							|  |  |  | 		err = usb_submit_urb(urb, GFP_KERNEL); | 
					
						
							|  |  |  | 		if (err) | 
					
						
							|  |  |  | 			goto err_out; | 
					
						
							|  |  |  | 		usb_free_urb(urb); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err_out: | 
					
						
							|  |  |  | 	usb_kill_anchored_urbs(&rtlusb->rx_submitted); | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 	_rtl_usb_cleanup_rx(hw); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int rtl_usb_start(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = rtlpriv->cfg->ops->hw_init(hw); | 
					
						
							| 
									
										
										
										
											2012-01-30 09:54:49 -06:00
										 |  |  | 	if (!err) { | 
					
						
							|  |  |  | 		rtl_init_rx_config(hw); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-30 09:54:49 -06:00
										 |  |  | 		/* Enable software */ | 
					
						
							|  |  |  | 		SET_USB_START(rtlusb); | 
					
						
							|  |  |  | 		/* should after adapter start and interrupt enable. */ | 
					
						
							|  |  |  | 		set_hal_start(rtlhal); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-30 09:54:49 -06:00
										 |  |  | 		/* Start bulk IN */ | 
					
						
							| 
									
										
										
										
											2012-10-14 22:15:48 +02:00
										 |  |  | 		err = _rtl_usb_receive(hw); | 
					
						
							| 
									
										
										
										
											2012-01-30 09:54:49 -06:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*=======================  tx =========================================*/ | 
					
						
							|  |  |  | static void rtl_usb_cleanup(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 i; | 
					
						
							|  |  |  | 	struct sk_buff *_skb; | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 	struct ieee80211_tx_info *txinfo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SET_USB_STOP(rtlusb); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* clean up rx stuff. */ | 
					
						
							| 
									
										
										
										
											2013-03-17 11:59:13 +02:00
										 |  |  | 	_rtl_usb_cleanup_rx(hw); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* clean up tx stuff */ | 
					
						
							|  |  |  | 	for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) { | 
					
						
							|  |  |  | 		while ((_skb = skb_dequeue(&rtlusb->tx_skb_queue[i]))) { | 
					
						
							|  |  |  | 			rtlusb->usb_tx_cleanup(hw, _skb); | 
					
						
							|  |  |  | 			txinfo = IEEE80211_SKB_CB(_skb); | 
					
						
							|  |  |  | 			ieee80211_tx_info_clear_status(txinfo); | 
					
						
							|  |  |  | 			txinfo->flags |= IEEE80211_TX_STAT_ACK; | 
					
						
							|  |  |  | 			ieee80211_tx_status_irqsafe(hw, _skb); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		usb_kill_anchored_urbs(&rtlusb->tx_pending[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	usb_kill_anchored_urbs(&rtlusb->tx_submitted); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * We may add some struct into struct rtl_usb later. Do deinit here. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void rtl_usb_deinit(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	rtl_usb_cleanup(hw); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void rtl_usb_stop(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* should after adapter start and interrupt enable. */ | 
					
						
							|  |  |  | 	set_hal_stop(rtlhal); | 
					
						
							| 
									
										
										
										
											2013-05-30 18:05:55 -05:00
										 |  |  | 	cancel_work_sync(&rtlpriv->works.fill_h2c_cmd); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	/* Enable software */ | 
					
						
							|  |  |  | 	SET_USB_STOP(rtlusb); | 
					
						
							|  |  |  | 	rtl_usb_deinit(hw); | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->hw_disable(hw); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_submit_tx_urb(struct ieee80211_hw *hw, struct urb *_urb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	usb_anchor_urb(_urb, &rtlusb->tx_submitted); | 
					
						
							|  |  |  | 	err = usb_submit_urb(_urb, GFP_ATOMIC); | 
					
						
							|  |  |  | 	if (err < 0) { | 
					
						
							|  |  |  | 		struct sk_buff *skb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Failed to submit urb\n"); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		usb_unanchor_urb(_urb); | 
					
						
							|  |  |  | 		skb = (struct sk_buff *)_urb->context; | 
					
						
							|  |  |  | 		kfree_skb(skb); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	usb_free_urb(_urb); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int _usb_tx_post(struct ieee80211_hw *hw, struct urb *urb, | 
					
						
							|  |  |  | 			struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 	struct ieee80211_tx_info *txinfo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlusb->usb_tx_post_hdl(hw, urb, skb); | 
					
						
							|  |  |  | 	skb_pull(skb, RTL_TX_HEADER_SIZE); | 
					
						
							|  |  |  | 	txinfo = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 	ieee80211_tx_info_clear_status(txinfo); | 
					
						
							|  |  |  | 	txinfo->flags |= IEEE80211_TX_STAT_ACK; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (urb->status) { | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Urb has error status 0x%X\n", urb->status); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		goto out; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/*  TODO:	statistics */ | 
					
						
							|  |  |  | out: | 
					
						
							|  |  |  | 	ieee80211_tx_status_irqsafe(hw, skb); | 
					
						
							|  |  |  | 	return urb->status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_tx_complete(struct urb *urb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb = (struct sk_buff *)urb->context; | 
					
						
							|  |  |  | 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = (struct rtl_usb *)info->rate_driver_data[0]; | 
					
						
							|  |  |  | 	struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf); | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(IS_USB_STOP(rtlusb))) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	err = _usb_tx_post(hw, urb, skb); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		/* Ignore error and keep issuiing other urbs */ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct urb *_rtl_usb_tx_urb_setup(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				struct sk_buff *skb, u32 ep_num) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 	struct urb *_urb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WARN_ON(NULL == skb); | 
					
						
							|  |  |  | 	_urb = usb_alloc_urb(0, GFP_ATOMIC); | 
					
						
							|  |  |  | 	if (!_urb) { | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Can't allocate URB for bulk out!\n"); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		kfree_skb(skb); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	_rtl_install_trx_info(rtlusb, skb, ep_num); | 
					
						
							|  |  |  | 	usb_fill_bulk_urb(_urb, rtlusb->udev, usb_sndbulkpipe(rtlusb->udev, | 
					
						
							|  |  |  | 			  ep_num), skb->data, skb->len, _rtl_tx_complete, skb); | 
					
						
							|  |  |  | 	_urb->transfer_flags |= URB_ZERO_PACKET; | 
					
						
							|  |  |  | 	return _urb; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl_usb_transmit(struct ieee80211_hw *hw, struct sk_buff *skb, | 
					
						
							|  |  |  | 		       enum rtl_txq qnum) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 	u32 ep_num; | 
					
						
							|  |  |  | 	struct urb *_urb = NULL; | 
					
						
							|  |  |  | 	struct sk_buff *_skb = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WARN_ON(NULL == rtlusb->usb_tx_aggregate_hdl); | 
					
						
							|  |  |  | 	if (unlikely(IS_USB_STOP(rtlusb))) { | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "USB device is stopping...\n"); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		kfree_skb(skb); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ep_num = rtlusb->ep_map.ep_mapping[qnum]; | 
					
						
							|  |  |  | 	_skb = skb; | 
					
						
							|  |  |  | 	_urb = _rtl_usb_tx_urb_setup(hw, _skb, ep_num); | 
					
						
							|  |  |  | 	if (unlikely(!_urb)) { | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Can't allocate urb. Drop skb!\n"); | 
					
						
							| 
									
										
										
										
											2013-03-17 11:54:04 +02:00
										 |  |  | 		kfree_skb(skb); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	_rtl_submit_tx_urb(hw, _urb); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-23 21:33:42 +02:00
										 |  |  | static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				   struct ieee80211_sta *sta, | 
					
						
							|  |  |  | 				   struct sk_buff *skb, | 
					
						
							|  |  |  | 				   u16 hw_queue) | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | 
					
						
							|  |  |  | 	struct rtl_tx_desc *pdesc = NULL; | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:29 -05:00
										 |  |  | 	struct rtl_tcb_desc tcb_desc; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); | 
					
						
							| 
									
										
										
										
											2011-02-19 16:29:57 -06:00
										 |  |  | 	__le16 fc = hdr->frame_control; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	u8 *pda_addr = hdr->addr1; | 
					
						
							|  |  |  | 	/* ssn */ | 
					
						
							|  |  |  | 	u8 *qc = NULL; | 
					
						
							|  |  |  | 	u8 tid = 0; | 
					
						
							|  |  |  | 	u16 seq_number = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-22 22:59:02 -05:00
										 |  |  | 	memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:29 -05:00
										 |  |  | 	if (ieee80211_is_auth(fc)) { | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 		RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n"); | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:29 -05:00
										 |  |  | 		rtl_ips_nic_on(hw); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rtlpriv->psc.sw_ps_enabled) { | 
					
						
							|  |  |  | 		if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) && | 
					
						
							|  |  |  | 		    !ieee80211_has_pm(fc)) | 
					
						
							|  |  |  | 			hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	rtl_action_proc(hw, skb, true); | 
					
						
							|  |  |  | 	if (is_multicast_ether_addr(pda_addr)) | 
					
						
							|  |  |  | 		rtlpriv->stats.txbytesmulticast += skb->len; | 
					
						
							|  |  |  | 	else if (is_broadcast_ether_addr(pda_addr)) | 
					
						
							|  |  |  | 		rtlpriv->stats.txbytesbroadcast += skb->len; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		rtlpriv->stats.txbytesunicast += skb->len; | 
					
						
							|  |  |  | 	if (ieee80211_is_data_qos(fc)) { | 
					
						
							|  |  |  | 		qc = ieee80211_get_qos_ctl(hdr); | 
					
						
							|  |  |  | 		tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; | 
					
						
							|  |  |  | 		seq_number = (le16_to_cpu(hdr->seq_ctrl) & | 
					
						
							|  |  |  | 			     IEEE80211_SCTL_SEQ) >> 4; | 
					
						
							|  |  |  | 		seq_number += 1; | 
					
						
							|  |  |  | 		seq_number <<= 4; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-07-23 21:33:42 +02:00
										 |  |  | 	rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, info, sta, skb, | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:29 -05:00
										 |  |  | 					hw_queue, &tcb_desc); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	if (!ieee80211_has_morefrags(hdr->frame_control)) { | 
					
						
							|  |  |  | 		if (qc) | 
					
						
							|  |  |  | 			mac->tids[tid].seq_number = seq_number; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (ieee80211_is_data(fc)) | 
					
						
							|  |  |  | 		rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-23 21:33:42 +02:00
										 |  |  | static int rtl_usb_tx(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 		      struct ieee80211_sta *sta, | 
					
						
							|  |  |  | 		      struct sk_buff *skb, | 
					
						
							| 
									
										
										
										
											2011-04-25 13:23:10 -05:00
										 |  |  | 		      struct rtl_tcb_desc *dummy) | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); | 
					
						
							| 
									
										
										
										
											2011-02-19 16:29:57 -06:00
										 |  |  | 	__le16 fc = hdr->frame_control; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	u16 hw_queue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(is_hal_stop(rtlhal))) | 
					
						
							|  |  |  | 		goto err_free; | 
					
						
							|  |  |  | 	hw_queue = rtlusb->usb_mq_to_hwq(fc, skb_get_queue_mapping(skb)); | 
					
						
							| 
									
										
										
										
											2012-07-23 21:33:42 +02:00
										 |  |  | 	_rtl_usb_tx_preprocess(hw, sta, skb, hw_queue); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	_rtl_usb_transmit(hw, skb, hw_queue); | 
					
						
							|  |  |  | 	return NETDEV_TX_OK; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | err_free: | 
					
						
							|  |  |  | 	dev_kfree_skb_any(skb); | 
					
						
							|  |  |  | 	return NETDEV_TX_OK; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static bool rtl_usb_tx_chk_waitq_insert(struct ieee80211_hw *hw, | 
					
						
							| 
									
										
										
										
											2012-07-23 21:33:42 +02:00
										 |  |  | 					struct ieee80211_sta *sta, | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 					struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-30 18:05:55 -05:00
										 |  |  | static void rtl_fill_h2c_cmd_work_callback(struct work_struct *work) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_works *rtlworks = | 
					
						
							|  |  |  | 	    container_of(work, struct rtl_works, fill_h2c_cmd); | 
					
						
							|  |  |  | 	struct ieee80211_hw *hw = rtlworks->hw; | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->fill_h2c_cmd(hw, H2C_RA_MASK, 5, rtlpriv->rate_mask); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | static struct rtl_intf_ops rtl_usb_ops = { | 
					
						
							|  |  |  | 	.adapter_start = rtl_usb_start, | 
					
						
							|  |  |  | 	.adapter_stop = rtl_usb_stop, | 
					
						
							|  |  |  | 	.adapter_tx = rtl_usb_tx, | 
					
						
							|  |  |  | 	.waitq_insert = rtl_usb_tx_chk_waitq_insert, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-03 09:56:43 -05:00
										 |  |  | int rtl_usb_probe(struct usb_interface *intf, | 
					
						
							| 
									
										
										
										
											2013-02-06 12:54:17 -06:00
										 |  |  | 		  const struct usb_device_id *id, | 
					
						
							|  |  |  | 		  struct rtl_hal_cfg *rtl_hal_cfg) | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 	struct ieee80211_hw *hw = NULL; | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = NULL; | 
					
						
							|  |  |  | 	struct usb_device	*udev; | 
					
						
							|  |  |  | 	struct rtl_usb_priv *usb_priv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hw = ieee80211_alloc_hw(sizeof(struct rtl_priv) + | 
					
						
							|  |  |  | 				sizeof(struct rtl_usb_priv), &rtl_ops); | 
					
						
							|  |  |  | 	if (!hw) { | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:43 -08:00
										 |  |  | 		RT_ASSERT(false, "ieee80211 alloc failed\n"); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	rtlpriv = hw->priv; | 
					
						
							| 
									
										
										
										
											2012-03-19 15:44:31 -05:00
										 |  |  | 	rtlpriv->usb_data = kzalloc(RTL_USB_MAX_RX_COUNT * sizeof(u32), | 
					
						
							|  |  |  | 				    GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!rtlpriv->usb_data) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							| 
									
										
										
										
											2012-07-11 14:37:28 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* this spin lock must be initialized early */ | 
					
						
							|  |  |  | 	spin_lock_init(&rtlpriv->locks.usb_lock); | 
					
						
							| 
									
										
										
										
											2013-05-30 18:05:55 -05:00
										 |  |  | 	INIT_WORK(&rtlpriv->works.fill_h2c_cmd, | 
					
						
							|  |  |  | 		  rtl_fill_h2c_cmd_work_callback); | 
					
						
							| 
									
										
										
										
											2013-06-28 09:12:53 -05:00
										 |  |  | 	INIT_WORK(&rtlpriv->works.lps_change_work, | 
					
						
							|  |  |  | 		  rtl_lps_change_work_callback); | 
					
						
							| 
									
										
										
										
											2012-07-11 14:37:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-19 15:44:31 -05:00
										 |  |  | 	rtlpriv->usb_data_index = 0; | 
					
						
							| 
									
										
										
										
											2012-01-30 09:54:49 -06:00
										 |  |  | 	init_completion(&rtlpriv->firmware_loading_complete); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	SET_IEEE80211_DEV(hw, &intf->dev); | 
					
						
							|  |  |  | 	udev = interface_to_usbdev(intf); | 
					
						
							|  |  |  | 	usb_get_dev(udev); | 
					
						
							|  |  |  | 	usb_priv = rtl_usbpriv(hw); | 
					
						
							|  |  |  | 	memset(usb_priv, 0, sizeof(*usb_priv)); | 
					
						
							|  |  |  | 	usb_priv->dev.intf = intf; | 
					
						
							|  |  |  | 	usb_priv->dev.udev = udev; | 
					
						
							|  |  |  | 	usb_set_intfdata(intf, hw); | 
					
						
							|  |  |  | 	/* init cfg & intf_ops */ | 
					
						
							|  |  |  | 	rtlpriv->rtlhal.interface = INTF_USB; | 
					
						
							| 
									
										
										
										
											2013-02-06 12:54:17 -06:00
										 |  |  | 	rtlpriv->cfg = rtl_hal_cfg; | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	rtlpriv->intf_ops = &rtl_usb_ops; | 
					
						
							|  |  |  | 	rtl_dbgp_flag_init(hw); | 
					
						
							|  |  |  | 	/* Init IO handler */ | 
					
						
							|  |  |  | 	_rtl_usb_io_handler_init(&udev->dev, hw); | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->read_chip_version(hw); | 
					
						
							|  |  |  | 	/*like read eeprom and so on */ | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->read_eeprom_info(hw); | 
					
						
							|  |  |  | 	err = _rtl_usb_init(hw); | 
					
						
							| 
									
										
										
										
											2012-03-02 13:21:22 -06:00
										 |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto error_out; | 
					
						
							| 
									
										
										
										
											2012-03-02 13:22:46 -06:00
										 |  |  | 	rtl_usb_init_sw(hw); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	/* Init mac80211 sw */ | 
					
						
							|  |  |  | 	err = rtl_init_core(hw); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Can't allocate sw for mac80211\n"); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 		goto error_out; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-04 08:27:43 -05:00
										 |  |  | 	if (rtlpriv->cfg->ops->init_sw_vars(hw)) { | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Can't init_sw_vars\n"); | 
					
						
							|  |  |  | 		goto error_out; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->init_sw_leds(hw); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | error_out: | 
					
						
							|  |  |  | 	rtl_deinit_core(hw); | 
					
						
							|  |  |  | 	_rtl_usb_io_handler_release(hw); | 
					
						
							|  |  |  | 	usb_put_dev(udev); | 
					
						
							| 
									
										
										
										
											2012-01-30 09:54:49 -06:00
										 |  |  | 	complete(&rtlpriv->firmware_loading_complete); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	return -ENODEV; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL(rtl_usb_probe); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void rtl_usb_disconnect(struct usb_interface *intf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ieee80211_hw *hw = usb_get_intfdata(intf); | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(!rtlpriv)) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2012-01-30 09:54:49 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* just in case driver is removed before firmware callback */ | 
					
						
							|  |  |  | 	wait_for_completion(&rtlpriv->firmware_loading_complete); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	/*ieee80211_unregister_hw will call ops_stop */ | 
					
						
							|  |  |  | 	if (rtlmac->mac80211_registered == 1) { | 
					
						
							|  |  |  | 		ieee80211_unregister_hw(hw); | 
					
						
							|  |  |  | 		rtlmac->mac80211_registered = 0; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		rtl_deinit_deferred_work(hw); | 
					
						
							|  |  |  | 		rtlpriv->intf_ops->adapter_stop(hw); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/*deinit rfkill */ | 
					
						
							|  |  |  | 	/* rtl_deinit_rfkill(hw); */ | 
					
						
							|  |  |  | 	rtl_usb_deinit(hw); | 
					
						
							|  |  |  | 	rtl_deinit_core(hw); | 
					
						
							| 
									
										
										
										
											2012-03-19 15:44:31 -05:00
										 |  |  | 	kfree(rtlpriv->usb_data); | 
					
						
							| 
									
										
										
										
											2011-02-11 14:27:49 -06:00
										 |  |  | 	rtlpriv->cfg->ops->deinit_sw_leds(hw); | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->deinit_sw_vars(hw); | 
					
						
							|  |  |  | 	_rtl_usb_io_handler_release(hw); | 
					
						
							|  |  |  | 	usb_put_dev(rtlusb->udev); | 
					
						
							|  |  |  | 	usb_set_intfdata(intf, NULL); | 
					
						
							|  |  |  | 	ieee80211_free_hw(hw); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL(rtl_usb_disconnect); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int rtl_usb_suspend(struct usb_interface *pusb_intf, pm_message_t message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL(rtl_usb_suspend); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int rtl_usb_resume(struct usb_interface *pusb_intf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL(rtl_usb_resume); |