linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/6] rtlwifi: Add usb driver
@ 2011-02-06 18:44 Larry Finger
  2011-02-07 15:07 ` Stanislaw Gruszka
  2011-02-07 15:12 ` Stanislaw Gruszka
  0 siblings, 2 replies; 12+ messages in thread
From: Larry Finger @ 2011-02-06 18:44 UTC (permalink / raw)
  To: John W Linville; +Cc: sgruszka, george0505, chaoming_li, linux-wireless

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---

V2 - incorporate the comments by Stanislaw Gruszka.

Index: wireless-testing/drivers/net/wireless/rtlwifi/Makefile
===================================================================
--- wireless-testing.orig/drivers/net/wireless/rtlwifi/Makefile
+++ wireless-testing/drivers/net/wireless/rtlwifi/Makefile
@@ -8,6 +8,7 @@ rtlwifi-objs	:=		\
 		pci.o		\
 		ps.o		\
 		rc.o		\
-		regd.o
+		regd.o		\
+		usb.o
 
 obj-$(CONFIG_RTL8192CE)		+= rtl8192ce/
Index: wireless-testing/drivers/net/wireless/rtlwifi/usb.c
===================================================================
--- /dev/null
+++ wireless-testing/drivers/net/wireless/rtlwifi/usb.c
@@ -0,0 +1,1065 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2009-2011  Realtek Corporation. All rights reserved.
+ *
+ * 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.
+ *
+ *****************************************************************************/
+#include <linux/usb.h>
+#include "core.h"
+#include "wifi.h"
+#include "usb.h"
+#include "base.h"
+#include "ps.h"
+
+#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
+
+#define REALTEK_USB_VENQT_MAX_BUF_SIZE		254
+
+enum {
+	VENDOR_WRITE = 0x00,
+	VENDOR_READ = 0x01,
+};
+
+static void usbctrl_async_callback(struct urb *urb)
+{
+	if (urb)
+		kfree(urb->context);
+}
+
+static int _usbctrl_vendorreq_async(struct usb_device *udev, u8 request,
+					  u16 value, u16 index, void *pdata,
+					  u16 len, u8 requesttype)
+{
+	int rc;
+	unsigned int pipe;
+	u8 reqtype;
+	struct usb_ctrlrequest *dr;
+	struct urb *urb;
+	struct rtl819x_async_write_data {
+		u8 data[REALTEK_USB_VENQT_MAX_BUF_SIZE];
+		struct usb_ctrlrequest dr;
+	} *buf;
+
+	if (requesttype == VENDOR_READ) {
+		pipe = usb_rcvctrlpipe(udev, 0); /* read_in */
+		reqtype =  REALTEK_USB_VENQT_READ;
+	} else {
+		pipe = usb_sndctrlpipe(udev, 0); /* write_out */
+		reqtype =  REALTEK_USB_VENQT_WRITE;
+	}
+
+	buf = kmalloc(sizeof(*buf), GFP_ATOMIC);
+	if (!buf)
+		return -ENOMEM;
+
+	urb = usb_alloc_urb(0, GFP_ATOMIC);
+	if (!urb) {
+		kfree(buf);
+		return -ENOMEM;
+	}
+
+	dr = &buf->dr;
+
+	dr->bRequestType = reqtype;
+	dr->bRequest = request;
+	dr->wValue = cpu_to_le16(value);
+	dr->wIndex = cpu_to_le16(index);
+	dr->wLength = cpu_to_le16(len);
+	memcpy(buf, pdata, len);
+	usb_fill_control_urb(urb, udev, pipe,
+			     (unsigned char *)dr, buf, len,
+			     usbctrl_async_callback, buf);
+	rc = usb_submit_urb(urb, GFP_ATOMIC);
+	if (rc < 0)
+		kfree(buf);
+	usb_free_urb(urb);
+	return rc;
+}
+
+static int _usbctrl_vendorreq_sync(struct usb_device *udev, u8 request,
+				   u16 value, u16 index, void *pdata,
+				   u16 len, u8 requesttype)
+{
+	unsigned int pipe;
+	int status;
+	u8 reqtype;
+
+	if (requesttype == VENDOR_READ) {
+		pipe = usb_rcvctrlpipe(udev, 0); /* read_in */
+		reqtype =  REALTEK_USB_VENQT_READ;
+	} else {
+		pipe = usb_sndctrlpipe(udev, 0); /* write_out */
+		reqtype =  REALTEK_USB_VENQT_WRITE;
+	}
+
+	status = usb_control_msg(udev, pipe, request, reqtype, value, index,
+				 pdata, len, 0); /* max. timeout */
+
+	if (status < 0)
+		printk(KERN_ERR "reg 0x%x, usbctrl_vendorreq TimeOut! "
+		       "status:0x%x value=0x%x\n", value, status,
+		       *(u32 *)pdata);
+	return status;
+}
+
+static u32 _usb_read_sync(struct usb_device *udev, u32 addr, u16 len)
+{
+	u8 request;
+	u8 requesttype;
+	u16 wvalue;
+	u16 index;
+	u32 *data;
+	u32 ret;
+
+	data = kmalloc(sizeof(u32), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+	requesttype = VENDOR_READ; /* read_in */
+	request = REALTEK_USB_VENQT_CMD_REQ;
+	index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
+
+	wvalue = (u16)(addr&0x0000ffff);
+	_usbctrl_vendorreq_sync(udev, request, wvalue, index, data, len,
+				requesttype);
+	ret = le32_to_cpu(*data);
+	kfree(data);
+	return ret;
+}
+
+static u8 _usb_read8_sync(struct rtl_priv *rtlpriv, u32 addr)
+{
+	struct device *dev = rtlpriv->io.dev;
+
+	return (u8)_usb_read_sync(to_usb_device(dev), addr, 1);
+}
+
+static u16 _usb_read16_sync(struct rtl_priv *rtlpriv, u32 addr)
+{
+	struct device *dev = rtlpriv->io.dev;
+
+	return (u16)_usb_read_sync(to_usb_device(dev), addr, 2);
+}
+
+static u32 _usb_read32_sync(struct rtl_priv *rtlpriv, u32 addr)
+{
+	struct device *dev = rtlpriv->io.dev;
+
+	return _usb_read_sync(to_usb_device(dev), addr, 4);
+}
+
+static void _usb_write_async(struct usb_device *udev, u32 addr, u32 val,
+			     u16 len)
+{
+	u8 request;
+	u8 requesttype;
+	u16 wvalue;
+	u16 index;
+	u32 data;
+
+	requesttype = VENDOR_WRITE; /* write_out */
+	request = REALTEK_USB_VENQT_CMD_REQ;
+	index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
+	wvalue = (u16)(addr&0x0000ffff);
+	data = cpu_to_le32(val);
+	_usbctrl_vendorreq_async(udev, request, wvalue, index, &data,
+				       len, requesttype);
+}
+
+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);
+}
+
+static int _usb_nbytes_read_write(struct usb_device *udev, bool read, u32 addr,
+				  u16 len, u8 *pdata)
+{
+	int status;
+	u8 request;
+	u8 requesttype;
+	u16 wvalue;
+	u16 index;
+
+	requesttype = (read) ? VENDOR_READ : VENDOR_WRITE; /* read_in */
+	request = REALTEK_USB_VENQT_CMD_REQ;
+	index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
+	wvalue = (u16)(addr&0x0000ffff);
+	if (read)
+		status = _usbctrl_vendorreq_sync(udev, request, wvalue, index,
+						 pdata, len, requesttype);
+	else
+		status = _usbctrl_vendorreq_async(udev, request, wvalue,
+							index, pdata, len,
+							requesttype);
+	return status;
+}
+
+static int _usb_readN_sync(struct rtl_priv *rtlpriv, u32 addr, u16 len,
+			   u8 *pdata)
+{
+	struct device *dev = rtlpriv->io.dev;
+
+	return _usb_nbytes_read_write(to_usb_device(dev), true, addr, len,
+				       pdata);
+}
+
+static int _usb_writeN_async(struct rtl_priv *rtlpriv, u32 addr, u16 len,
+			     u8 *pdata)
+{
+	struct device *dev = rtlpriv->io.dev;
+
+	return _usb_nbytes_read_write(to_usb_device(dev), false, addr, len,
+				      pdata);
+}
+
+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.writeN_async	= _usb_writeN_async;
+	rtlpriv->io.read8_sync		= _usb_read8_sync;
+	rtlpriv->io.read16_sync		= _usb_read16_sync;
+	rtlpriv->io.read32_sync		= _usb_read32_sync;
+	rtlpriv->io.readN_sync		= _usb_readN_sync;
+}
+
+static void _rtl_usb_io_handler_release(struct ieee80211_hw *hw)
+{
+	struct rtl_priv *rtlpriv = rtl_priv(hw);
+
+	if (&rtlpriv->io)
+		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;
+
+	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("USB Max Bulk-out Size=%d\n",
+		 rtlusb->max_bulk_out_size));
+
+	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,
+				 ("Invalid endpoint map setting!\n"));
+			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;
+}
+
+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;
+
+	printk(KERN_INFO "rtl8192cu: rx_max_size %d, rx_urb_num %d, in_ep %d\n",
+		rtlusb->rx_max_size, rtlusb->rx_urb_num, rtlusb->in_ep);
+	init_usb_anchor(&rtlusb->rx_submitted);
+	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,
+			 ("USB EP(0x%02x), MaxPacketSize=%d ,Interval=%d.\n",
+			 pep_desc->bEndpointAddress, pep_desc->wMaxPacketSize,
+			 pep_desc->bInterval));
+	}
+	if (rtlusb->in_ep_nums <  rtlpriv->cfg->usb_interface_cfg->in_ep_num)
+		return -EINVAL ;
+
+	/* 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;
+}
+
+static int _rtl_usb_init_sw(struct ieee80211_hw *hw)
+{
+	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;
+	ppsc->b_inactiveps = false;
+	ppsc->b_leisure_ps = false;
+	ppsc->b_fwctrl_lps = false;
+	ppsc->b_reg_fwctrl_lps = 3;
+	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;
+	return 0;
+}
+
+#define __RADIO_TAP_SIZE_RSV	32
+
+static void _rtl_rx_completed(struct urb *urb);
+
+static struct sk_buff *_rtl_prep_rx_urb(struct ieee80211_hw *hw,
+					struct rtl_usb *rtlusb,
+					struct urb *urb,
+					gfp_t gfp_mask)
+{
+	struct sk_buff *skb;
+	struct rtl_priv *rtlpriv = rtl_priv(hw);
+
+	skb = __dev_alloc_skb((rtlusb->rx_max_size + __RADIO_TAP_SIZE_RSV),
+			       gfp_mask);
+	if (!skb) {
+		RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
+			 ("Failed to __dev_alloc_skb!!\n"))
+		return ERR_PTR(-ENOMEM);
+	}
+
+	/* reserve some space for mac80211's radiotap */
+	skb_reserve(skb, __RADIO_TAP_SIZE_RSV);
+	usb_fill_bulk_urb(urb, rtlusb->udev,
+			  usb_rcvbulkpipe(rtlusb->udev, rtlusb->in_ep),
+			  skb->data, min(skb_tailroom(skb),
+			  (int)rtlusb->rx_max_size),
+			  _rtl_rx_completed, skb);
+
+	_rtl_install_trx_info(rtlusb, skb, rtlusb->in_ep);
+	return skb;
+}
+
+#undef __RADIO_TAP_SIZE_RSV
+
+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;
+	u16 fc;
+	struct ieee80211_rx_status rx_status = {0};
+	struct rtl_stats stats = {
+		.signal = 0,
+		.noise = -98,
+		.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);
+	fc = le16_to_cpu(hdr->frame_control);
+	if (!stats.b_crc) {
+		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;
+		}
+
+		rtl_is_special_data(hw, skb, false);
+
+		if (ieee80211_is_data(fc)) {
+			rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX);
+
+			if (unicast)
+				rtlpriv->link_info.num_rx_inperiod++;
+		}
+	}
+}
+
+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;
+	u16 fc;
+	struct ieee80211_rx_status rx_status = {0};
+	struct rtl_stats stats = {
+		.signal = 0,
+		.noise = -98,
+		.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);
+	fc = le16_to_cpu(hdr->frame_control);
+	if (!stats.b_crc) {
+		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;
+		}
+
+		rtl_is_special_data(hw, skb, false);
+
+		if (ieee80211_is_data(fc)) {
+			rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX);
+
+			if (unicast)
+				rtlpriv->link_info.num_rx_inperiod++;
+		}
+		if (likely(rtl_action_proc(hw, skb, false))) {
+			struct sk_buff *uskb = NULL;
+			u8 *pdata;
+
+			uskb = dev_alloc_skb(skb->len + 128);
+			memcpy(IEEE80211_SKB_RXCB(uskb), &rx_status,
+			       sizeof(rx_status));
+			pdata = (u8 *)skb_put(uskb, skb->len);
+			memcpy(pdata, skb->data, skb->len);
+			dev_kfree_skb_any(skb);
+			ieee80211_rx_irqsafe(hw, uskb);
+		} else {
+			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);
+		_rtl_usb_rx_process_agg(hw, skb);
+		ieee80211_rx_irqsafe(hw, skb);
+	}
+}
+
+static void _rtl_rx_completed(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);
+	struct rtl_priv *rtlpriv = rtl_priv(hw);
+	int err = 0;
+
+	/* TODO: check */
+	if (unlikely(IS_USB_STOP(rtlusb)))
+		goto free;
+
+	if (likely(0 == _urb->status)) {
+		/* TODO: Move these code to work queue to improve CPU
+		 * utilization!  NOTE: We shall allocate another skb
+		 * and reuse the original one.
+		 */
+		skb_put(skb, _urb->actual_length);
+
+		if (likely(!rtlusb->usb_rx_segregate_hdl)) {
+			struct sk_buff *_skb;
+			_rtl_usb_rx_process_noagg(hw, skb);
+			_skb = _rtl_prep_rx_urb(hw, rtlusb, _urb, GFP_ATOMIC);
+			if (IS_ERR(_skb)) {
+				err = PTR_ERR(_skb);
+				RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
+					("Can't allocate skb for bulk IN!\n"));
+				return;
+			}
+			skb = _skb;
+		} else{
+			/* TO DO */
+			_rtl_rx_pre_process(hw, skb);
+			printk(KERN_ERR "rtlwifi: rx agg not supported\n");
+		}
+		goto resubmit;
+	}
+
+	switch (_urb->status) {
+	/* disconnect */
+	case -ENOENT:
+	case -ECONNRESET:
+	case -ENODEV:
+	case -ESHUTDOWN:
+		goto free;
+	default:
+		break;
+	}
+
+resubmit:
+	skb_reset_tail_pointer(skb);
+	skb_trim(skb, 0);
+
+	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:
+	dev_kfree_skb_irq(skb);
+}
+
+static int _rtl_usb_receive(struct ieee80211_hw *hw)
+{
+	struct urb *urb;
+	struct sk_buff *skb;
+	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,
+				 ("Failed to alloc URB!!\n"))
+			goto err_out;
+		}
+
+		skb = _rtl_prep_rx_urb(hw, rtlusb, urb, GFP_KERNEL);
+		if (IS_ERR(skb)) {
+			RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
+				 ("Failed to prep_rx_urb!!\n"))
+			err = PTR_ERR(skb);
+			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);
+	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);
+	rtl_init_rx_config(hw);
+
+	/* Enable software */
+	SET_USB_START(rtlusb);
+	/* should after adapter start and interrupt enable. */
+	set_hal_start(rtlhal);
+
+	/* Start bulk IN */
+	_rtl_usb_receive(hw);
+
+	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);
+	/*  TODO: think of race condition... */
+
+	/* clean up rx stuff. */
+	usb_kill_anchored_urbs(&rtlusb->rx_submitted);
+
+	/* 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);
+	/* 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,
+			 ("Failed to submit urb.\n"));
+		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,
+			 ("Urb has error status 0x%X\n", urb->status));
+		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) {
+		/* TODO: Shall I ignore error and keep issue 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) {
+		/* TODO: reinsert skb to list or free the skb? */
+		RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
+			 ("Can't allocate URB for bulk out!\n"));
+		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;
+	struct sk_buff_head *skb_list;
+	struct usb_anchor *urb_list;
+
+	WARN_ON(NULL == rtlusb->usb_tx_aggregate_hdl);
+	/* TODO: if usb suspend, we may queue the skb and wake device up.
+	 * Then xmit.
+	 * TODO: may change this statement and check all usb state */
+	if (unlikely(IS_USB_STOP(rtlusb))) {
+		RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
+			 ("USB device is stopping...\n"));
+		kfree_skb(skb);
+		return;
+	}
+	ep_num = rtlusb->ep_map.ep_mapping[qnum];
+	skb_list = &rtlusb->tx_skb_queue[ep_num];
+	_skb = skb;
+	_urb = _rtl_usb_tx_urb_setup(hw, _skb, ep_num);
+	if (unlikely(!_urb)) {
+		RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
+			 ("Can't allocate urb. Drop skb!\n"));
+		return;
+	}
+	urb_list = &rtlusb->tx_pending[ep_num];
+	_rtl_submit_tx_urb(hw, _urb);
+}
+
+static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw, struct sk_buff *skb,
+			    u16 hw_queue)
+{
+	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;
+	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
+	u16 fc = le16_to_cpu(hdr->frame_control);
+	u8 *pda_addr = hdr->addr1;
+	/* ssn */
+	u8 *qc = NULL;
+	u8 tid = 0;
+	u16 seq_number = 0;
+
+	if (ieee80211_is_mgmt(fc))
+		rtl_tx_mgmt_proc(hw, skb);
+	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;
+	}
+	rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, info, skb,
+					hw_queue);
+	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);
+}
+
+static int rtl_usb_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+	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);
+	u16 fc = le16_to_cpu(hdr->frame_control);
+	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));
+	_rtl_usb_tx_preprocess(hw, skb, hw_queue);
+	_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,
+					struct sk_buff *skb)
+{
+	return false;
+}
+
+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,
+};
+
+int __devinit rtl_usb_probe(struct usb_interface *intf,
+			const struct usb_device_id *id)
+{
+	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) {
+		RT_ASSERT(false, ("%s : ieee80211 alloc failed\n", __func__));
+		return -ENOMEM;
+	}
+	rtlpriv = hw->priv;
+	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;
+	rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_info);
+	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);
+	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);
+	err = _rtl_usb_init(hw);
+	err = _rtl_usb_init_sw(hw);
+	/* Init mac80211 sw */
+	err = rtl_init_core(hw);
+	if (err) {
+		RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
+			 ("Can't allocate sw for mac80211.\n"));
+		goto error_out;
+	}
+
+	/*init rfkill */
+	/* rtl_init_rfkill(hw); */
+
+	err = ieee80211_register_hw(hw);
+	if (err) {
+		RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
+			 ("Can't register mac80211 hw.\n"));
+		goto error_out;
+	} else {
+		rtlpriv->mac80211.mac80211_registered = 1;
+	}
+	set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
+	return 0;
+error_out:
+	rtl_deinit_core(hw);
+	_rtl_usb_io_handler_release(hw);
+	ieee80211_free_hw(hw);
+	usb_put_dev(udev);
+	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;
+	/*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);
+	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);
Index: wireless-testing/drivers/net/wireless/rtlwifi/usb.h
===================================================================
--- /dev/null
+++ wireless-testing/drivers/net/wireless/rtlwifi/usb.h
@@ -0,0 +1,164 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2009-2011  Realtek Corporation. All rights reserved.
+ *
+ * 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.
+ *
+ *****************************************************************************/
+
+#ifndef __RTL_USB_H__
+#define __RTL_USB_H__
+
+#include <linux/usb.h>
+#include <linux/skbuff.h>
+
+#define RTL_USB_DEVICE(vend, prod, cfg) \
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
+	.idVendor = (vend), \
+	.idProduct = (prod), \
+	.driver_info = (kernel_ulong_t)&(cfg)
+
+#define USB_HIGH_SPEED_BULK_SIZE	512
+#define USB_FULL_SPEED_BULK_SIZE	64
+
+
+#define RTL_USB_MAX_TXQ_NUM		4		/* max tx queue */
+#define RTL_USB_MAX_EP_NUM		6		/* max ep number */
+#define RTL_USB_MAX_TX_URBS_NUM		8
+
+enum rtl_txq {
+	/* These definitions shall be consistent with value
+	 * returned by skb_get_queue_mapping
+	 *------------------------------------*/
+	RTL_TXQ_BK,
+	RTL_TXQ_BE,
+	RTL_TXQ_VI,
+	RTL_TXQ_VO,
+	/*------------------------------------*/
+	RTL_TXQ_BCN,
+	RTL_TXQ_MGT,
+	RTL_TXQ_HI,
+
+	/* Must be last */
+	__RTL_TXQ_NUM,
+};
+
+struct rtl_ep_map {
+	u32 ep_mapping[__RTL_TXQ_NUM];
+};
+
+struct _trx_info {
+	struct rtl_usb *rtlusb;
+	u32 ep_num;
+};
+
+static inline void _rtl_install_trx_info(struct rtl_usb *rtlusb,
+					 struct sk_buff *skb,
+					 u32 ep_num)
+{
+	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+	info->rate_driver_data[0] = rtlusb;
+	info->rate_driver_data[1] = (void *)(__kernel_size_t)ep_num;
+}
+
+
+/*  Add suspend/resume later */
+enum rtl_usb_state {
+	USB_STATE_STOP	= 0,
+	USB_STATE_START	= 1,
+};
+
+#define IS_USB_STOP(rtlusb_ptr) (USB_STATE_STOP == (rtlusb_ptr)->state)
+#define IS_USB_START(rtlusb_ptr) (USB_STATE_START == (rtlusb_ptr)->state)
+#define SET_USB_STOP(rtlusb_ptr) \
+	do {							\
+		(rtlusb_ptr)->state = USB_STATE_STOP;		\
+	} while (0)
+
+#define SET_USB_START(rtlusb_ptr)				\
+	do { \
+		(rtlusb_ptr)->state = USB_STATE_START;		\
+	} while (0)
+
+struct rtl_usb {
+	struct usb_device *udev;
+	struct usb_interface *intf;
+	enum rtl_usb_state state;
+
+	/* Bcn control register setting */
+	u32 reg_bcn_ctrl_val;
+	/* for 88/92cu card disable */
+	u8	disableHWSM;
+	/*QOS & EDCA */
+	enum acm_method acm_method;
+	/* irq  . HIMR,HIMR_EX */
+	u32 irq_mask[2];
+	bool irq_enabled;
+
+	u16 (*usb_mq_to_hwq)(u16 fc, u16 mac80211_queue_index);
+
+	/* Tx */
+	u8 out_ep_nums ;
+	u8 out_queue_sel;
+	struct rtl_ep_map ep_map;
+
+	u32 max_bulk_out_size;
+	u32 tx_submitted_urbs;
+	struct sk_buff_head tx_skb_queue[RTL_USB_MAX_EP_NUM];
+
+	struct usb_anchor tx_pending[RTL_USB_MAX_EP_NUM];
+	struct usb_anchor tx_submitted;
+
+	struct sk_buff *(*usb_tx_aggregate_hdl)(struct ieee80211_hw *,
+						struct sk_buff_head *);
+	int (*usb_tx_post_hdl)(struct ieee80211_hw *,
+			       struct urb *, struct sk_buff *);
+	void (*usb_tx_cleanup)(struct ieee80211_hw *, struct sk_buff *);
+
+	/* Rx */
+	u8 in_ep_nums ;
+	u32 in_ep;		/* Bulk IN endpoint number */
+	u32 rx_max_size;	/* Bulk IN max buffer size */
+	u32 rx_urb_num;		/* How many Bulk INs are submitted to host. */
+	struct usb_anchor	rx_submitted;
+	void (*usb_rx_segregate_hdl)(struct ieee80211_hw *, struct sk_buff *,
+				     struct sk_buff_head *);
+	void (*usb_rx_hdl)(struct ieee80211_hw *, struct sk_buff *);
+};
+
+struct rtl_usb_priv {
+	struct rtl_usb dev;
+	struct rtl_led_ctl ledctl;
+};
+
+#define rtl_usbpriv(hw)	 (((struct rtl_usb_priv *)(rtl_priv(hw))->priv))
+#define rtl_usbdev(usbpriv)	(&((usbpriv)->dev))
+
+
+
+int __devinit rtl_usb_probe(struct usb_interface *intf,
+			    const struct usb_device_id *id);
+void rtl_usb_disconnect(struct usb_interface *intf);
+int rtl_usb_suspend(struct usb_interface *pusb_intf, pm_message_t message);
+int rtl_usb_resume(struct usb_interface *pusb_intf);
+
+#endif

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/6] rtlwifi: Add usb driver
  2011-02-06 18:44 [PATCH 2/6] rtlwifi: Add usb driver Larry Finger
