| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | /******************************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-01-07 20:46:43 -06:00
										 |  |  |  * Copyright(c) 2009-2012  Realtek Corporation. | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Larry Finger <Larry.Finger@lwfinger.net> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../wifi.h"
 | 
					
						
							|  |  |  | #include "../pci.h"
 | 
					
						
							|  |  |  | #include "../base.h"
 | 
					
						
							| 
									
										
										
										
											2011-02-23 10:24:58 -06:00
										 |  |  | #include "../rtl8192ce/reg.h"
 | 
					
						
							|  |  |  | #include "../rtl8192ce/def.h"
 | 
					
						
							|  |  |  | #include "fw_common.h"
 | 
					
						
							| 
									
										
										
										
											2012-01-27 13:59:25 -06:00
										 |  |  | #include <linux/export.h>
 | 
					
						
							| 
									
										
										
										
											2012-04-13 13:57:43 -05:00
										 |  |  | #include <linux/kmemleak.h>
 | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void _rtl92c_enable_fw_download(struct ieee80211_hw *hw, bool enable) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CU) { | 
					
						
							|  |  |  | 		u32 value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL); | 
					
						
							|  |  |  | 		if (enable) | 
					
						
							|  |  |  | 			value32 |= MCUFWDL_EN; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			value32 &= ~MCUFWDL_EN; | 
					
						
							|  |  |  | 		rtl_write_dword(rtlpriv, REG_MCUFWDL, value32); | 
					
						
							|  |  |  | 	} else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CE) { | 
					
						
							|  |  |  | 		u8 tmp; | 
					
						
							|  |  |  | 		if (enable) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1); | 
					
						
							|  |  |  | 			rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, | 
					
						
							|  |  |  | 				       tmp | 0x04); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL); | 
					
						
							|  |  |  | 			rtl_write_byte(rtlpriv, REG_MCUFWDL, tmp | 0x01); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL + 2); | 
					
						
							|  |  |  | 			rtl_write_byte(rtlpriv, REG_MCUFWDL + 2, tmp & 0xf7); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL); | 
					
						
							|  |  |  | 			rtl_write_byte(rtlpriv, REG_MCUFWDL, tmp & 0xfe); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			rtl_write_byte(rtlpriv, REG_MCUFWDL + 1, 0x00); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:43 -06:00
										 |  |  | static void rtl_block_fw_writeN(struct ieee80211_hw *hw, const u8 *buffer, | 
					
						
							|  |  |  | 				u32 size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	u32 blockSize = REALTEK_USB_VENQT_MAX_BUF_SIZE - 20; | 
					
						
							|  |  |  | 	u8 *bufferPtr = (u8 *) buffer; | 
					
						
							|  |  |  | 	u32 i, offset, blockCount, remainSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	blockCount = size / blockSize; | 
					
						
							|  |  |  | 	remainSize = size % blockSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < blockCount; i++) { | 
					
						
							|  |  |  | 		offset = i * blockSize; | 
					
						
							|  |  |  | 		rtlpriv->io.writeN_sync(rtlpriv, | 
					
						
							|  |  |  | 					(FW_8192C_START_ADDRESS + offset), | 
					
						
							|  |  |  | 					(void *)(bufferPtr + offset), | 
					
						
							|  |  |  | 					blockSize); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (remainSize) { | 
					
						
							|  |  |  | 		offset = blockCount * blockSize; | 
					
						
							|  |  |  | 		rtlpriv->io.writeN_sync(rtlpriv, | 
					
						
							|  |  |  | 					(FW_8192C_START_ADDRESS + offset), | 
					
						
							|  |  |  | 					(void *)(bufferPtr + offset), | 
					
						
							|  |  |  | 					remainSize); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | static void _rtl92c_fw_block_write(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				   const u8 *buffer, u32 size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	u32 blockSize = sizeof(u32); | 
					
						
							|  |  |  | 	u8 *bufferPtr = (u8 *) buffer; | 
					
						
							|  |  |  | 	u32 *pu4BytePtr = (u32 *) buffer; | 
					
						
							|  |  |  | 	u32 i, offset, blockCount, remainSize; | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 	u32 data; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:43 -06:00
										 |  |  | 	if (rtlpriv->io.writeN_sync) { | 
					
						
							|  |  |  | 		rtl_block_fw_writeN(hw, buffer, size); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	blockCount = size / blockSize; | 
					
						
							|  |  |  | 	remainSize = size % blockSize; | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 	if (remainSize) { | 
					
						
							|  |  |  | 		/* the last word is < 4 bytes - pad it with zeros */ | 
					
						
							|  |  |  | 		for (i = 0; i < 4 - remainSize; i++) | 
					
						
							|  |  |  | 			*(bufferPtr + size + i) = 0; | 
					
						
							|  |  |  | 		blockCount++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < blockCount; i++) { | 
					
						
							|  |  |  | 		offset = i * blockSize; | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 		/* for big-endian platforms, the firmware data need to be byte
 | 
					
						
							|  |  |  | 		 * swapped as it was read as a byte string and will be written | 
					
						
							|  |  |  | 		 * as 32-bit dwords and byte swapped when written | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		data = le32_to_cpu(*(__le32 *)(pu4BytePtr + i)); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		rtl_write_dword(rtlpriv, (FW_8192C_START_ADDRESS + offset), | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 				data); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl92c_fw_page_write(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				  u32 page, const u8 *buffer, u32 size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	u8 value8; | 
					
						
							|  |  |  | 	u8 u8page = (u8) (page & 0x07); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	value8 = (rtl_read_byte(rtlpriv, REG_MCUFWDL + 2) & 0xF8) | u8page; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtl_write_byte(rtlpriv, (REG_MCUFWDL + 2), value8); | 
					
						
							|  |  |  | 	_rtl92c_fw_block_write(hw, buffer, size); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl92c_fill_dummy(u8 *pfwbuf, u32 *pfwlen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 fwlen = *pfwlen; | 
					
						
							|  |  |  | 	u8 remain = (u8) (fwlen % 4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	remain = (remain == 0) ? 0 : (4 - remain); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (remain > 0) { | 
					
						
							|  |  |  | 		pfwbuf[fwlen] = 0; | 
					
						
							|  |  |  | 		fwlen++; | 
					
						
							|  |  |  | 		remain--; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*pfwlen = fwlen; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl92c_write_fw(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 			     enum version_8192c version, u8 *buffer, u32 size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
					
						
							| 
									
										
										
										
											2012-06-04 12:44:17 +00:00
										 |  |  | 	u8 *bufferPtr = buffer; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 	RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE, "FW size is %d bytes\n", size); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:34:03 -06:00
										 |  |  | 	if (IS_CHIP_VER_B(version)) { | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		u32 pageNums, remainSize; | 
					
						
							|  |  |  | 		u32 page, offset; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-11 14:34:03 -06:00
										 |  |  | 		if (IS_HARDWARE_TYPE_8192CE(rtlhal)) | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			_rtl92c_fill_dummy(bufferPtr, &size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		pageNums = size / FW_8192C_PAGE_SIZE; | 
					
						
							|  |  |  | 		remainSize = size % FW_8192C_PAGE_SIZE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (pageNums > 4) { | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "Page numbers should not greater then 4\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (page = 0; page < pageNums; page++) { | 
					
						
							|  |  |  | 			offset = page * FW_8192C_PAGE_SIZE; | 
					
						
							|  |  |  | 			_rtl92c_fw_page_write(hw, page, (bufferPtr + offset), | 
					
						
							|  |  |  | 					      FW_8192C_PAGE_SIZE); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (remainSize) { | 
					
						
							|  |  |  | 			offset = pageNums * FW_8192C_PAGE_SIZE; | 
					
						
							|  |  |  | 			page = pageNums; | 
					
						
							|  |  |  | 			_rtl92c_fw_page_write(hw, page, (bufferPtr + offset), | 
					
						
							|  |  |  | 					      remainSize); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		_rtl92c_fw_block_write(hw, buffer, size); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int _rtl92c_fw_free_to_go(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	u32 counter = 0; | 
					
						
							|  |  |  | 	u32 value32; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL); | 
					
						
							|  |  |  | 	} while ((counter++ < FW_8192C_POLLING_TIMEOUT_COUNT) && | 
					
						
							|  |  |  | 		 (!(value32 & FWDL_ChkSum_rpt))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (counter >= FW_8192C_POLLING_TIMEOUT_COUNT) { | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "chksum report faill ! REG_MCUFWDL:0x%08x\n", value32); | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 		return -EIO; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 		 "Checksum report OK ! REG_MCUFWDL:0x%08x\n", value32); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL); | 
					
						
							|  |  |  | 	value32 |= MCUFWDL_RDY; | 
					
						
							|  |  |  | 	value32 &= ~WINTINI_RDY; | 
					
						
							|  |  |  | 	rtl_write_dword(rtlpriv, REG_MCUFWDL, value32); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	counter = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL); | 
					
						
							|  |  |  | 		if (value32 & WINTINI_RDY) { | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "Polling FW ready success!! REG_MCUFWDL:0x%08x\n", | 
					
						
							|  |  |  | 				 value32); | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		mdelay(FW_8192C_POLLING_DELAY); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} while (counter++ < FW_8192C_POLLING_TIMEOUT_COUNT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 		 "Polling FW ready fail!! REG_MCUFWDL:0x%08x\n", value32); | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 	return -EIO; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int rtl92c_download_fw(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct rtl92c_firmware_header *pfwheader; | 
					
						
							|  |  |  | 	u8 *pfwdata; | 
					
						
							|  |  |  | 	u32 fwsize; | 
					
						
							|  |  |  | 	enum version_8192c version = rtlhal->version; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-30 09:54:49 -06:00
										 |  |  | 	if (rtlpriv->max_fw_size == 0 || !rtlhal->pfirmware) | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pfwheader = (struct rtl92c_firmware_header *)rtlhal->pfirmware; | 
					
						
							| 
									
										
										
										
											2012-06-04 12:44:17 +00:00
										 |  |  | 	pfwdata = rtlhal->pfirmware; | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 	fwsize = rtlhal->fwsize; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (IS_FW_HEADER_EXIST(pfwheader)) { | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_FW, DBG_DMESG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Firmware Version(%d), Signature(%#x),Size(%d)\n", | 
					
						
							| 
									
										
										
										
											2011-11-17 12:14:44 -06:00
										 |  |  | 			 le16_to_cpu(pfwheader->version), | 
					
						
							|  |  |  | 			 le16_to_cpu(pfwheader->signature), | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 (uint)sizeof(struct rtl92c_firmware_header)); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		pfwdata = pfwdata + sizeof(struct rtl92c_firmware_header); | 
					
						
							|  |  |  | 		fwsize = fwsize - sizeof(struct rtl92c_firmware_header); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_rtl92c_enable_fw_download(hw, true); | 
					
						
							|  |  |  | 	_rtl92c_write_fw(hw, version, pfwdata, fwsize); | 
					
						
							|  |  |  | 	_rtl92c_enable_fw_download(hw, false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 	if (_rtl92c_fw_free_to_go(hw)) { | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Firmware is not ready to run!\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_FW, DBG_TRACE, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Firmware is ready to run!\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-23 10:24:58 -06:00
										 |  |  | EXPORT_SYMBOL(rtl92c_download_fw); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static bool _rtl92c_check_fw_read_last_h2c(struct ieee80211_hw *hw, u8 boxnum) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	u8 val_hmetfr, val_mcutst_1; | 
					
						
							|  |  |  | 	bool result = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	val_hmetfr = rtl_read_byte(rtlpriv, REG_HMETFR); | 
					
						
							|  |  |  | 	val_mcutst_1 = rtl_read_byte(rtlpriv, (REG_MCUTST_1 + boxnum)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (((val_hmetfr >> boxnum) & BIT(0)) == 0 && val_mcutst_1 == 0) | 
					
						
							|  |  |  | 		result = true; | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void _rtl92c_fill_h2c_command(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 			      u8 element_id, u32 cmd_len, u8 *p_cmdbuffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
					
						
							|  |  |  | 	u8 boxnum; | 
					
						
							| 
									
										
										
										
											2011-04-13 21:00:02 -05:00
										 |  |  | 	u16 box_reg = 0, box_extreg = 0; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	u8 u1b_tmp; | 
					
						
							|  |  |  | 	bool isfw_read = false; | 
					
						
							| 
									
										
										
										
											2012-09-01 10:31:09 -07:00
										 |  |  | 	bool bwrite_success = false; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	u8 wait_h2c_limmit = 100; | 
					
						
							|  |  |  | 	u8 wait_writeh2c_limmit = 100; | 
					
						
							|  |  |  | 	u8 boxcontent[4], boxextcontent[2]; | 
					
						
							|  |  |  | 	u32 h2c_waitcounter = 0; | 
					
						
							|  |  |  | 	unsigned long flag; | 
					
						
							|  |  |  | 	u8 idx; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 	RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, "come in\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (true) { | 
					
						
							|  |  |  | 		spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag); | 
					
						
							| 
									
										
										
										
											2011-02-19 16:28:57 -06:00
										 |  |  | 		if (rtlhal->h2c_setinprogress) { | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "H2C set in progress! Wait to set..element_id(%d)\n", | 
					
						
							|  |  |  | 				 element_id); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-19 16:28:57 -06:00
										 |  |  | 			while (rtlhal->h2c_setinprogress) { | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 				spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, | 
					
						
							|  |  |  | 						       flag); | 
					
						
							|  |  |  | 				h2c_waitcounter++; | 
					
						
							|  |  |  | 				RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 					 "Wait 100 us (%d times)...\n", | 
					
						
							|  |  |  | 					 h2c_waitcounter); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 				udelay(100); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (h2c_waitcounter > 1000) | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 				spin_lock_irqsave(&rtlpriv->locks.h2c_lock, | 
					
						
							|  |  |  | 						  flag); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2011-02-19 16:28:57 -06:00
										 |  |  | 			rtlhal->h2c_setinprogress = true; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-01 10:31:09 -07:00
										 |  |  | 	while (!bwrite_success) { | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		wait_writeh2c_limmit--; | 
					
						
							|  |  |  | 		if (wait_writeh2c_limmit == 0) { | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "Write H2C fail because no trigger for FW INT!\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		boxnum = rtlhal->last_hmeboxnum; | 
					
						
							|  |  |  | 		switch (boxnum) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 			box_reg = REG_HMEBOX_0; | 
					
						
							|  |  |  | 			box_extreg = REG_HMEBOX_EXT_0; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			box_reg = REG_HMEBOX_1; | 
					
						
							|  |  |  | 			box_extreg = REG_HMEBOX_EXT_1; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							|  |  |  | 			box_reg = REG_HMEBOX_2; | 
					
						
							|  |  |  | 			box_extreg = REG_HMEBOX_EXT_2; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 3: | 
					
						
							|  |  |  | 			box_reg = REG_HMEBOX_3; | 
					
						
							|  |  |  | 			box_extreg = REG_HMEBOX_EXT_3; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "switch case not processed\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		isfw_read = _rtl92c_check_fw_read_last_h2c(hw, boxnum); | 
					
						
							|  |  |  | 		while (!isfw_read) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			wait_h2c_limmit--; | 
					
						
							|  |  |  | 			if (wait_h2c_limmit == 0) { | 
					
						
							|  |  |  | 				RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 					 "Waiting too long for FW read clear HMEBox(%d)!\n", | 
					
						
							|  |  |  | 					 boxnum); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			udelay(10); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			isfw_read = _rtl92c_check_fw_read_last_h2c(hw, boxnum); | 
					
						
							|  |  |  | 			u1b_tmp = rtl_read_byte(rtlpriv, 0x1BF); | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "Waiting for FW read clear HMEBox(%d)!!! 0x1BF = %2x\n", | 
					
						
							|  |  |  | 				 boxnum, u1b_tmp); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!isfw_read) { | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "Write H2C register BOX[%d] fail!!!!! Fw do not read\n", | 
					
						
							|  |  |  | 				 boxnum); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		memset(boxcontent, 0, sizeof(boxcontent)); | 
					
						
							|  |  |  | 		memset(boxextcontent, 0, sizeof(boxextcontent)); | 
					
						
							|  |  |  | 		boxcontent[0] = element_id; | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Write element_id box_reg(%4x) = %2x\n", | 
					
						
							|  |  |  | 			 box_reg, element_id); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		switch (cmd_len) { | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			boxcontent[0] &= ~(BIT(7)); | 
					
						
							|  |  |  | 			memcpy((u8 *) (boxcontent) + 1, | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 			       p_cmdbuffer, 1); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (idx = 0; idx < 4; idx++) { | 
					
						
							|  |  |  | 				rtl_write_byte(rtlpriv, box_reg + idx, | 
					
						
							|  |  |  | 					       boxcontent[idx]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							|  |  |  | 			boxcontent[0] &= ~(BIT(7)); | 
					
						
							|  |  |  | 			memcpy((u8 *) (boxcontent) + 1, | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 			       p_cmdbuffer, 2); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (idx = 0; idx < 4; idx++) { | 
					
						
							|  |  |  | 				rtl_write_byte(rtlpriv, box_reg + idx, | 
					
						
							|  |  |  | 					       boxcontent[idx]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 3: | 
					
						
							|  |  |  | 			boxcontent[0] &= ~(BIT(7)); | 
					
						
							|  |  |  | 			memcpy((u8 *) (boxcontent) + 1, | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 			       p_cmdbuffer, 3); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (idx = 0; idx < 4; idx++) { | 
					
						
							|  |  |  | 				rtl_write_byte(rtlpriv, box_reg + idx, | 
					
						
							|  |  |  | 					       boxcontent[idx]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 4: | 
					
						
							|  |  |  | 			boxcontent[0] |= (BIT(7)); | 
					
						
							|  |  |  | 			memcpy((u8 *) (boxextcontent), | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 			       p_cmdbuffer, 2); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			memcpy((u8 *) (boxcontent) + 1, | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 			       p_cmdbuffer + 2, 2); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (idx = 0; idx < 2; idx++) { | 
					
						
							|  |  |  | 				rtl_write_byte(rtlpriv, box_extreg + idx, | 
					
						
							|  |  |  | 					       boxextcontent[idx]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (idx = 0; idx < 4; idx++) { | 
					
						
							|  |  |  | 				rtl_write_byte(rtlpriv, box_reg + idx, | 
					
						
							|  |  |  | 					       boxcontent[idx]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 5: | 
					
						
							|  |  |  | 			boxcontent[0] |= (BIT(7)); | 
					
						
							|  |  |  | 			memcpy((u8 *) (boxextcontent), | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 			       p_cmdbuffer, 2); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			memcpy((u8 *) (boxcontent) + 1, | 
					
						
							| 
									
										
										
										
											2011-03-27 16:19:57 -05:00
										 |  |  | 			       p_cmdbuffer + 2, 3); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (idx = 0; idx < 2; idx++) { | 
					
						
							|  |  |  | 				rtl_write_byte(rtlpriv, box_extreg + idx, | 
					
						
							|  |  |  | 					       boxextcontent[idx]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (idx = 0; idx < 4; idx++) { | 
					
						
							|  |  |  | 				rtl_write_byte(rtlpriv, box_reg + idx, | 
					
						
							|  |  |  | 					       boxcontent[idx]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 				 "switch case not processed\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-01 10:31:09 -07:00
										 |  |  | 		bwrite_success = true; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		rtlhal->last_hmeboxnum = boxnum + 1; | 
					
						
							|  |  |  | 		if (rtlhal->last_hmeboxnum == 4) | 
					
						
							|  |  |  | 			rtlhal->last_hmeboxnum = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "pHalData->last_hmeboxnum  = %d\n", | 
					
						
							|  |  |  | 			 rtlhal->last_hmeboxnum); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag); | 
					
						
							| 
									
										
										
										
											2011-02-19 16:28:57 -06:00
										 |  |  | 	rtlhal->h2c_setinprogress = false; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 	RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, "go out\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void rtl92c_fill_h2c_cmd(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 			 u8 element_id, u32 cmd_len, u8 *p_cmdbuffer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 tmp_cmdbuf[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memset(tmp_cmdbuf, 0, 8); | 
					
						
							|  |  |  | 	memcpy(tmp_cmdbuf, p_cmdbuffer, cmd_len); | 
					
						
							|  |  |  | 	_rtl92c_fill_h2c_command(hw, element_id, cmd_len, (u8 *)&tmp_cmdbuf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-23 10:24:58 -06:00
										 |  |  | EXPORT_SYMBOL(rtl92c_fill_h2c_cmd); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | void rtl92c_firmware_selfreset(struct ieee80211_hw *hw) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8 u1b_tmp; | 
					
						
							|  |  |  | 	u8 delay = 100; | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtl_write_byte(rtlpriv, REG_HMETFR + 3, 0x20); | 
					
						
							|  |  |  | 	u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (u1b_tmp & BIT(2)) { | 
					
						
							|  |  |  | 		delay--; | 
					
						
							|  |  |  | 		if (delay == 0) { | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:43 -08:00
										 |  |  | 			RT_ASSERT(false, "8051 reset fail\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		udelay(50); | 
					
						
							|  |  |  | 		u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-23 10:24:58 -06:00
										 |  |  | EXPORT_SYMBOL(rtl92c_firmware_selfreset); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | void rtl92c_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	u8 u1_h2c_set_pwrmode[3] = {0}; | 
					
						
							|  |  |  | 	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 	RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, "FW LPS mode = %d\n", mode); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	SET_H2CCMD_PWRMODE_PARM_MODE(u1_h2c_set_pwrmode, mode); | 
					
						
							| 
									
										
										
										
											2013-03-24 22:06:40 -05:00
										 |  |  | 	SET_H2CCMD_PWRMODE_PARM_SMART_PS(u1_h2c_set_pwrmode, | 
					
						
							|  |  |  | 					 (rtlpriv->mac80211.p2p) ? | 
					
						
							|  |  |  | 					 ppsc->smart_ps : 1); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	SET_H2CCMD_PWRMODE_PARM_BCN_PASS_TIME(u1_h2c_set_pwrmode, | 
					
						
							|  |  |  | 					      ppsc->reg_max_lps_awakeintvl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:40 -08:00
										 |  |  | 		      "rtl92c_set_fw_rsvdpagepkt(): u1_h2c_set_pwrmode", | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		      u1_h2c_set_pwrmode, 3); | 
					
						
							|  |  |  | 	rtl92c_fill_h2c_cmd(hw, H2C_SETPWRMODE, 3, u1_h2c_set_pwrmode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-23 10:24:58 -06:00
										 |  |  | EXPORT_SYMBOL(rtl92c_set_fw_pwrmode_cmd); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | static bool _rtl92c_cmd_send_packet(struct ieee80211_hw *hw, | 
					
						
							|  |  |  | 				struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); | 
					
						
							|  |  |  | 	struct rtl8192_tx_ring *ring; | 
					
						
							|  |  |  | 	struct rtl_tx_desc *pdesc; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	struct sk_buff *pskb = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ring = &rtlpci->tx_ring[BEACON_QUEUE]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pskb = __skb_dequeue(&ring->queue); | 
					
						
							| 
									
										
										
										
											2012-08-28 21:12:00 +08:00
										 |  |  | 	kfree_skb(pskb); | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pdesc = &ring->desc[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->fill_tx_cmddesc(hw, (u8 *) pdesc, 1, 1, skb); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	__skb_queue_tail(&ring->queue, skb); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtlpriv->cfg->ops->tx_polling(hw, BEACON_QUEUE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | #define BEACON_PG		0 /*->1*/
 | 
					
						
							|  |  |  | #define PSPOLL_PG		2
 | 
					
						
							|  |  |  | #define NULL_PG			3
 | 
					
						
							|  |  |  | #define PROBERSP_PG		4 /*->5*/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define TOTAL_RESERVED_PKT_LEN	768
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u8 reserved_page_packet[TOTAL_RESERVED_PKT_LEN] = { | 
					
						
							|  |  |  | 	/* page 0 beacon */ | 
					
						
							|  |  |  | 	0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, | 
					
						
							|  |  |  | 	0xFF, 0xFF, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42, | 
					
						
							|  |  |  | 	0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x50, 0x08, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69, | 
					
						
							|  |  |  | 	0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C, | 
					
						
							|  |  |  | 	0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96, | 
					
						
							|  |  |  | 	0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A, | 
					
						
							|  |  |  | 	0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C, | 
					
						
							|  |  |  | 	0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18, | 
					
						
							|  |  |  | 	0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02, | 
					
						
							|  |  |  | 	0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* page 1 beacon */ | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x10, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x10, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* page 2  ps-poll */ | 
					
						
							|  |  |  | 	0xA4, 0x10, 0x01, 0xC0, 0x00, 0x40, 0x10, 0x10, | 
					
						
							|  |  |  | 	0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x18, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, | 
					
						
							|  |  |  | 	0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* page 3  null */ | 
					
						
							|  |  |  | 	0x48, 0x01, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10, | 
					
						
							|  |  |  | 	0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42, | 
					
						
							|  |  |  | 	0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x72, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, | 
					
						
							|  |  |  | 	0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* page 4  probe_resp */ | 
					
						
							|  |  |  | 	0x50, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10, | 
					
						
							|  |  |  | 	0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42, | 
					
						
							|  |  |  | 	0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x9E, 0x46, 0x15, 0x32, 0x27, 0xF2, 0x2D, 0x00, | 
					
						
							|  |  |  | 	0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69, | 
					
						
							|  |  |  | 	0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C, | 
					
						
							|  |  |  | 	0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96, | 
					
						
							|  |  |  | 	0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A, | 
					
						
							|  |  |  | 	0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C, | 
					
						
							|  |  |  | 	0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18, | 
					
						
							|  |  |  | 	0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02, | 
					
						
							|  |  |  | 	0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* page 5  probe_resp */ | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool dl_finished) | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct sk_buff *skb = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	u32 totalpacketlen; | 
					
						
							|  |  |  | 	bool rtstatus; | 
					
						
							|  |  |  | 	u8 u1RsvdPageLoc[3] = {0}; | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 	bool dlok = false; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	u8 *beacon; | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 	u8 *pspoll; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	u8 *nullfunc; | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 	u8 *probersp; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	/*---------------------------------------------------------
 | 
					
						
							|  |  |  | 				(1) beacon | 
					
						
							|  |  |  | 	---------------------------------------------------------*/ | 
					
						
							|  |  |  | 	beacon = &reserved_page_packet[BEACON_PG * 128]; | 
					
						
							|  |  |  | 	SET_80211_HDR_ADDRESS2(beacon, mac->mac_addr); | 
					
						
							|  |  |  | 	SET_80211_HDR_ADDRESS3(beacon, mac->bssid); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*-------------------------------------------------------
 | 
					
						
							|  |  |  | 				(2) ps-poll | 
					
						
							|  |  |  | 	--------------------------------------------------------*/ | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 	pspoll = &reserved_page_packet[PSPOLL_PG * 128]; | 
					
						
							|  |  |  | 	SET_80211_PS_POLL_AID(pspoll, (mac->assoc_id | 0xc000)); | 
					
						
							|  |  |  | 	SET_80211_PS_POLL_BSSID(pspoll, mac->bssid); | 
					
						
							|  |  |  | 	SET_80211_PS_POLL_TA(pspoll, mac->mac_addr); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1RsvdPageLoc, PSPOLL_PG); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*--------------------------------------------------------
 | 
					
						
							|  |  |  | 				(3) null data | 
					
						
							|  |  |  | 	---------------------------------------------------------*/ | 
					
						
							|  |  |  | 	nullfunc = &reserved_page_packet[NULL_PG * 128]; | 
					
						
							|  |  |  | 	SET_80211_HDR_ADDRESS1(nullfunc, mac->bssid); | 
					
						
							|  |  |  | 	SET_80211_HDR_ADDRESS2(nullfunc, mac->mac_addr); | 
					
						
							|  |  |  | 	SET_80211_HDR_ADDRESS3(nullfunc, mac->bssid); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SET_H2CCMD_RSVDPAGE_LOC_NULL_DATA(u1RsvdPageLoc, NULL_PG); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*---------------------------------------------------------
 | 
					
						
							|  |  |  | 				(4) probe response | 
					
						
							|  |  |  | 	----------------------------------------------------------*/ | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 	probersp = &reserved_page_packet[PROBERSP_PG * 128]; | 
					
						
							|  |  |  | 	SET_80211_HDR_ADDRESS1(probersp, mac->bssid); | 
					
						
							|  |  |  | 	SET_80211_HDR_ADDRESS2(probersp, mac->mac_addr); | 
					
						
							|  |  |  | 	SET_80211_HDR_ADDRESS3(probersp, mac->bssid); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	SET_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1RsvdPageLoc, PROBERSP_PG); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	totalpacketlen = TOTAL_RESERVED_PKT_LEN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:40 -08:00
										 |  |  | 		      "rtl92c_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL", | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		      &reserved_page_packet[0], totalpacketlen); | 
					
						
							|  |  |  | 	RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:40 -08:00
										 |  |  | 		      "rtl92c_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL", | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		      u1RsvdPageLoc, 3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb = dev_alloc_skb(totalpacketlen); | 
					
						
							| 
									
										
										
										
											2012-01-07 20:46:40 -06:00
										 |  |  | 	if (!skb) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2012-04-13 13:57:43 -05:00
										 |  |  | 	kmemleak_not_leak(skb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 	memcpy((u8 *) skb_put(skb, totalpacketlen), | 
					
						
							|  |  |  | 	       &reserved_page_packet, totalpacketlen); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 	rtstatus = _rtl92c_cmd_send_packet(hw, skb); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (rtstatus) | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 		dlok = true; | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 12:53:40 -05:00
										 |  |  | 	if (dlok) { | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Set RSVD page location to Fw\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:40 -08:00
										 |  |  | 			      "H2C_RSVDPAGE", u1RsvdPageLoc, 3); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 		rtl92c_fill_h2c_cmd(hw, H2C_RSVDPAGE, | 
					
						
							|  |  |  | 				    sizeof(u1RsvdPageLoc), u1RsvdPageLoc); | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, | 
					
						
							| 
									
										
										
										
											2012-01-04 19:40:41 -08:00
										 |  |  | 			 "Set RSVD page location to Fw FAIL!!!!!!\n"); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-23 10:24:58 -06:00
										 |  |  | EXPORT_SYMBOL(rtl92c_set_fw_rsvdpagepkt); | 
					
						
							| 
									
										
										
										
											2010-12-08 11:12:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | void rtl92c_set_fw_joinbss_report_cmd(struct ieee80211_hw *hw, u8 mstatus) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8 u1_joinbssrpt_parm[1] = {0}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SET_H2CCMD_JOINBSSRPT_PARM_OPMODE(u1_joinbssrpt_parm, mstatus); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtl92c_fill_h2c_cmd(hw, H2C_JOINBSSRPT, 1, u1_joinbssrpt_parm); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-23 10:24:58 -06:00
										 |  |  | EXPORT_SYMBOL(rtl92c_set_fw_joinbss_report_cmd); | 
					
						
							| 
									
										
										
										
											2013-03-24 22:06:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void rtl92c_set_p2p_ctw_period_cmd(struct ieee80211_hw *hw, u8 ctwindow) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8 u1_ctwindow_period[1] = {ctwindow}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtl92c_fill_h2c_cmd(hw, H2C_P2P_PS_CTW_CMD, 1, u1_ctwindow_period); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void rtl92c_set_p2p_ps_offload_cmd(struct ieee80211_hw *hw, u8 p2p_ps_state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct rtl_priv *rtlpriv = rtl_priv(hw); | 
					
						
							|  |  |  | 	struct rtl_ps_ctl *rtlps = rtl_psc(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
					
						
							|  |  |  | 	struct rtl_p2p_ps_info *p2pinfo = &(rtlps->p2p_ps_info); | 
					
						
							|  |  |  | 	struct p2p_ps_offload_t *p2p_ps_offload = &rtlhal->p2p_ps_offload; | 
					
						
							|  |  |  | 	u8	i; | 
					
						
							|  |  |  | 	u16	ctwindow; | 
					
						
							|  |  |  | 	u32	start_time, tsf_low; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (p2p_ps_state) { | 
					
						
							|  |  |  | 	case P2P_PS_DISABLE: | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_DISABLE\n"); | 
					
						
							|  |  |  | 		memset(p2p_ps_offload, 0, sizeof(struct p2p_ps_offload_t)); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case P2P_PS_ENABLE: | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_ENABLE\n"); | 
					
						
							|  |  |  | 		/* update CTWindow value. */ | 
					
						
							|  |  |  | 		if (p2pinfo->ctwindow > 0) { | 
					
						
							|  |  |  | 			p2p_ps_offload->ctwindow_en = 1; | 
					
						
							|  |  |  | 			ctwindow = p2pinfo->ctwindow; | 
					
						
							|  |  |  | 			rtl92c_set_p2p_ctw_period_cmd(hw, ctwindow); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* hw only support 2 set of NoA */ | 
					
						
							|  |  |  | 		for (i = 0; i < p2pinfo->noa_num; i++) { | 
					
						
							|  |  |  | 			/* To control the register setting for which NOA*/ | 
					
						
							|  |  |  | 			rtl_write_byte(rtlpriv, 0x5cf, (i << 4)); | 
					
						
							|  |  |  | 			if (i == 0) | 
					
						
							|  |  |  | 				p2p_ps_offload->noa0_en = 1; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				p2p_ps_offload->noa1_en = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* config P2P NoA Descriptor Register */ | 
					
						
							|  |  |  | 			rtl_write_dword(rtlpriv, 0x5E0, | 
					
						
							|  |  |  | 					p2pinfo->noa_duration[i]); | 
					
						
							|  |  |  | 			rtl_write_dword(rtlpriv, 0x5E4, | 
					
						
							|  |  |  | 					p2pinfo->noa_interval[i]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/*Get Current TSF value */ | 
					
						
							|  |  |  | 			tsf_low = rtl_read_dword(rtlpriv, REG_TSFTR); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			start_time = p2pinfo->noa_start_time[i]; | 
					
						
							|  |  |  | 			if (p2pinfo->noa_count_type[i] != 1) { | 
					
						
							|  |  |  | 				while (start_time <= (tsf_low+(50*1024))) { | 
					
						
							|  |  |  | 					start_time += p2pinfo->noa_interval[i]; | 
					
						
							|  |  |  | 					if (p2pinfo->noa_count_type[i] != 255) | 
					
						
							|  |  |  | 						p2pinfo->noa_count_type[i]--; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			rtl_write_dword(rtlpriv, 0x5E8, start_time); | 
					
						
							|  |  |  | 			rtl_write_dword(rtlpriv, 0x5EC, | 
					
						
							|  |  |  | 					p2pinfo->noa_count_type[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ((p2pinfo->opp_ps == 1) || (p2pinfo->noa_num > 0)) { | 
					
						
							|  |  |  | 			/* rst p2p circuit */ | 
					
						
							|  |  |  | 			rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, BIT(4)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			p2p_ps_offload->offload_en = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (P2P_ROLE_GO == rtlpriv->mac80211.p2p) { | 
					
						
							|  |  |  | 				p2p_ps_offload->role = 1; | 
					
						
							|  |  |  | 				p2p_ps_offload->allstasleep = 0; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				p2p_ps_offload->role = 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			p2p_ps_offload->discovery = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case P2P_PS_SCAN: | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_SCAN\n"); | 
					
						
							|  |  |  | 		p2p_ps_offload->discovery = 1; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case P2P_PS_SCAN_DONE: | 
					
						
							|  |  |  | 		RT_TRACE(rtlpriv, COMP_FW, DBG_LOUD, "P2P_PS_SCAN_DONE\n"); | 
					
						
							|  |  |  | 		p2p_ps_offload->discovery = 0; | 
					
						
							|  |  |  | 		p2pinfo->p2p_ps_state = P2P_PS_ENABLE; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rtl92c_fill_h2c_cmd(hw, H2C_P2P_PS_OFFLOAD, 1, (u8 *)p2p_ps_offload); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(rtl92c_set_p2p_ps_offload_cmd); |