@ 2011-02-07 15:07 ` Stanislaw Gruszka
  2011-02-07 15:12 ` Stanislaw Gruszka
  1 sibling, 0 replies; 12+ messages in thread
From: Stanislaw Gruszka @ 2011-02-07 15:07 UTC (permalink / raw)
  To: Larry Finger; +Cc: John W Linville, george0505, chaoming_li, linux-wireless

On Sun, Feb 06, 2011 at 12:44:20PM -0600, Larry Finger wrote:
> +enum {
> +	VENDOR_WRITE = 0x00,
> +	VENDOR_READ = 0x01,
> +};
[snip]
> +static int _usbctrl_vendorreq_async(struct usb_device *udev, u8 request,
> +					  u16 value, u16 index, void *pdata,
> +					  u16 len, u8 requesttype)
> +{
It whould be better to leave old name and remove requesttype argument.
We never call  _usbctrl_vendorreq_async with VENDOR_READ, and 
 _usbctrl_vendorreq_sync with VENDOR_WRITE.

If this is not preparation for future changes, that need to
cleaned up, and VENDOR_WRITE and VENDOR_READ definition removed at all.

> +	wvalue = (u16)(addr&0x0000ffff);
wvalue = (u16) addr;

> +static void _rtl_usb_io_handler_release(struct ieee80211_hw *hw)
> +{
> +	struct rtl_priv *rtlpriv = rtl_priv(hw);
> +
> +	if (&rtlpriv->io)
How it can be NULL? :-) Perhaps this should be rtlpriv check?

> +	/*  TODO: think of race condition... */
[snip]
> +	/*  TODO:	statistics */
[snip]
> +
[snip]
> +		/* TODO: Shall I ignore error and keep issue other urbs? */
[snip]
> +		/* TODO: reinsert skb to list or free the skb? */
[snip]
> +	/* TODO: if usb suspend, we may queue the skb and wake device up.
> +	 * Then xmit.
> +	 * TODO: may change this statement and check all usb state */

Lots of TODO, is this code working? :-)

Is this driver for devices that are currently on the market,
or for future product? I have 3 Realtek dongles, but all works
only with staging driver ...

Stanislaw

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/6] rtlwifi: Add usb driver
  2011-02-06 18:44 [PATCH 2/6] rtlwifi: Add usb driver Larry Finger
  2011-02-07 15:07 ` Stanislaw Gruszka
@ 2011-02-07 15:12 ` Stanislaw Gruszka
  2011-02-09  1:58   ` about Mac80211 scan issue 李朝明
  1 sibling, 1 reply; 12+ messages in thread
From: Stanislaw Gruszka @ 2011-02-07 15:12 UTC (permalink / raw)
  To: Larry Finger; +Cc: John W Linville, george0505, chaoming_li, linux-wireless

On Sun, Feb 06, 2011 at 12:44:20PM -0600, Larry Finger wrote:
> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>

Oh, one more thing, shouldn't be signed also by Realtek
or Realsil?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* about Mac80211 scan issue
  2011-02-07 15:12 ` Stanislaw Gruszka
@ 2011-02-09  1:58   ` 李朝明
  2011-02-09 10:54     ` Stanislaw Gruszka
  0 siblings, 1 reply; 12+ messages in thread
From: 李朝明 @ 2011-02-09  1:58 UTC (permalink / raw)
  To: 'Stanislaw Gruszka', 'Larry Finger'
  Cc: 'John W Linville',
	linux-wireless, '冯春燕',
	'熊光安'

 
Dear John:

	recently, I found some issues on mac80211 scan about null packet.
	
	Before we switch channel in scanning, we will send null packet to AP
to indicate that we will sleep.
	but at the same time there maybe lots of packets in HW tx buffer
witch are all ready to tx but with out 
	power save flag set to 1. if we send this null packet after these
tx buffer packets in a low priority, this will 
	cause follwing null packets fail because follwing check in
__ieee80211_tx:
		if (local->queue_stop_reasons[q] ||
		    (!txpending && !skb_queue_empty(&local->pending[q])))
			ret = IEEE80211_TX_PENDING;

	But if we send these null before there tx buffer packets packets in
a high priority, these packets will 
	be send after this null before switch channel. and switch channel
will cause RX packet from AP fail abruptly,
	this abruptly fail will cause DELETE BA for some AP like Belkin-8233
11N mode or dis-associate by some AP like Dir855 5G 11N mode
	when we  to test Throughput use chariot

	And I found that after power save  null packet have been sent, there
are lots packet send to driver from mac80211,
	should we stop all queues after we send power save  null packet  and
recover all queues after we send awake null packet.

	So, I don't kown if it's a mac80211's issue, Could you give some
help?

Thank you! 
Best regards!
lizhaoming





^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: about Mac80211 scan issue
  2011-02-09  1:58   ` about Mac80211 scan issue 李朝明
@ 2011-02-09 10:54     ` Stanislaw Gruszka
       [not found]       ` <B8DE8263FD784AC082CFDB7E9269BAEA@realsil.com.cn>
  0 siblings, 1 reply; 12+ messages in thread
From: Stanislaw Gruszka @ 2011-02-09 10:54 UTC (permalink / raw)
  To: 李朝明
  Cc: 'Larry Finger', 'John W Linville',
	linux-wireless, '冯春燕',
	'熊光安'

On Wed, Feb 09, 2011 at 09:58:46AM +0800, 李朝明 wrote:
> 	recently, I found some issues on mac80211 scan about null packet.
> 	
> 	Before we switch channel in scanning, we will send null packet to AP
> to indicate that we will sleep.
> 	but at the same time there maybe lots of packets in HW tx buffer
> witch are all ready to tx but with out 
> 	power save flag set to 1. if we send this null packet after these
> tx buffer packets in a low priority,

We have ieee80211_ops->flush() method to send all pending tx frames from
hw before sending null frame. I see rtlwifi does not have it.

> this will 
> 	cause follwing null packets fail because follwing check in
> __ieee80211_tx:
> 		if (local->queue_stop_reasons[q] ||
> 		    (!txpending && !skb_queue_empty(&local->pending[q])))
> 			ret = IEEE80211_TX_PENDING;
> 
> 	But if we send these null before there tx buffer packets packets in
> a high priority, these packets will 
> 	be send after this null before switch channel. and switch channel
> will cause RX packet from AP fail abruptly,
> 	this abruptly fail will cause DELETE BA for some AP like Belkin-8233
> 11N mode or dis-associate by some AP like Dir855 5G 11N mode
> 	when we  to test Throughput use chariot
> 
> 	And I found that after power save  null packet have been sent, there
> are lots packet send to driver from mac80211,
> 	should we stop all queues after we send power save  null packet  and
> recover all queues after we send awake null packet.
> 
> 	So, I don't kown if it's a mac80211's issue, Could you give some
> help?

I'm not sure if I understand problem you described. Anyway, maybe is
enaugh to implement ->flush() in rtlwifi to solve the problem?

Stanislaw

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: 答复: about Mac80211 scan issue
       [not found]       ` <B8DE8263FD784AC082CFDB7E9269BAEA@realsil.com.cn>
@ 2011-02-10  7:41         ` Stanislaw Gruszka
       [not found]           ` <39A39FA0AD1A481480DE0BD469AAA79E@realsil.com.cn>
  0 siblings, 1 reply; 12+ messages in thread
From: Stanislaw Gruszka @ 2011-02-10  7:41 UTC (permalink / raw)
  To: 李朝明
  Cc: 'Larry Finger', 'John W Linville',
	linux-wireless, '冯春燕',
	'熊光安'

On Thu, Feb 10, 2011 at 03:03:57PM +0800, 李朝明 wrote:
> > I'm not sure if I understand problem you described. Anyway, 
> > maybe is enaugh to implement ->flush() in rtlwifi to solve 
> > the problem?
> 
> I don't think drv_flush in ieee80211_start_sw_scan is needed, because
> there's no netif_tx_stop_all_queues before it.
> And on my test, all queues still send skb to driver in this drv_flush.

Hmm, there must be something wrong ... there is netif_tx_stop_all_queues
when interface is not MONITOR. Below are corresponding code snippets:

static void ieee80211_scan_state_leave_oper_channel(struct ieee80211_local *local,
                                                    unsigned long *next_delay)
{
        /* PS will already be in off-channel mode,
         * we do that once at the beginning of scanning.
         */
        ieee80211_offchannel_stop_vifs(local, false);

        /*
         * What if the nullfunc frames didn't arrive?
         */
        drv_flush(local, false);

....

void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local,
                                    bool offchannel_ps_enable)
{
        struct ieee80211_sub_if_data *sdata;

        /*
         * notify the AP about us leaving the channel and stop all
         * STA interfaces.
         */
        mutex_lock(&local->iflist_mtx);
        list_for_each_entry(sdata, &local->interfaces, list) {
                if (!ieee80211_sdata_running(sdata))
                        continue;

                if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
                        set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
...
                if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
                        netif_tx_stop_all_queues(sdata->dev);
              

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: 答复: 答复: about Mac80211 scan issue
       [not found]           ` <39A39FA0AD1A481480DE0BD469AAA79E@realsil.com.cn>
@ 2011-02-10  9:50             ` Stanislaw Gruszka
       [not found]               ` <86D43C3FD69641C38E7144E721BCC5A6@realsil.com.cn>
  0 siblings, 1 reply; 12+ messages in thread
From: Stanislaw Gruszka @ 2011-02-10  9:50 UTC (permalink / raw)
  To: 李朝明, Johannes Berg
  Cc: 'Larry Finger', 'John W Linville',
	linux-wireless, '冯春燕',
	'熊光安'

On Thu, Feb 10, 2011 at 03:48:57PM +0800, 李朝明 wrote:
> Yes, that flush can work well, but before drv_flush in
> ieee80211_start_sw_scan have no queue stop actions.
> Below are corresponding code:
> static int ieee80211_start_sw_scan(struct ieee80211_local *local)
> {
> 	/*
> 	 * Hardware/driver doesn't support hw_scan, so use software
> 	 * scanning instead. First send a nullfunc frame with power save
> 	 * bit on so that AP will buffer the frames for us while we are not
> 	 * listening, then send probe requests to each channel and wait for
> 	 * the responses. After all channels are scanned, tune back to the
> 	 * original channel and send a nullfunc frame with power save bit
> 	 * off to trigger the AP to send us all the buffered frames.
> 	 *
> 	 * Note that while local->sw_scanning is true everything else but
> 	 * nullfunc frames and probe requests will be dropped in
> 	 * ieee80211_tx_h_check_assoc().
> 	 */
> 	drv_sw_scan_start(local);
> 
> 	ieee80211_offchannel_stop_beaconing(local);
> 
> 	local->leave_oper_channel_time = 0;
> 	local->next_scan_state = SCAN_DECISION;
> 	local->scan_channel_idx = 0;
> 
> 	drv_flush(local, false);

I looked at wireless-testing tree where code was currently
changed by b23b025fe246f3acc2988eb6d400df34c27cb8ae
"mac80211: Optimize scans on current operating channel."
We stop queues and flush only when leaving operating channel in
ieee80211_scan_state_leave_oper_channel(), what seems to be correct.

Regarding linux-2.6 tree. I think you have right and we have bug
in mac80211, because we do not stop queues before flush in
ieee80211_offchannel_stop_beaconing() when working in STA mode.
Also comment in above function seems to be wrong. 

I'm not sure what to do with that, maybe Johannes will
have some insight?

Anyway, chaoming_li, could you clone current wireless-testing
tree and see how things work there?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: 答复: 答复: 答复: about Mac80211scan issue
       [not found]               ` <86D43C3FD69641C38E7144E721BCC5A6@realsil.com.cn>
@ 2011-02-10 11:37                 ` Stanislaw Gruszka
  2011-02-11  2:26                   ` [RFC] mac80211: cisco 1252 HT bw20, sta->ht_cap.cap bw is wrong 李朝明
  0 siblings, 1 reply; 12+ messages in thread
From: Stanislaw Gruszka @ 2011-02-10 11:37 UTC (permalink / raw)
  To: 李朝明
  Cc: 'Johannes Berg', 'Larry Finger',
	'John W Linville',
	linux-wireless, '冯春燕',
	'熊光安'

On Thu, Feb 10, 2011 at 06:05:20PM +0800, 李朝明 wrote:
> Sorry,  could you tell me address of  wireless-testing tree.

http://git.kernel.org/?p=linux/kernel/git/linville/wireless-testing.git;a=summary

Most kernel trees are hosted on git.kernel.org and are availeble using git.

Stanislaw

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [RFC] mac80211: cisco 1252 HT bw20, sta->ht_cap.cap bw is wrong
  2011-02-10 11:37                 ` 答复: 答复: 答复: about Mac80211scan issue Stanislaw Gruszka
@ 2011-02-11  2:26                   ` 李朝明
  2011-02-11 10:22                     ` Stanislaw Gruszka
  0 siblings, 1 reply; 12+ messages in thread
From: 李朝明 @ 2011-02-11  2:26 UTC (permalink / raw)
  To: 'Stanislaw Gruszka'
  Cc: 'Johannes Berg', 'Larry Finger',
	'John W Linville',
	linux-wireless, '冯春燕',
	'熊光安'

Dear Stanislaw:

	I find for cisco 1252 11N mode bandwith-20,
ieee80211_sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40
	was wrong in bss_info_changed, I have to check 20/40 MHZ based on
hw->conf.channel_type.

	All other APs will be ok, So may be it's AP IE's issue, But I think
mac80211 should also check hw->conf.channel_type
	before set ieee80211_sta->ht_cap.cap &
IEEE80211_HT_CAP_SUP_WIDTH_20_40.

Thank you!
 
lizhaoming
-- 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC] mac80211: cisco 1252 HT bw20, sta->ht_cap.cap bw is wrong
  2011-02-11  2:26                   ` [RFC] mac80211: cisco 1252 HT bw20, sta->ht_cap.cap bw is wrong 李朝明
@ 2011-02-11 10:22                     ` Stanislaw Gruszka
  2011-02-12  3:32                       ` [RFC] mac80211: mac80211's null packet issue 李朝明
  0 siblings, 1 reply; 12+ messages in thread
From: Stanislaw Gruszka @ 2011-02-11 10:22 UTC (permalink / raw)
  To: 李朝明
  Cc: 'Johannes Berg', 'Larry Finger',
	'John W Linville',
	linux-wireless, '冯春燕',
	'熊光安'

On Fri, Feb 11, 2011 at 10:26:13AM +0800, 李朝明 wrote:
> Dear Stanislaw:
"Hi" would be enough ;-)

> 	I find for cisco 1252 11N mode bandwith-20,
> ieee80211_sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40
> 	was wrong in bss_info_changed, I have to check 20/40 MHZ based on
> hw->conf.channel_type.
> 
> 	All other APs will be ok, So may be it's AP IE's issue, But I think
> mac80211 should also check hw->conf.channel_type
> 	before set ieee80211_sta->ht_cap.cap &
> IEEE80211_HT_CAP_SUP_WIDTH_20_40.
Perhaps you could send patch with fix?

Stanislaw

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [RFC] mac80211: mac80211's null packet issue.
  2011-02-11 10:22                     ` Stanislaw Gruszka
@ 2011-02-12  3:32                       ` 李朝明
  2011-02-14 10:16                         ` Johannes Berg
  0 siblings, 1 reply; 12+ messages in thread
From: 李朝明 @ 2011-02-12  3:32 UTC (permalink / raw)
  To: 'Stanislaw Gruszka'
  Cc: 'Johannes Berg', 'Larry Finger',
	'John W Linville',
	linux-wireless, '冯春燕',
	'熊光安'

Dear Stanislaw & John:

follwing is the Call Trace issue I found:

====================
Feb 12 10:58:28 lzm-laptop kernel: [243855.472129]
rtl8192de-0:rtl92d_phy_switch_wirelessband():<0-0> ====>2.4G
Feb 12 10:58:28 lzm-laptop kernel: [243855.475867] pm = 0 null have been
send
Feb 12 10:58:29 lzm-laptop kernel: [243855.672881] pm = 1 null have been
send
Feb 12 10:58:29 lzm-laptop kernel: [243855.733668] =========> rtl_op_config
wide_chan:56
Feb 12 10:58:29 lzm-laptop kernel: [243855.733741]
rtl8192de-0:rtl92d_phy_switch_wirelessband():<0-0> ====>5G
Feb 12 10:58:30 lzm-laptop kernel: [243856.621680] =========> rtl_op_config
wide_chan:149
Feb 12 10:58:30 lzm-laptop kernel: [243856.621754]
rtl8192de-0:rtl92d_phy_switch_wirelessband():<0-0> ====>5G
Feb 12 10:58:30 lzm-laptop kernel: [243856.660040] ------------[ cut here
]------------
Feb 12 10:58:30 lzm-laptop kernel: [243856.660067] WARNING: at
/home/mac80211_2.6.37/tx.c:656 invoke_tx_handlers+0xd46/0xf80 [mac80211]()
Feb 12 10:58:30 lzm-laptop kernel: [243856.660072] Hardware name: A8Sc

Feb 12 10:58:30 lzm-laptop kernel: [243856.660077] wlan0: Dropped data frame
as no usable bitrate found while scanning and associated. Target station:
00:1c:f0:c0:ab:bd on 5 GHz band
Feb 12 10:58:30 lzm-laptop kernel: [243856.660081] Modules linked in:
rtl8192de rtl8192se rtl8192ce rtlwifi mac80211 cfg80211 nls_iso8859_1
nls_cp437 vfat fat usb_storage aes_i586 aes_generic arc4 binfmt_misc rfcomm
ppdev sco bridge stp bnep l2cap snd_hda_codec_si3054 snd_hda_codec_realtek
snd_hda_intel snd_hda_codec snd_hwdep joydev snd_pcm snd_seq_midi
snd_rawmidi snd_seq_midi_event snd_seq snd_timer snd_seq_device nouveau ttm
drm_kms_helper drm snd intel_agp i2c_algo_bit asus_laptop sparse_keymap
intel_gtt agpgart uvcvideo psmouse videodev r852 serio_raw video btusb
soundcore snd_page_alloc output v4l1_compat irda crc_ccitt sm_common nand
nand_ids nand_ecc sdhci_pci sdhci mtd led_class bluetooth lp parport ahci
r8169 libahci mii [last unloaded: mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660195] Pid: 5873, comm:
kworker/u:2 Tainted: G        W   2.6.37-020637rc1-generic #201011020905
Feb 12 10:58:30 lzm-laptop kernel: [243856.660199] Call Trace:
Feb 12 10:58:30 lzm-laptop kernel: [243856.660220]  [<fbff21a6>] ?
invoke_tx_handlers+0xd46/0xf80 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660241]  [<fbff21a6>] ?
invoke_tx_handlers+0xd46/0xf80 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660252]  [<c014f7c1>]
warn_slowpath_common+0x81/0xa0
Feb 12 10:58:30 lzm-laptop kernel: [243856.660272]  [<fbff21a6>] ?
invoke_tx_handlers+0xd46/0xf80 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660282]  [<c014f883>]
warn_slowpath_fmt+0x33/0x40
Feb 12 10:58:30 lzm-laptop kernel: [243856.660294]  [<fbff21a6>]
invoke_tx_handlers+0xd46/0xf80 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660307]  [<fbff2440>]
ieee80211_tx+0x60/0x1b0 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660312]  [<c0505766>] ?
pskb_expand_head+0x56/0x1b0
Feb 12 10:58:30 lzm-laptop kernel: [243856.660315]  [<c05058ac>] ?
pskb_expand_head+0x19c/0x1b0
Feb 12 10:58:30 lzm-laptop kernel: [243856.660328]  [<fbff2638>]
ieee80211_xmit+0xa8/0x1f0 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660332]  [<c0505177>] ?
__alloc_skb+0x77/0x100
Feb 12 10:58:30 lzm-laptop kernel: [243856.660344]  [<fbff0c9d>] ?
ieee80211_nullfunc_get+0x5d/0x140 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660356]  [<fbff27c5>]
ieee80211_tx_skb+0x45/0x60 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660367]  [<fbfe299f>]
ieee80211_send_nullfunc+0x3f/0x60 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660377]  [<fbfe2a49>]
ieee80211_dynamic_ps_enable_work+0x89/0x90 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660383]  [<c0168819>]
process_one_work+0xd9/0x330
Feb 12 10:58:30 lzm-laptop kernel: [243856.660393]  [<fbfe29c0>] ?
ieee80211_dynamic_ps_enable_work+0x0/0x90 [mac80211]
Feb 12 10:58:30 lzm-laptop kernel: [243856.660397]  [<c0169413>]
worker_thread+0xb3/0x210
Feb 12 10:58:30 lzm-laptop kernel: [243856.660401]  [<c0169360>] ?
worker_thread+0x0/0x210
Feb 12 10:58:30 lzm-laptop kernel: [243856.660405]  [<c016c935>]
kthread+0x75/0x80
Feb 12 10:58:30 lzm-laptop kernel: [243856.660409]  [<c016c8c0>] ?
kthread+0x0/0x80
Feb 12 10:58:30 lzm-laptop kernel: [243856.660413]  [<c01032fe>]
kernel_thread_helper+0x6/0x10
Feb 12 10:58:30 lzm-laptop kernel: [243856.660415] ---[ end trace
31d359aae6ce5643 ]---
Feb 12 10:58:30 lzm-laptop kernel: [243856.660419] ===========> rtl_get_rate
rix:0 isnull:1 ps_flag:1
Feb 12 10:58:30 lzm-laptop kernel: [243856.660421] rtlwifi: 
Feb 12 10:58:30 lzm-laptop kernel: [243856.660423] In process "kworker/u:2"
(pid 5873):skb 
Feb 12 10:58:30 lzm-laptop kernel: [243856.660426] 48 11 00 00  00 1C F0 C0
AB BD 00 E0  4C 92 01 BA  
Feb 12 10:58:30 lzm-laptop kernel: [243856.660437] 00 1C F0 C0  AB BD 00 00

Feb 12 10:58:30 lzm-laptop kernel: [243856.660443] 
Feb 12 10:58:30 lzm-laptop kernel: [243856.660512] pm = 1 null have been
send
Feb 12 10:58:30 lzm-laptop kernel: [243856.797670] =========> rtl_op_config
wide_chan:9
Feb 12 10:58:30 lzm-laptop kernel: [243856.797744]
rtl8192de-0:rtl92d_phy_switch_wirelessband():<0-0> ====>2.4G
Feb 12 10:58:30 lzm-laptop kernel: [243856.801563] pm = 0 null have been
send
Feb 12 10:58:30 lzm-laptop kernel: [243856.900126] pm = 1 null have been
send
Feb 12 10:58:30 lzm-laptop kernel: [243857.000119] pm = 1 null have been
send
Feb 12 10:58:30 lzm-laptop kernel: [243857.061661] =========> rtl_op_config
wide_chan:153
====================

I find the root cause is: after I linked AP in 9 channel(2.4G), I use iwlist
wlan0 scan
when driverf offchannel to 5G 149 channel, a null(pm=1) packet was send ,
and then call trace
happend because "WARN" in "ieee80211_tx_h_rate_ctrl" .
Below are corresponding code:
ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
{
	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
	

	/*
	 * Lets not bother rate control if we're associated and cannot
	 * talk to the sta. This should not happen (but this indeed
happend).
	 */
	if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) &&
		 (sta_flags & WLAN_STA_ASSOC) &&
		 !rate_usable_index_exists(sband, &tx->sta->sta),
		 "%s: Dropped data frame as no usable bitrate found while "
		 "scanning and associated. Target station: "
		 "%pM on %d GHz band\n",
		 tx->sdata->name, hdr->addr1,
		 tx->channel->band ? 5 : 2))
		return TX_DROP;

}

And I also find this issue happens when I open power save:
	hw->flags = IEEE80211_HW_SIGNAL_DBM |
	    IEEE80211_HW_RX_INCLUDES_FCS |
	    IEEE80211_HW_BEACON_FILTER |
	    IEEE80211_HW_AMPDU_AGGREGATION |
	    IEEE80211_HW_REPORTS_TX_ACK_STATUS | 
	    IEEE80211_HW_SUPPORTS_PS |
	    IEEE80211_HW_PS_NULLFUNC_STACK |
	    /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
	   0;
if I close power save like follwing this issue will never happen:
	hw->flags = IEEE80211_HW_SIGNAL_DBM |
	    IEEE80211_HW_RX_INCLUDES_FCS |
	    IEEE80211_HW_BEACON_FILTER |
	    IEEE80211_HW_AMPDU_AGGREGATION |
	    IEEE80211_HW_REPORTS_TX_ACK_STATUS | 
	    /* IEEE80211_HW_SUPPORTS_PS | */
	    /* IEEE80211_HW_PS_NULLFUNC_STACK | */
	    /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
	   0;

So, is any body familiar with mac80211 power save can help ?
Thank you!

lizhaoming
--


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC] mac80211: mac80211's null packet issue.
  2011-02-12  3:32                       ` [RFC] mac80211: mac80211's null packet issue 李朝明
@ 2011-02-14 10:16                         ` Johannes Berg
  0 siblings, 0 replies; 12+ messages in thread
From: Johannes Berg @ 2011-02-14 10:16 UTC (permalink / raw)
  To: 李朝明
  Cc: 'Stanislaw Gruszka', 'Larry Finger',
	'John W Linville',
	linux-wireless, '冯春燕',
	'熊光安'

This thread has me confused. Powersave issue and HT20 issue at the same
time??

I'm skipping this -- if you want any input from me on either question
please repost them more clearly and try not to intermingle the thread
(changing the subject is *not* enough).

johannes


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-02-14 10:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-06 18:44 [PATCH 2/6] rtlwifi: Add usb driver Larry Finger
2011-02-07 15:07 ` Stanislaw Gruszka
2011-02-07 15:12 ` Stanislaw Gruszka
2011-02-09  1:58   ` about Mac80211 scan issue 李朝明
2011-02-09 10:54     ` Stanislaw Gruszka
     [not found]       ` <B8DE8263FD784AC082CFDB7E9269BAEA@realsil.com.cn>
2011-02-10  7:41         ` 答复: " Stanislaw Gruszka
     [not found]           ` <39A39FA0AD1A481480DE0BD469AAA79E@realsil.com.cn>
2011-02-10  9:50             ` 答复: " Stanislaw Gruszka
     [not found]               ` <86D43C3FD69641C38E7144E721BCC5A6@realsil.com.cn>
2011-02-10 11:37                 ` 答复: 答复: 答复: about Mac80211scan issue Stanislaw Gruszka
2011-02-11  2:26                   ` [RFC] mac80211: cisco 1252 HT bw20, sta->ht_cap.cap bw is wrong 李朝明
2011-02-11 10:22                     ` Stanislaw Gruszka
2011-02-12  3:32                       ` [RFC] mac80211: mac80211's null packet issue 李朝明
2011-02-14 10:16                         ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).