pci.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * wlanfae <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. * Larry Finger <Larry.Finger@lwfinger.net>
  27. *
  28. *****************************************************************************/
  29. #include "core.h"
  30. #include "wifi.h"
  31. #include "pci.h"
  32. #include "base.h"
  33. #include "ps.h"
  34. #include "efuse.h"
  35. static const u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = {
  36. INTEL_VENDOR_ID,
  37. ATI_VENDOR_ID,
  38. AMD_VENDOR_ID,
  39. SIS_VENDOR_ID
  40. };
  41. static const u8 ac_to_hwq[] = {
  42. VO_QUEUE,
  43. VI_QUEUE,
  44. BE_QUEUE,
  45. BK_QUEUE
  46. };
  47. u8 _rtl_mac_to_hwqueue(struct ieee80211_hw *hw,
  48. struct sk_buff *skb)
  49. {
  50. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  51. u16 fc = rtl_get_fc(skb);
  52. u8 queue_index = skb_get_queue_mapping(skb);
  53. if (unlikely(ieee80211_is_beacon(fc)))
  54. return BEACON_QUEUE;
  55. if (ieee80211_is_mgmt(fc))
  56. return MGNT_QUEUE;
  57. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
  58. if (ieee80211_is_nullfunc(fc))
  59. return HIGH_QUEUE;
  60. return ac_to_hwq[queue_index];
  61. }
  62. /* Update PCI dependent default settings*/
  63. static void _rtl_pci_update_default_setting(struct ieee80211_hw *hw)
  64. {
  65. struct rtl_priv *rtlpriv = rtl_priv(hw);
  66. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  67. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  68. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  69. u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor;
  70. u8 init_aspm;
  71. ppsc->reg_rfps_level = 0;
  72. ppsc->support_aspm = 0;
  73. /*Update PCI ASPM setting */
  74. ppsc->const_amdpci_aspm = rtlpci->const_amdpci_aspm;
  75. switch (rtlpci->const_pci_aspm) {
  76. case 0:
  77. /*No ASPM */
  78. break;
  79. case 1:
  80. /*ASPM dynamically enabled/disable. */
  81. ppsc->reg_rfps_level |= RT_RF_LPS_LEVEL_ASPM;
  82. break;
  83. case 2:
  84. /*ASPM with Clock Req dynamically enabled/disable. */
  85. ppsc->reg_rfps_level |= (RT_RF_LPS_LEVEL_ASPM |
  86. RT_RF_OFF_LEVL_CLK_REQ);
  87. break;
  88. case 3:
  89. /*
  90. * Always enable ASPM and Clock Req
  91. * from initialization to halt.
  92. * */
  93. ppsc->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM);
  94. ppsc->reg_rfps_level |= (RT_RF_PS_LEVEL_ALWAYS_ASPM |
  95. RT_RF_OFF_LEVL_CLK_REQ);
  96. break;
  97. case 4:
  98. /*
  99. * Always enable ASPM without Clock Req
  100. * from initialization to halt.
  101. * */
  102. ppsc->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM |
  103. RT_RF_OFF_LEVL_CLK_REQ);
  104. ppsc->reg_rfps_level |= RT_RF_PS_LEVEL_ALWAYS_ASPM;
  105. break;
  106. }
  107. ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC;
  108. /*Update Radio OFF setting */
  109. switch (rtlpci->const_hwsw_rfoff_d3) {
  110. case 1:
  111. if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM)
  112. ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM;
  113. break;
  114. case 2:
  115. if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM)
  116. ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM;
  117. ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC;
  118. break;
  119. case 3:
  120. ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_PCI_D3;
  121. break;
  122. }
  123. /*Set HW definition to determine if it supports ASPM. */
  124. switch (rtlpci->const_support_pciaspm) {
  125. case 0:{
  126. /*Not support ASPM. */
  127. bool support_aspm = false;
  128. ppsc->support_aspm = support_aspm;
  129. break;
  130. }
  131. case 1:{
  132. /*Support ASPM. */
  133. bool support_aspm = true;
  134. bool support_backdoor = true;
  135. ppsc->support_aspm = support_aspm;
  136. /*if (priv->oem_id == RT_CID_TOSHIBA &&
  137. !priv->ndis_adapter.amd_l1_patch)
  138. support_backdoor = false; */
  139. ppsc->support_backdoor = support_backdoor;
  140. break;
  141. }
  142. case 2:
  143. /*ASPM value set by chipset. */
  144. if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL) {
  145. bool support_aspm = true;
  146. ppsc->support_aspm = support_aspm;
  147. }
  148. break;
  149. default:
  150. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  151. ("switch case not process\n"));
  152. break;
  153. }
  154. /* toshiba aspm issue, toshiba will set aspm selfly
  155. * so we should not set aspm in driver */
  156. pci_read_config_byte(rtlpci->pdev, 0x80, &init_aspm);
  157. if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8192SE &&
  158. init_aspm == 0x43)
  159. ppsc->support_aspm = false;
  160. }
  161. /*Disable L0s dirtectly. We will disable host L0s by default. */
  162. void rtl_pci_disable_host_l0s(struct ieee80211_hw *hw)
  163. {
  164. struct rtl_priv *rtlpriv = rtl_priv(hw);
  165. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  166. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  167. u8 pcibridge_busnum = pcipriv->ndis_adapter.pcibridge_busnum;
  168. u8 pcibridge_devnum = pcipriv->ndis_adapter.pcibridge_devnum;
  169. u8 pcibridge_funcnum = pcipriv->ndis_adapter.pcibridge_funcnum;
  170. u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport;
  171. u8 num4bytes = pcipriv->ndis_adapter.num4bytes;
  172. u8 u_pcibridge_aspmsetting = 0;
  173. /*Read Link Control Register */
  174. rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS,
  175. pcicfg_addrport + (num4bytes << 2));
  176. rtl_pci_raw_read_port_uchar(PCI_CONF_DATA, &u_pcibridge_aspmsetting);
  177. if (u_pcibridge_aspmsetting & BIT(0))
  178. u_pcibridge_aspmsetting &= ~(BIT(0));
  179. rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS,
  180. pcicfg_addrport + (num4bytes << 2));
  181. rtl_pci_raw_write_port_uchar(PCI_CONF_DATA, u_pcibridge_aspmsetting);
  182. udelay(50);
  183. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  184. ("PciBridge busnumber[%x], DevNumbe[%x], "
  185. "funcnumber[%x], Write reg[%x] = %lx\n",
  186. pcibridge_busnum, pcibridge_devnum, pcibridge_funcnum,
  187. (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10),
  188. (pcipriv->ndis_adapter.pcibridge_linkctrlreg |
  189. (rtlpci->const_devicepci_aspm_setting & ~BIT(0)))));
  190. }
  191. /*Enable rtl8192ce backdoor to control ASPM and clock request.*/
  192. bool rtl_pci_enable_back_door(struct ieee80211_hw *hw)
  193. {
  194. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  195. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  196. u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor;
  197. bool bresult = true;
  198. u8 value;
  199. pci_read_config_byte(rtlpci->pdev, 0x70f, &value);
  200. /*0x70f BIT(7) is used to control L0S */
  201. if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL) {
  202. value |= BIT(7);
  203. } else {
  204. /*Set 0x70f to 0x23 when non-Intel platform. */
  205. value = 0x23;
  206. }
  207. pci_write_config_byte(rtlpci->pdev, 0x70f, value);
  208. pci_read_config_byte(rtlpci->pdev, 0x719, &value);
  209. /*0x719 BIT(3) is for L1 BIT(4) is for clock request */
  210. value |= (BIT(3) | BIT(4));
  211. pci_write_config_byte(rtlpci->pdev, 0x719, value);
  212. return bresult;
  213. }
  214. static bool _rtl_pci_platform_switch_device_pci_aspm(
  215. struct ieee80211_hw *hw,
  216. u8 value)
  217. {
  218. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  219. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  220. if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE)
  221. value |= 0x40;
  222. pci_write_config_byte(rtlpci->pdev, 0x80, value);
  223. return false;
  224. }
  225. /*When we set 0x01 to enable clk request. Set 0x0 to disable clk req.*/
  226. static bool _rtl_pci_switch_clk_req(struct ieee80211_hw *hw, u8 value)
  227. {
  228. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  229. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  230. pci_write_config_byte(rtlpci->pdev, 0x81, value);
  231. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
  232. udelay(100);
  233. return true;
  234. }
  235. /*Disable RTL8192SE ASPM & Disable Pci Bridge ASPM*/
  236. static void rtl_pci_disable_aspm(struct ieee80211_hw *hw)
  237. {
  238. struct rtl_priv *rtlpriv = rtl_priv(hw);
  239. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  240. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  241. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  242. u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor;
  243. u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport;
  244. u8 num4bytes = pcipriv->ndis_adapter.num4bytes;
  245. /*Retrieve original configuration settings. */
  246. u8 linkctrl_reg = pcipriv->ndis_adapter.linkctrl_reg;
  247. u16 pcibridge_linkctrlreg = pcipriv->ndis_adapter.
  248. pcibridge_linkctrlreg;
  249. u16 aspmlevel = 0;
  250. u8 tmp_u1b = 0;
  251. if (!ppsc->support_aspm)
  252. return;
  253. if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) {
  254. RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
  255. ("PCI(Bridge) UNKNOWN.\n"));
  256. return;
  257. }
  258. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) {
  259. RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_CLK_REQ);
  260. _rtl_pci_switch_clk_req(hw, 0x0);
  261. }
  262. /*for promising device will in L0 state after an I/O. */
  263. pci_read_config_byte(rtlpci->pdev, 0x80, &tmp_u1b);
  264. /*Set corresponding value. */
  265. aspmlevel |= BIT(0) | BIT(1);
  266. linkctrl_reg &= ~aspmlevel;
  267. pcibridge_linkctrlreg &= ~(BIT(0) | BIT(1));
  268. _rtl_pci_platform_switch_device_pci_aspm(hw, linkctrl_reg);
  269. udelay(50);
  270. /*4 Disable Pci Bridge ASPM */
  271. rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS,
  272. pcicfg_addrport + (num4bytes << 2));
  273. rtl_pci_raw_write_port_uchar(PCI_CONF_DATA, pcibridge_linkctrlreg);
  274. udelay(50);
  275. }
  276. /*
  277. *Enable RTL8192SE ASPM & Enable Pci Bridge ASPM for
  278. *power saving We should follow the sequence to enable
  279. *RTL8192SE first then enable Pci Bridge ASPM
  280. *or the system will show bluescreen.
  281. */
  282. static void rtl_pci_enable_aspm(struct ieee80211_hw *hw)
  283. {
  284. struct rtl_priv *rtlpriv = rtl_priv(hw);
  285. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  286. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  287. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  288. u8 pcibridge_busnum = pcipriv->ndis_adapter.pcibridge_busnum;
  289. u8 pcibridge_devnum = pcipriv->ndis_adapter.pcibridge_devnum;
  290. u8 pcibridge_funcnum = pcipriv->ndis_adapter.pcibridge_funcnum;
  291. u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor;
  292. u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport;
  293. u8 num4bytes = pcipriv->ndis_adapter.num4bytes;
  294. u16 aspmlevel;
  295. u8 u_pcibridge_aspmsetting;
  296. u8 u_device_aspmsetting;
  297. if (!ppsc->support_aspm)
  298. return;
  299. if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) {
  300. RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
  301. ("PCI(Bridge) UNKNOWN.\n"));
  302. return;
  303. }
  304. /*4 Enable Pci Bridge ASPM */
  305. rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS,
  306. pcicfg_addrport + (num4bytes << 2));
  307. u_pcibridge_aspmsetting =
  308. pcipriv->ndis_adapter.pcibridge_linkctrlreg |
  309. rtlpci->const_hostpci_aspm_setting;
  310. if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL)
  311. u_pcibridge_aspmsetting &= ~BIT(0);
  312. rtl_pci_raw_write_port_uchar(PCI_CONF_DATA, u_pcibridge_aspmsetting);
  313. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  314. ("PlatformEnableASPM():PciBridge busnumber[%x], "
  315. "DevNumbe[%x], funcnumber[%x], Write reg[%x] = %x\n",
  316. pcibridge_busnum, pcibridge_devnum, pcibridge_funcnum,
  317. (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10),
  318. u_pcibridge_aspmsetting));
  319. udelay(50);
  320. /*Get ASPM level (with/without Clock Req) */
  321. aspmlevel = rtlpci->const_devicepci_aspm_setting;
  322. u_device_aspmsetting = pcipriv->ndis_adapter.linkctrl_reg;
  323. /*_rtl_pci_platform_switch_device_pci_aspm(dev,*/
  324. /*(priv->ndis_adapter.linkctrl_reg | ASPMLevel)); */
  325. u_device_aspmsetting |= aspmlevel;
  326. _rtl_pci_platform_switch_device_pci_aspm(hw, u_device_aspmsetting);
  327. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) {
  328. _rtl_pci_switch_clk_req(hw, (ppsc->reg_rfps_level &
  329. RT_RF_OFF_LEVL_CLK_REQ) ? 1 : 0);
  330. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_CLK_REQ);
  331. }
  332. udelay(100);
  333. }
  334. static bool rtl_pci_get_amd_l1_patch(struct ieee80211_hw *hw)
  335. {
  336. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  337. u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport;
  338. bool status = false;
  339. u8 offset_e0;
  340. unsigned offset_e4;
  341. rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS,
  342. pcicfg_addrport + 0xE0);
  343. rtl_pci_raw_write_port_uchar(PCI_CONF_DATA, 0xA0);
  344. rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS,
  345. pcicfg_addrport + 0xE0);
  346. rtl_pci_raw_read_port_uchar(PCI_CONF_DATA, &offset_e0);
  347. if (offset_e0 == 0xA0) {
  348. rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS,
  349. pcicfg_addrport + 0xE4);
  350. rtl_pci_raw_read_port_ulong(PCI_CONF_DATA, &offset_e4);
  351. if (offset_e4 & BIT(23))
  352. status = true;
  353. }
  354. return status;
  355. }
  356. void rtl_pci_get_linkcontrol_field(struct ieee80211_hw *hw)
  357. {
  358. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  359. u8 capabilityoffset = pcipriv->ndis_adapter.pcibridge_pciehdr_offset;
  360. u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport;
  361. u8 linkctrl_reg;
  362. u8 num4bbytes;
  363. num4bbytes = (capabilityoffset + 0x10) / 4;
  364. /*Read Link Control Register */
  365. rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS,
  366. pcicfg_addrport + (num4bbytes << 2));
  367. rtl_pci_raw_read_port_uchar(PCI_CONF_DATA, &linkctrl_reg);
  368. pcipriv->ndis_adapter.pcibridge_linkctrlreg = linkctrl_reg;
  369. }
  370. static void rtl_pci_parse_configuration(struct pci_dev *pdev,
  371. struct ieee80211_hw *hw)
  372. {
  373. struct rtl_priv *rtlpriv = rtl_priv(hw);
  374. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  375. u8 tmp;
  376. int pos;
  377. u8 linkctrl_reg;
  378. /*Link Control Register */
  379. pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  380. pci_read_config_byte(pdev, pos + PCI_EXP_LNKCTL, &linkctrl_reg);
  381. pcipriv->ndis_adapter.linkctrl_reg = linkctrl_reg;
  382. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  383. ("Link Control Register =%x\n",
  384. pcipriv->ndis_adapter.linkctrl_reg));
  385. pci_read_config_byte(pdev, 0x98, &tmp);
  386. tmp |= BIT(4);
  387. pci_write_config_byte(pdev, 0x98, tmp);
  388. tmp = 0x17;
  389. pci_write_config_byte(pdev, 0x70f, tmp);
  390. }
  391. static void rtl_pci_init_aspm(struct ieee80211_hw *hw)
  392. {
  393. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  394. _rtl_pci_update_default_setting(hw);
  395. if (ppsc->reg_rfps_level & RT_RF_PS_LEVEL_ALWAYS_ASPM) {
  396. /*Always enable ASPM & Clock Req. */
  397. rtl_pci_enable_aspm(hw);
  398. RT_SET_PS_LEVEL(ppsc, RT_RF_PS_LEVEL_ALWAYS_ASPM);
  399. }
  400. }
  401. static void _rtl_pci_io_handler_init(struct device *dev,
  402. struct ieee80211_hw *hw)
  403. {
  404. struct rtl_priv *rtlpriv = rtl_priv(hw);
  405. rtlpriv->io.dev = dev;
  406. rtlpriv->io.write8_async = pci_write8_async;
  407. rtlpriv->io.write16_async = pci_write16_async;
  408. rtlpriv->io.write32_async = pci_write32_async;
  409. rtlpriv->io.read8_sync = pci_read8_sync;
  410. rtlpriv->io.read16_sync = pci_read16_sync;
  411. rtlpriv->io.read32_sync = pci_read32_sync;
  412. }
  413. static void _rtl_pci_io_handler_release(struct ieee80211_hw *hw)
  414. {
  415. }
  416. static bool _rtl_update_earlymode_info(struct ieee80211_hw *hw,
  417. struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc, u8 tid)
  418. {
  419. struct rtl_priv *rtlpriv = rtl_priv(hw);
  420. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  421. u8 additionlen = FCS_LEN;
  422. struct sk_buff *next_skb;
  423. /* here open is 4, wep/tkip is 8, aes is 12*/
  424. if (info->control.hw_key)
  425. additionlen += info->control.hw_key->icv_len;
  426. /* The most skb num is 6 */
  427. tcb_desc->empkt_num = 0;
  428. spin_lock_bh(&rtlpriv->locks.waitq_lock);
  429. skb_queue_walk(&rtlpriv->mac80211.skb_waitq[tid], next_skb) {
  430. struct ieee80211_tx_info *next_info;
  431. next_info = IEEE80211_SKB_CB(next_skb);
  432. if (next_info->flags & IEEE80211_TX_CTL_AMPDU) {
  433. tcb_desc->empkt_len[tcb_desc->empkt_num] =
  434. next_skb->len + additionlen;
  435. tcb_desc->empkt_num++;
  436. } else {
  437. break;
  438. }
  439. if (skb_queue_is_last(&rtlpriv->mac80211.skb_waitq[tid],
  440. next_skb))
  441. break;
  442. if (tcb_desc->empkt_num >= 5)
  443. break;
  444. }
  445. spin_unlock_bh(&rtlpriv->locks.waitq_lock);
  446. return true;
  447. }
  448. /* just for early mode now */
  449. static void _rtl_pci_tx_chk_waitq(struct ieee80211_hw *hw)
  450. {
  451. struct rtl_priv *rtlpriv = rtl_priv(hw);
  452. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  453. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  454. struct sk_buff *skb = NULL;
  455. struct ieee80211_tx_info *info = NULL;
  456. int tid; /* should be int */
  457. if (!rtlpriv->rtlhal.earlymode_enable)
  458. return;
  459. /* we juse use em for BE/BK/VI/VO */
  460. for (tid = 7; tid >= 0; tid--) {
  461. u8 hw_queue = ac_to_hwq[rtl_tid_to_ac(hw, tid)];
  462. struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
  463. while (!mac->act_scanning &&
  464. rtlpriv->psc.rfpwr_state == ERFON) {
  465. struct rtl_tcb_desc tcb_desc;
  466. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  467. spin_lock_bh(&rtlpriv->locks.waitq_lock);
  468. if (!skb_queue_empty(&mac->skb_waitq[tid]) &&
  469. (ring->entries - skb_queue_len(&ring->queue) > 5)) {
  470. skb = skb_dequeue(&mac->skb_waitq[tid]);
  471. } else {
  472. spin_unlock_bh(&rtlpriv->locks.waitq_lock);
  473. break;
  474. }
  475. spin_unlock_bh(&rtlpriv->locks.waitq_lock);
  476. /* Some macaddr can't do early mode. like
  477. * multicast/broadcast/no_qos data */
  478. info = IEEE80211_SKB_CB(skb);
  479. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  480. _rtl_update_earlymode_info(hw, skb,
  481. &tcb_desc, tid);
  482. #if 0 /* temporary */
  483. rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
  484. #endif
  485. }
  486. }
  487. }
  488. static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio)
  489. {
  490. struct rtl_priv *rtlpriv = rtl_priv(hw);
  491. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  492. struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[prio];
  493. while (skb_queue_len(&ring->queue)) {
  494. struct rtl_tx_desc *entry = &ring->desc[ring->idx];
  495. struct sk_buff *skb;
  496. struct ieee80211_tx_info *info;
  497. __le16 fc;
  498. u8 tid;
  499. u8 own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) entry, true,
  500. HW_DESC_OWN);
  501. /*
  502. *beacon packet will only use the first
  503. *descriptor defautly,and the own may not
  504. *be cleared by the hardware
  505. */
  506. if (own)
  507. return;
  508. ring->idx = (ring->idx + 1) % ring->entries;
  509. skb = __skb_dequeue(&ring->queue);
  510. pci_unmap_single(rtlpci->pdev,
  511. le32_to_cpu(rtlpriv->cfg->ops->
  512. get_desc((u8 *) entry, true,
  513. HW_DESC_TXBUFF_ADDR)),
  514. skb->len, PCI_DMA_TODEVICE);
  515. /* remove early mode header */
  516. if (rtlpriv->rtlhal.earlymode_enable)
  517. skb_pull(skb, EM_HDR_LEN);
  518. RT_TRACE(rtlpriv, (COMP_INTR | COMP_SEND), DBG_TRACE,
  519. ("new ring->idx:%d, "
  520. "free: skb_queue_len:%d, free: seq:%x\n",
  521. ring->idx,
  522. skb_queue_len(&ring->queue),
  523. *(u16 *) (skb->data + 22)));
  524. if (prio == TXCMD_QUEUE) {
  525. dev_kfree_skb(skb);
  526. goto tx_status_ok;
  527. }
  528. /* for sw LPS, just after NULL skb send out, we can
  529. * sure AP kown we are sleeped, our we should not let
  530. * rf to sleep*/
  531. fc = rtl_get_fc(skb);
  532. if (ieee80211_is_nullfunc(fc)) {
  533. if (ieee80211_has_pm(fc)) {
  534. rtlpriv->mac80211.offchan_deley = true;
  535. rtlpriv->psc.state_inap = 1;
  536. } else {
  537. rtlpriv->psc.state_inap = 0;
  538. }
  539. }
  540. /* update tid tx pkt num */
  541. tid = rtl_get_tid(skb);
  542. if (tid <= 7)
  543. rtlpriv->link_info.tidtx_inperiod[tid]++;
  544. info = IEEE80211_SKB_CB(skb);
  545. ieee80211_tx_info_clear_status(info);
  546. info->flags |= IEEE80211_TX_STAT_ACK;
  547. /*info->status.rates[0].count = 1; */
  548. ieee80211_tx_status_irqsafe(hw, skb);
  549. if ((ring->entries - skb_queue_len(&ring->queue))
  550. == 2) {
  551. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  552. ("more desc left, wake"
  553. "skb_queue@%d,ring->idx = %d,"
  554. "skb_queue_len = 0x%d\n",
  555. prio, ring->idx,
  556. skb_queue_len(&ring->queue)));
  557. ieee80211_wake_queue(hw,
  558. skb_get_queue_mapping
  559. (skb));
  560. }
  561. tx_status_ok:
  562. skb = NULL;
  563. }
  564. if (((rtlpriv->link_info.num_rx_inperiod +
  565. rtlpriv->link_info.num_tx_inperiod) > 8) ||
  566. (rtlpriv->link_info.num_rx_inperiod > 2)) {
  567. rtl_lps_leave(hw);
  568. }
  569. }
  570. static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
  571. {
  572. struct rtl_priv *rtlpriv = rtl_priv(hw);
  573. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  574. int rx_queue_idx = RTL_PCI_RX_MPDU_QUEUE;
  575. struct ieee80211_rx_status rx_status = { 0 };
  576. unsigned int count = rtlpci->rxringcount;
  577. u8 own;
  578. u8 tmp_one;
  579. u32 bufferaddress;
  580. bool unicast = false;
  581. struct rtl_stats stats = {
  582. .signal = 0,
  583. .noise = -98,
  584. .rate = 0,
  585. };
  586. /*RX NORMAL PKT */
  587. while (count--) {
  588. /*rx descriptor */
  589. struct rtl_rx_desc *pdesc = &rtlpci->rx_ring[rx_queue_idx].desc[
  590. rtlpci->rx_ring[rx_queue_idx].idx];
  591. /*rx pkt */
  592. struct sk_buff *skb = rtlpci->rx_ring[rx_queue_idx].rx_buf[
  593. rtlpci->rx_ring[rx_queue_idx].idx];
  594. own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) pdesc,
  595. false, HW_DESC_OWN);
  596. if (own) {
  597. /*wait data to be filled by hardware */
  598. return;
  599. } else {
  600. struct ieee80211_hdr *hdr;
  601. __le16 fc;
  602. struct sk_buff *new_skb = NULL;
  603. rtlpriv->cfg->ops->query_rx_desc(hw, &stats,
  604. &rx_status,
  605. (u8 *) pdesc, skb);
  606. pci_unmap_single(rtlpci->pdev,
  607. *((dma_addr_t *) skb->cb),
  608. rtlpci->rxbuffersize,
  609. PCI_DMA_FROMDEVICE);
  610. skb_put(skb, rtlpriv->cfg->ops->get_desc((u8 *) pdesc,
  611. false,
  612. HW_DESC_RXPKT_LEN));
  613. skb_reserve(skb,
  614. stats.rx_drvinfo_size + stats.rx_bufshift);
  615. /*
  616. *NOTICE This can not be use for mac80211,
  617. *this is done in mac80211 code,
  618. *if you done here sec DHCP will fail
  619. *skb_trim(skb, skb->len - 4);
  620. */
  621. hdr = rtl_get_hdr(skb);
  622. fc = rtl_get_fc(skb);
  623. if (!stats.crc || !stats.hwerror) {
  624. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status,
  625. sizeof(rx_status));
  626. if (is_broadcast_ether_addr(hdr->addr1)) {
  627. ;/*TODO*/
  628. } else if (is_multicast_ether_addr(hdr->addr1)) {
  629. ;/*TODO*/
  630. } else {
  631. unicast = true;
  632. rtlpriv->stats.rxbytesunicast +=
  633. skb->len;
  634. }
  635. rtl_is_special_data(hw, skb, false);
  636. if (ieee80211_is_data(fc)) {
  637. rtlpriv->cfg->ops->led_control(hw,
  638. LED_CTL_RX);
  639. if (unicast)
  640. rtlpriv->link_info.
  641. num_rx_inperiod++;
  642. }
  643. /* for sw lps */
  644. rtl_swlps_beacon(hw, (void *)skb->data,
  645. skb->len);
  646. rtl_recognize_peer(hw, (void *)skb->data,
  647. skb->len);
  648. if ((rtlpriv->mac80211.opmode ==
  649. NL80211_IFTYPE_AP) &&
  650. (rtlpriv->rtlhal.current_bandtype ==
  651. BAND_ON_2_4G) &&
  652. (ieee80211_is_beacon(fc) ||
  653. ieee80211_is_probe_resp(fc))) {
  654. dev_kfree_skb_any(skb);
  655. } else {
  656. if (unlikely(!rtl_action_proc(hw, skb,
  657. false))) {
  658. dev_kfree_skb_any(skb);
  659. } else {
  660. struct sk_buff *uskb = NULL;
  661. u8 *pdata;
  662. uskb = dev_alloc_skb(skb->len
  663. + 128);
  664. memcpy(IEEE80211_SKB_RXCB(uskb),
  665. &rx_status,
  666. sizeof(rx_status));
  667. pdata = (u8 *)skb_put(uskb,
  668. skb->len);
  669. memcpy(pdata, skb->data,
  670. skb->len);
  671. dev_kfree_skb_any(skb);
  672. ieee80211_rx_irqsafe(hw, uskb);
  673. }
  674. }
  675. } else {
  676. dev_kfree_skb_any(skb);
  677. }
  678. if (((rtlpriv->link_info.num_rx_inperiod +
  679. rtlpriv->link_info.num_tx_inperiod) > 8) ||
  680. (rtlpriv->link_info.num_rx_inperiod > 2)) {
  681. rtl_lps_leave(hw);
  682. }
  683. new_skb = dev_alloc_skb(rtlpci->rxbuffersize);
  684. if (unlikely(!new_skb)) {
  685. RT_TRACE(rtlpriv, (COMP_INTR | COMP_RECV),
  686. DBG_DMESG,
  687. ("can't alloc skb for rx\n"));
  688. goto done;
  689. }
  690. skb = new_skb;
  691. /*skb->dev = dev; */
  692. rtlpci->rx_ring[rx_queue_idx].rx_buf[rtlpci->
  693. rx_ring
  694. [rx_queue_idx].
  695. idx] = skb;
  696. *((dma_addr_t *) skb->cb) =
  697. pci_map_single(rtlpci->pdev, skb_tail_pointer(skb),
  698. rtlpci->rxbuffersize,
  699. PCI_DMA_FROMDEVICE);
  700. }
  701. done:
  702. bufferaddress = cpu_to_le32(*((dma_addr_t *)skb->cb));
  703. tmp_one = 1;
  704. rtlpriv->cfg->ops->set_desc((u8 *) pdesc, false,
  705. HW_DESC_RXBUFF_ADDR,
  706. (u8 *)&bufferaddress);
  707. rtlpriv->cfg->ops->set_desc((u8 *)pdesc, false, HW_DESC_RXOWN,
  708. (u8 *)&tmp_one);
  709. rtlpriv->cfg->ops->set_desc((u8 *)pdesc, false,
  710. HW_DESC_RXPKT_LEN,
  711. (u8 *)&rtlpci->rxbuffersize);
  712. if (rtlpci->rx_ring[rx_queue_idx].idx ==
  713. rtlpci->rxringcount - 1)
  714. rtlpriv->cfg->ops->set_desc((u8 *)pdesc, false,
  715. HW_DESC_RXERO,
  716. (u8 *)&tmp_one);
  717. rtlpci->rx_ring[rx_queue_idx].idx =
  718. (rtlpci->rx_ring[rx_queue_idx].idx + 1) %
  719. rtlpci->rxringcount;
  720. }
  721. }
  722. void _rtl_pci_tx_interrupt(struct ieee80211_hw *hw)
  723. {
  724. struct rtl_priv *rtlpriv = rtl_priv(hw);
  725. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  726. int prio;
  727. for (prio = 0; prio < RTL_PCI_MAX_TX_QUEUE_COUNT; prio++) {
  728. struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[prio];
  729. while (skb_queue_len(&ring->queue)) {
  730. struct rtl_tx_desc *entry = &ring->desc[ring->idx];
  731. struct sk_buff *skb;
  732. struct ieee80211_tx_info *info;
  733. u8 own;
  734. /*
  735. *beacon packet will only use the first
  736. *descriptor defautly, and the own may not
  737. *be cleared by the hardware, and
  738. *beacon will free in prepare beacon
  739. */
  740. if (prio == BEACON_QUEUE || prio == TXCMD_QUEUE ||
  741. prio == HCCA_QUEUE)
  742. break;
  743. own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) entry,
  744. true,
  745. HW_DESC_OWN);
  746. if (own)
  747. break;
  748. skb = __skb_dequeue(&ring->queue);
  749. pci_unmap_single(rtlpci->pdev,
  750. le32_to_cpu(rtlpriv->cfg->ops->
  751. get_desc((u8 *) entry,
  752. true,
  753. HW_DESC_TXBUFF_ADDR)),
  754. skb->len, PCI_DMA_TODEVICE);
  755. ring->idx = (ring->idx + 1) % ring->entries;
  756. info = IEEE80211_SKB_CB(skb);
  757. ieee80211_tx_info_clear_status(info);
  758. info->flags |= IEEE80211_TX_STAT_ACK;
  759. /*info->status.rates[0].count = 1; */
  760. ieee80211_tx_status_irqsafe(hw, skb);
  761. if ((ring->entries - skb_queue_len(&ring->queue))
  762. == 2 && prio != BEACON_QUEUE) {
  763. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  764. ("more desc left, wake "
  765. "skb_queue@%d,ring->idx = %d,"
  766. "skb_queue_len = 0x%d\n",
  767. prio, ring->idx,
  768. skb_queue_len(&ring->queue)));
  769. ieee80211_wake_queue(hw,
  770. skb_get_queue_mapping
  771. (skb));
  772. }
  773. skb = NULL;
  774. }
  775. }
  776. }
  777. static irqreturn_t _rtl_pci_interrupt(int irq, void *dev_id)
  778. {
  779. struct ieee80211_hw *hw = dev_id;
  780. struct rtl_priv *rtlpriv = rtl_priv(hw);
  781. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  782. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  783. unsigned long flags;
  784. u32 inta = 0;
  785. u32 intb = 0;
  786. if (rtlpci->irq_enabled == 0)
  787. return IRQ_HANDLED;
  788. spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
  789. /*read ISR: 4/8bytes */
  790. rtlpriv->cfg->ops->interrupt_recognized(hw, &inta, &intb);
  791. /*Shared IRQ or HW disappared */
  792. if (!inta || inta == 0xffff)
  793. goto done;
  794. /*<1> beacon related */
  795. if (inta & rtlpriv->cfg->maps[RTL_IMR_TBDOK]) {
  796. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  797. ("beacon ok interrupt!\n"));
  798. }
  799. if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_TBDER])) {
  800. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  801. ("beacon err interrupt!\n"));
  802. }
  803. if (inta & rtlpriv->cfg->maps[RTL_IMR_BDOK]) {
  804. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  805. ("beacon interrupt!\n"));
  806. }
  807. if (inta & rtlpriv->cfg->maps[RTL_IMR_BcnInt]) {
  808. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  809. ("prepare beacon for interrupt!\n"));
  810. tasklet_schedule(&rtlpriv->works.irq_prepare_bcn_tasklet);
  811. }
  812. /*<3> Tx related */
  813. if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_TXFOVW]))
  814. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, ("IMR_TXFOVW!\n"));
  815. if (inta & rtlpriv->cfg->maps[RTL_IMR_MGNTDOK]) {
  816. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  817. ("Manage ok interrupt!\n"));
  818. _rtl_pci_tx_isr(hw, MGNT_QUEUE);
  819. }
  820. if (inta & rtlpriv->cfg->maps[RTL_IMR_HIGHDOK]) {
  821. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  822. ("HIGH_QUEUE ok interrupt!\n"));
  823. _rtl_pci_tx_isr(hw, HIGH_QUEUE);
  824. }
  825. if (inta & rtlpriv->cfg->maps[RTL_IMR_BKDOK]) {
  826. rtlpriv->link_info.num_tx_inperiod++;
  827. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  828. ("BK Tx OK interrupt!\n"));
  829. _rtl_pci_tx_isr(hw, BK_QUEUE);
  830. }
  831. if (inta & rtlpriv->cfg->maps[RTL_IMR_BEDOK]) {
  832. rtlpriv->link_info.num_tx_inperiod++;
  833. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  834. ("BE TX OK interrupt!\n"));
  835. _rtl_pci_tx_isr(hw, BE_QUEUE);
  836. }
  837. if (inta & rtlpriv->cfg->maps[RTL_IMR_VIDOK]) {
  838. rtlpriv->link_info.num_tx_inperiod++;
  839. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  840. ("VI TX OK interrupt!\n"));
  841. _rtl_pci_tx_isr(hw, VI_QUEUE);
  842. }
  843. if (inta & rtlpriv->cfg->maps[RTL_IMR_VODOK]) {
  844. rtlpriv->link_info.num_tx_inperiod++;
  845. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  846. ("Vo TX OK interrupt!\n"));
  847. _rtl_pci_tx_isr(hw, VO_QUEUE);
  848. }
  849. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) {
  850. if (inta & rtlpriv->cfg->maps[RTL_IMR_COMDOK]) {
  851. rtlpriv->link_info.num_tx_inperiod++;
  852. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
  853. ("CMD TX OK interrupt!\n"));
  854. _rtl_pci_tx_isr(hw, TXCMD_QUEUE);
  855. }
  856. }
  857. /*<2> Rx related */
  858. if (inta & rtlpriv->cfg->maps[RTL_IMR_ROK]) {
  859. RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, ("Rx ok interrupt!\n"));
  860. _rtl_pci_rx_interrupt(hw);
  861. }
  862. if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RDU])) {
  863. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  864. ("rx descriptor unavailable!\n"));
  865. _rtl_pci_rx_interrupt(hw);
  866. }
  867. if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RXFOVW])) {
  868. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, ("rx overflow !\n"));
  869. _rtl_pci_rx_interrupt(hw);
  870. }
  871. if (rtlpriv->rtlhal.earlymode_enable)
  872. tasklet_schedule(&rtlpriv->works.irq_tasklet);
  873. spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
  874. return IRQ_HANDLED;
  875. done:
  876. spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
  877. return IRQ_HANDLED;
  878. }
  879. static void _rtl_pci_irq_tasklet(struct ieee80211_hw *hw)
  880. {
  881. _rtl_pci_tx_chk_waitq(hw);
  882. }
  883. static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw)
  884. {
  885. struct rtl_priv *rtlpriv = rtl_priv(hw);
  886. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  887. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  888. struct rtl8192_tx_ring *ring = NULL;
  889. struct ieee80211_hdr *hdr = NULL;
  890. struct ieee80211_tx_info *info = NULL;
  891. struct sk_buff *pskb = NULL;
  892. struct rtl_tx_desc *pdesc = NULL;
  893. struct rtl_tcb_desc tcb_desc;
  894. u8 temp_one = 1;
  895. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  896. ring = &rtlpci->tx_ring[BEACON_QUEUE];
  897. pskb = __skb_dequeue(&ring->queue);
  898. if (pskb)
  899. kfree_skb(pskb);
  900. /*NB: the beacon data buffer must be 32-bit aligned. */
  901. pskb = ieee80211_beacon_get(hw, mac->vif);
  902. if (pskb == NULL)
  903. return;
  904. hdr = rtl_get_hdr(pskb);
  905. info = IEEE80211_SKB_CB(pskb);
  906. pdesc = &ring->desc[0];
  907. #if 0 /* temporary */
  908. rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *) pdesc,
  909. info, pskb, BEACON_QUEUE, &tcb_desc);
  910. #endif
  911. __skb_queue_tail(&ring->queue, pskb);
  912. rtlpriv->cfg->ops->set_desc((u8 *) pdesc, true, HW_DESC_OWN,
  913. (u8 *)&temp_one);
  914. return;
  915. }
  916. static void _rtl_pci_init_trx_var(struct ieee80211_hw *hw)
  917. {
  918. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  919. u8 i;
  920. for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++)
  921. rtlpci->txringcount[i] = RT_TXDESC_NUM;
  922. /*
  923. *we just alloc 2 desc for beacon queue,
  924. *because we just need first desc in hw beacon.
  925. */
  926. rtlpci->txringcount[BEACON_QUEUE] = 2;
  927. /*
  928. *BE queue need more descriptor for performance
  929. *consideration or, No more tx desc will happen,
  930. *and may cause mac80211 mem leakage.
  931. */
  932. rtlpci->txringcount[BE_QUEUE] = RT_TXDESC_NUM_BE_QUEUE;
  933. rtlpci->rxbuffersize = 9100; /*2048/1024; */
  934. rtlpci->rxringcount = RTL_PCI_MAX_RX_COUNT; /*64; */
  935. }
  936. static void _rtl_pci_init_struct(struct ieee80211_hw *hw,
  937. struct pci_dev *pdev)
  938. {
  939. struct rtl_priv *rtlpriv = rtl_priv(hw);
  940. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  941. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  942. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  943. rtlpci->up_first_time = true;
  944. rtlpci->being_init_adapter = false;
  945. rtlhal->hw = hw;
  946. rtlpci->pdev = pdev;
  947. /*Tx/Rx related var */
  948. _rtl_pci_init_trx_var(hw);
  949. /*IBSS*/ mac->beacon_interval = 100;
  950. /*AMPDU*/
  951. mac->min_space_cfg = 0;
  952. mac->max_mss_density = 0;
  953. /*set sane AMPDU defaults */
  954. mac->current_ampdu_density = 7;
  955. mac->current_ampdu_factor = 3;
  956. /*QOS*/
  957. rtlpci->acm_method = eAcmWay2_SW;
  958. /*task */
  959. tasklet_init(&rtlpriv->works.irq_tasklet,
  960. (void (*)(unsigned long))_rtl_pci_irq_tasklet,
  961. (unsigned long)hw);
  962. tasklet_init(&rtlpriv->works.irq_prepare_bcn_tasklet,
  963. (void (*)(unsigned long))_rtl_pci_prepare_bcn_tasklet,
  964. (unsigned long)hw);
  965. }
  966. static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
  967. unsigned int prio, unsigned int entries)
  968. {
  969. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  970. struct rtl_priv *rtlpriv = rtl_priv(hw);
  971. struct rtl_tx_desc *ring;
  972. dma_addr_t dma;
  973. u32 nextdescaddress;
  974. int i;
  975. ring = pci_alloc_consistent(rtlpci->pdev,
  976. sizeof(*ring) * entries, &dma);
  977. if (!ring || (unsigned long)ring & 0xFF) {
  978. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  979. ("Cannot allocate TX ring (prio = %d)\n", prio));
  980. return -ENOMEM;
  981. }
  982. memset(ring, 0, sizeof(*ring) * entries);
  983. rtlpci->tx_ring[prio].desc = ring;
  984. rtlpci->tx_ring[prio].dma = dma;
  985. rtlpci->tx_ring[prio].idx = 0;
  986. rtlpci->tx_ring[prio].entries = entries;
  987. skb_queue_head_init(&rtlpci->tx_ring[prio].queue);
  988. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  989. ("queue:%d, ring_addr:%p\n", prio, ring));
  990. for (i = 0; i < entries; i++) {
  991. nextdescaddress = cpu_to_le32((u32) dma +
  992. ((i + 11) % entries) *
  993. sizeof(*ring));
  994. rtlpriv->cfg->ops->set_desc((u8 *)&(ring[i]),
  995. true, HW_DESC_TX_NEXTDESC_ADDR,
  996. (u8 *)&nextdescaddress);
  997. }
  998. return 0;
  999. }
  1000. static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw)
  1001. {
  1002. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1003. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1004. struct rtl_rx_desc *entry = NULL;
  1005. int i, rx_queue_idx;
  1006. u8 tmp_one = 1;
  1007. /*
  1008. *rx_queue_idx 0:RX_MPDU_QUEUE
  1009. *rx_queue_idx 1:RX_CMD_QUEUE
  1010. */
  1011. for (rx_queue_idx = 0; rx_queue_idx < RTL_PCI_MAX_RX_QUEUE;
  1012. rx_queue_idx++) {
  1013. rtlpci->rx_ring[rx_queue_idx].desc =
  1014. pci_alloc_consistent(rtlpci->pdev,
  1015. sizeof(*rtlpci->rx_ring[rx_queue_idx].
  1016. desc) * rtlpci->rxringcount,
  1017. &rtlpci->rx_ring[rx_queue_idx].dma);
  1018. if (!rtlpci->rx_ring[rx_queue_idx].desc ||
  1019. (unsigned long)rtlpci->rx_ring[rx_queue_idx].desc & 0xFF) {
  1020. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1021. ("Cannot allocate RX ring\n"));
  1022. return -ENOMEM;
  1023. }
  1024. memset(rtlpci->rx_ring[rx_queue_idx].desc, 0,
  1025. sizeof(*rtlpci->rx_ring[rx_queue_idx].desc) *
  1026. rtlpci->rxringcount);
  1027. rtlpci->rx_ring[rx_queue_idx].idx = 0;
  1028. for (i = 0; i < rtlpci->rxringcount; i++) {
  1029. struct sk_buff *skb =
  1030. dev_alloc_skb(rtlpci->rxbuffersize);
  1031. u32 bufferaddress;
  1032. if (!skb)
  1033. return 0;
  1034. entry = &rtlpci->rx_ring[rx_queue_idx].desc[i];
  1035. /*skb->dev = dev; */
  1036. rtlpci->rx_ring[rx_queue_idx].rx_buf[i] = skb;
  1037. /*
  1038. *just set skb->cb to mapping addr
  1039. *for pci_unmap_single use
  1040. */
  1041. *((dma_addr_t *) skb->cb) =
  1042. pci_map_single(rtlpci->pdev, skb_tail_pointer(skb),
  1043. rtlpci->rxbuffersize,
  1044. PCI_DMA_FROMDEVICE);
  1045. bufferaddress = cpu_to_le32(*((dma_addr_t *)skb->cb));
  1046. rtlpriv->cfg->ops->set_desc((u8 *)entry, false,
  1047. HW_DESC_RXBUFF_ADDR,
  1048. (u8 *)&bufferaddress);
  1049. rtlpriv->cfg->ops->set_desc((u8 *)entry, false,
  1050. HW_DESC_RXPKT_LEN,
  1051. (u8 *)&rtlpci->
  1052. rxbuffersize);
  1053. rtlpriv->cfg->ops->set_desc((u8 *) entry, false,
  1054. HW_DESC_RXOWN,
  1055. (u8 *)&tmp_one);
  1056. }
  1057. rtlpriv->cfg->ops->set_desc((u8 *) entry, false,
  1058. HW_DESC_RXERO, (u8 *)&tmp_one);
  1059. }
  1060. return 0;
  1061. }
  1062. static void _rtl_pci_free_tx_ring(struct ieee80211_hw *hw,
  1063. unsigned int prio)
  1064. {
  1065. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1066. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1067. struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[prio];
  1068. while (skb_queue_len(&ring->queue)) {
  1069. struct rtl_tx_desc *entry = &ring->desc[ring->idx];
  1070. struct sk_buff *skb = __skb_dequeue(&ring->queue);
  1071. pci_unmap_single(rtlpci->pdev,
  1072. le32_to_cpu(rtlpriv->cfg->
  1073. ops->get_desc((u8 *) entry, true,
  1074. HW_DESC_TXBUFF_ADDR)),
  1075. skb->len, PCI_DMA_TODEVICE);
  1076. kfree_skb(skb);
  1077. ring->idx = (ring->idx + 1) % ring->entries;
  1078. }
  1079. pci_free_consistent(rtlpci->pdev,
  1080. sizeof(*ring->desc) * ring->entries,
  1081. ring->desc, ring->dma);
  1082. ring->desc = NULL;
  1083. }
  1084. static void _rtl_pci_free_rx_ring(struct rtl_pci *rtlpci)
  1085. {
  1086. int i, rx_queue_idx;
  1087. /*rx_queue_idx 0:RX_MPDU_QUEUE */
  1088. /*rx_queue_idx 1:RX_CMD_QUEUE */
  1089. for (rx_queue_idx = 0; rx_queue_idx < RTL_PCI_MAX_RX_QUEUE;
  1090. rx_queue_idx++) {
  1091. for (i = 0; i < rtlpci->rxringcount; i++) {
  1092. struct sk_buff *skb =
  1093. rtlpci->rx_ring[rx_queue_idx].rx_buf[i];
  1094. if (!skb)
  1095. continue;
  1096. pci_unmap_single(rtlpci->pdev,
  1097. *((dma_addr_t *) skb->cb),
  1098. rtlpci->rxbuffersize,
  1099. PCI_DMA_FROMDEVICE);
  1100. kfree_skb(skb);
  1101. }
  1102. pci_free_consistent(rtlpci->pdev,
  1103. sizeof(*rtlpci->rx_ring[rx_queue_idx].
  1104. desc) * rtlpci->rxringcount,
  1105. rtlpci->rx_ring[rx_queue_idx].desc,
  1106. rtlpci->rx_ring[rx_queue_idx].dma);
  1107. rtlpci->rx_ring[rx_queue_idx].desc = NULL;
  1108. }
  1109. }
  1110. static int _rtl_pci_init_trx_ring(struct ieee80211_hw *hw)
  1111. {
  1112. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1113. int ret;
  1114. int i;
  1115. ret = _rtl_pci_init_rx_ring(hw);
  1116. if (ret)
  1117. return ret;
  1118. for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) {
  1119. ret = _rtl_pci_init_tx_ring(hw, i,
  1120. rtlpci->txringcount[i]);
  1121. if (ret)
  1122. goto err_free_rings;
  1123. }
  1124. return 0;
  1125. err_free_rings:
  1126. _rtl_pci_free_rx_ring(rtlpci);
  1127. for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++)
  1128. if (rtlpci->tx_ring[i].desc)
  1129. _rtl_pci_free_tx_ring(hw, i);
  1130. return 1;
  1131. }
  1132. static int _rtl_pci_deinit_trx_ring(struct ieee80211_hw *hw)
  1133. {
  1134. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1135. u32 i;
  1136. /*free rx rings */
  1137. _rtl_pci_free_rx_ring(rtlpci);
  1138. /*free tx rings */
  1139. for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++)
  1140. _rtl_pci_free_tx_ring(hw, i);
  1141. return 0;
  1142. }
  1143. int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw)
  1144. {
  1145. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1146. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1147. int i, rx_queue_idx;
  1148. unsigned long flags;
  1149. u8 tmp_one = 1;
  1150. /*rx_queue_idx 0:RX_MPDU_QUEUE */
  1151. /*rx_queue_idx 1:RX_CMD_QUEUE */
  1152. for (rx_queue_idx = 0; rx_queue_idx < RTL_PCI_MAX_RX_QUEUE;
  1153. rx_queue_idx++) {
  1154. /*
  1155. *force the rx_ring[RX_MPDU_QUEUE/
  1156. *RX_CMD_QUEUE].idx to the first one
  1157. */
  1158. if (rtlpci->rx_ring[rx_queue_idx].desc) {
  1159. struct rtl_rx_desc *entry = NULL;
  1160. for (i = 0; i < rtlpci->rxringcount; i++) {
  1161. entry = &rtlpci->rx_ring[rx_queue_idx].desc[i];
  1162. rtlpriv->cfg->ops->set_desc((u8 *) entry,
  1163. false,
  1164. HW_DESC_RXOWN,
  1165. (u8 *)&tmp_one);
  1166. }
  1167. rtlpci->rx_ring[rx_queue_idx].idx = 0;
  1168. }
  1169. }
  1170. /*
  1171. *after reset, release previous pending packet,
  1172. *and force the tx idx to the first one
  1173. */
  1174. spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
  1175. for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) {
  1176. if (rtlpci->tx_ring[i].desc) {
  1177. struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[i];
  1178. while (skb_queue_len(&ring->queue)) {
  1179. struct rtl_tx_desc *entry =
  1180. &ring->desc[ring->idx];
  1181. struct sk_buff *skb =
  1182. __skb_dequeue(&ring->queue);
  1183. pci_unmap_single(rtlpci->pdev,
  1184. le32_to_cpu(rtlpriv->cfg->ops->
  1185. get_desc((u8 *)
  1186. entry,
  1187. true,
  1188. HW_DESC_TXBUFF_ADDR)),
  1189. skb->len, PCI_DMA_TODEVICE);
  1190. kfree_skb(skb);
  1191. ring->idx = (ring->idx + 1) % ring->entries;
  1192. }
  1193. ring->idx = 0;
  1194. }
  1195. }
  1196. spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
  1197. return 0;
  1198. }
  1199. static bool rtl_pci_tx_chk_waitq_insert(struct ieee80211_hw *hw,
  1200. struct sk_buff *skb)
  1201. {
  1202. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1203. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1204. struct ieee80211_sta *sta = info->control.sta;
  1205. struct rtl_sta_info *sta_entry = NULL;
  1206. u8 tid = rtl_get_tid(skb);
  1207. if (!sta)
  1208. return false;
  1209. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1210. if (!rtlpriv->rtlhal.earlymode_enable)
  1211. return false;
  1212. if (sta_entry->tids[tid].agg.agg_state != RTL_AGG_OPERATIONAL)
  1213. return false;
  1214. if (_rtl_mac_to_hwqueue(hw, skb) > VO_QUEUE)
  1215. return false;
  1216. if (tid > 7)
  1217. return false;
  1218. /* maybe every tid should be checked */
  1219. if (!rtlpriv->link_info.higher_busytxtraffic[tid])
  1220. return false;
  1221. spin_lock_bh(&rtlpriv->locks.waitq_lock);
  1222. skb_queue_tail(&rtlpriv->mac80211.skb_waitq[tid], skb);
  1223. spin_unlock_bh(&rtlpriv->locks.waitq_lock);
  1224. return true;
  1225. }
  1226. int rtl_pci_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  1227. struct rtl_tcb_desc *ptcb_desc)
  1228. {
  1229. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1230. struct rtl_sta_info *sta_entry = NULL;
  1231. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1232. struct ieee80211_sta *sta = info->control.sta;
  1233. struct rtl8192_tx_ring *ring;
  1234. struct rtl_tx_desc *pdesc;
  1235. u8 idx;
  1236. u8 hw_queue = _rtl_mac_to_hwqueue(hw, skb);
  1237. unsigned long flags;
  1238. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1239. __le16 fc = rtl_get_fc(skb);
  1240. u8 *pda_addr = hdr->addr1;
  1241. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1242. /*ssn */
  1243. u8 tid = 0;
  1244. u16 seq_number = 0;
  1245. u8 own;
  1246. u8 temp_one = 1;
  1247. if (ieee80211_is_auth(fc)) {
  1248. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, ("MAC80211_LINKING\n"));
  1249. rtl_ips_nic_on(hw);
  1250. }
  1251. if (rtlpriv->psc.sw_ps_enabled) {
  1252. if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) &&
  1253. !ieee80211_has_pm(fc))
  1254. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  1255. }
  1256. rtl_action_proc(hw, skb, true);
  1257. if (is_multicast_ether_addr(pda_addr))
  1258. rtlpriv->stats.txbytesmulticast += skb->len;
  1259. else if (is_broadcast_ether_addr(pda_addr))
  1260. rtlpriv->stats.txbytesbroadcast += skb->len;
  1261. else
  1262. rtlpriv->stats.txbytesunicast += skb->len;
  1263. spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
  1264. ring = &rtlpci->tx_ring[hw_queue];
  1265. if (hw_queue != BEACON_QUEUE)
  1266. idx = (ring->idx + skb_queue_len(&ring->queue)) %
  1267. ring->entries;
  1268. else
  1269. idx = 0;
  1270. pdesc = &ring->desc[idx];
  1271. own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) pdesc,
  1272. true, HW_DESC_OWN);
  1273. if ((own == 1) && (hw_queue != BEACON_QUEUE)) {
  1274. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1275. ("No more TX desc@%d, ring->idx = %d,"
  1276. "idx = %d, skb_queue_len = 0x%d\n",
  1277. hw_queue, ring->idx, idx,
  1278. skb_queue_len(&ring->queue)));
  1279. spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
  1280. return skb->len;
  1281. }
  1282. if (ieee80211_is_data_qos(fc)) {
  1283. tid = rtl_get_tid(skb);
  1284. if (sta) {
  1285. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1286. seq_number = (le16_to_cpu(hdr->seq_ctrl) &
  1287. IEEE80211_SCTL_SEQ) >> 4;
  1288. seq_number += 1;
  1289. if (!ieee80211_has_morefrags(hdr->frame_control))
  1290. sta_entry->tids[tid].seq_number = seq_number;
  1291. }
  1292. }
  1293. if (ieee80211_is_data(fc))
  1294. rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX);
  1295. #if 0 /* temporary */
  1296. rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc,
  1297. info, skb, hw_queue, ptcb_desc);
  1298. #endif
  1299. __skb_queue_tail(&ring->queue, skb);
  1300. rtlpriv->cfg->ops->set_desc((u8 *)pdesc, true,
  1301. HW_DESC_OWN, (u8 *)&temp_one);
  1302. if ((ring->entries - skb_queue_len(&ring->queue)) < 2 &&
  1303. hw_queue != BEACON_QUEUE) {
  1304. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  1305. ("less desc left, stop skb_queue@%d, "
  1306. "ring->idx = %d,"
  1307. "idx = %d, skb_queue_len = 0x%d\n",
  1308. hw_queue, ring->idx, idx,
  1309. skb_queue_len(&ring->queue)));
  1310. ieee80211_stop_queue(hw, skb_get_queue_mapping(skb));
  1311. }
  1312. spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
  1313. rtlpriv->cfg->ops->tx_polling(hw, hw_queue);
  1314. return 0;
  1315. }
  1316. static void rtl_pci_flush(struct ieee80211_hw *hw, bool drop)
  1317. {
  1318. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1319. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1320. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1321. u16 i = 0;
  1322. int queue_id;
  1323. struct rtl8192_tx_ring *ring;
  1324. for (queue_id = RTL_PCI_MAX_TX_QUEUE_COUNT - 1; queue_id >= 0;) {
  1325. u32 queue_len;
  1326. ring = &pcipriv->dev.tx_ring[queue_id];
  1327. queue_len = skb_queue_len(&ring->queue);
  1328. if (queue_len == 0 || queue_id == BEACON_QUEUE ||
  1329. queue_id == TXCMD_QUEUE) {
  1330. queue_id--;
  1331. continue;
  1332. } else {
  1333. msleep(20);
  1334. i++;
  1335. }
  1336. /* we just wait 1s for all queues */
  1337. if (rtlpriv->psc.rfpwr_state == ERFOFF ||
  1338. is_hal_stop(rtlhal) || i >= 200)
  1339. return;
  1340. }
  1341. }
  1342. void rtl_pci_deinit(struct ieee80211_hw *hw)
  1343. {
  1344. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1345. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1346. _rtl_pci_deinit_trx_ring(hw);
  1347. synchronize_irq(rtlpci->pdev->irq);
  1348. tasklet_kill(&rtlpriv->works.irq_tasklet);
  1349. flush_workqueue(rtlpriv->works.rtl_wq);
  1350. destroy_workqueue(rtlpriv->works.rtl_wq);
  1351. }
  1352. int rtl_pci_init(struct ieee80211_hw *hw, struct pci_dev *pdev)
  1353. {
  1354. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1355. int err;
  1356. _rtl_pci_init_struct(hw, pdev);
  1357. err = _rtl_pci_init_trx_ring(hw);
  1358. if (err) {
  1359. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1360. ("tx ring initialization failed"));
  1361. return err;
  1362. }
  1363. return 1;
  1364. }
  1365. int rtl_pci_start(struct ieee80211_hw *hw)
  1366. {
  1367. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1368. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1369. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1370. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1371. int err;
  1372. rtl_pci_reset_trx_ring(hw);
  1373. rtlpci->driver_is_goingto_unload = false;
  1374. err = rtlpriv->cfg->ops->hw_init(hw);
  1375. if (err) {
  1376. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1377. ("Failed to config hardware!\n"));
  1378. return err;
  1379. }
  1380. rtlpriv->cfg->ops->enable_interrupt(hw);
  1381. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("enable_interrupt OK\n"));
  1382. rtl_init_rx_config(hw);
  1383. /*should after adapter start and interrupt enable. */
  1384. set_hal_start(rtlhal);
  1385. RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1386. rtlpci->up_first_time = false;
  1387. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("OK\n"));
  1388. return 0;
  1389. }
  1390. void rtl_pci_stop(struct ieee80211_hw *hw)
  1391. {
  1392. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1393. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1394. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1395. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1396. unsigned long flags;
  1397. u8 RFInProgressTimeOut = 0;
  1398. /*
  1399. *should before disable interrrupt&adapter
  1400. *and will do it immediately.
  1401. */
  1402. set_hal_stop(rtlhal);
  1403. rtlpriv->cfg->ops->disable_interrupt(hw);
  1404. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
  1405. while (ppsc->rfchange_inprogress) {
  1406. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags);
  1407. if (RFInProgressTimeOut > 100) {
  1408. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
  1409. break;
  1410. }
  1411. mdelay(1);
  1412. RFInProgressTimeOut++;
  1413. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
  1414. }
  1415. ppsc->rfchange_inprogress = true;
  1416. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags);
  1417. rtlpci->driver_is_goingto_unload = true;
  1418. rtlpriv->cfg->ops->hw_disable(hw);
  1419. rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
  1420. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
  1421. ppsc->rfchange_inprogress = false;
  1422. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags);
  1423. rtl_pci_enable_aspm(hw);
  1424. }
  1425. static bool _rtl_pci_find_adapter(struct pci_dev *pdev,
  1426. struct ieee80211_hw *hw)
  1427. {
  1428. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1429. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1430. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1431. struct pci_dev *bridge_pdev = pdev->bus->self;
  1432. u16 venderid;
  1433. u16 deviceid;
  1434. u8 revisionid;
  1435. u16 irqline;
  1436. u8 tmp;
  1437. venderid = pdev->vendor;
  1438. deviceid = pdev->device;
  1439. pci_read_config_byte(pdev, 0x8, &revisionid);
  1440. pci_read_config_word(pdev, 0x3C, &irqline);
  1441. if (deviceid == RTL_PCI_8192_DID ||
  1442. deviceid == RTL_PCI_0044_DID ||
  1443. deviceid == RTL_PCI_0047_DID ||
  1444. deviceid == RTL_PCI_8192SE_DID ||
  1445. deviceid == RTL_PCI_8174_DID ||
  1446. deviceid == RTL_PCI_8173_DID ||
  1447. deviceid == RTL_PCI_8172_DID ||
  1448. deviceid == RTL_PCI_8171_DID) {
  1449. switch (revisionid) {
  1450. case RTL_PCI_REVISION_ID_8192PCIE:
  1451. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1452. ("8192 PCI-E is found - "
  1453. "vid/did=%x/%x\n", venderid, deviceid));
  1454. rtlhal->hw_type = HARDWARE_TYPE_RTL8192E;
  1455. break;
  1456. case RTL_PCI_REVISION_ID_8192SE:
  1457. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1458. ("8192SE is found - "
  1459. "vid/did=%x/%x\n", venderid, deviceid));
  1460. rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE;
  1461. break;
  1462. default:
  1463. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1464. ("Err: Unknown device - "
  1465. "vid/did=%x/%x\n", venderid, deviceid));
  1466. rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE;
  1467. break;
  1468. }
  1469. } else if (deviceid == RTL_PCI_8192CET_DID ||
  1470. deviceid == RTL_PCI_8192CE_DID ||
  1471. deviceid == RTL_PCI_8191CE_DID ||
  1472. deviceid == RTL_PCI_8188CE_DID) {
  1473. rtlhal->hw_type = HARDWARE_TYPE_RTL8192CE;
  1474. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1475. ("8192C PCI-E is found - "
  1476. "vid/did=%x/%x\n", venderid, deviceid));
  1477. } else if (deviceid == RTL_PCI_8192DE_DID ||
  1478. deviceid == RTL_PCI_8192DE_DID2) {
  1479. rtlhal->hw_type = HARDWARE_TYPE_RTL8192DE;
  1480. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1481. ("8192D PCI-E is found - "
  1482. "vid/did=%x/%x\n", venderid, deviceid));
  1483. } else {
  1484. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1485. ("Err: Unknown device -"
  1486. " vid/did=%x/%x\n", venderid, deviceid));
  1487. rtlhal->hw_type = RTL_DEFAULT_HARDWARE_TYPE;
  1488. }
  1489. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE) {
  1490. if (revisionid == 0 || revisionid == 1) {
  1491. if (revisionid == 0) {
  1492. RT_TRACE(rtlpriv, COMP_INIT,
  1493. DBG_LOUD, ("Find 92DE MAC0.\n"));
  1494. rtlhal->interfaceindex = 0;
  1495. } else if (revisionid == 1) {
  1496. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1497. ("Find 92DE MAC1.\n"));
  1498. rtlhal->interfaceindex = 1;
  1499. }
  1500. } else {
  1501. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1502. ("Unknown device - "
  1503. "VendorID/DeviceID=%x/%x, Revision=%x\n",
  1504. venderid, deviceid, revisionid));
  1505. rtlhal->interfaceindex = 0;
  1506. }
  1507. }
  1508. /*find bus info */
  1509. pcipriv->ndis_adapter.busnumber = pdev->bus->number;
  1510. pcipriv->ndis_adapter.devnumber = PCI_SLOT(pdev->devfn);
  1511. pcipriv->ndis_adapter.funcnumber = PCI_FUNC(pdev->devfn);
  1512. /*find bridge info */
  1513. pcipriv->ndis_adapter.pcibridge_vendorid = bridge_pdev->vendor;
  1514. for (tmp = 0; tmp < PCI_BRIDGE_VENDOR_MAX; tmp++) {
  1515. if (bridge_pdev->vendor == pcibridge_vendors[tmp]) {
  1516. pcipriv->ndis_adapter.pcibridge_vendor = tmp;
  1517. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1518. ("Pci Bridge Vendor is found index: %d\n",
  1519. tmp));
  1520. break;
  1521. }
  1522. }
  1523. if (pcipriv->ndis_adapter.pcibridge_vendor !=
  1524. PCI_BRIDGE_VENDOR_UNKNOWN) {
  1525. pcipriv->ndis_adapter.pcibridge_busnum =
  1526. bridge_pdev->bus->number;
  1527. pcipriv->ndis_adapter.pcibridge_devnum =
  1528. PCI_SLOT(bridge_pdev->devfn);
  1529. pcipriv->ndis_adapter.pcibridge_funcnum =
  1530. PCI_FUNC(bridge_pdev->devfn);
  1531. pcipriv->ndis_adapter.pcicfg_addrport =
  1532. (pcipriv->ndis_adapter.pcibridge_busnum << 16) |
  1533. (pcipriv->ndis_adapter.pcibridge_devnum << 11) |
  1534. (pcipriv->ndis_adapter.pcibridge_funcnum << 8) | (1 << 31);
  1535. pcipriv->ndis_adapter.pcibridge_pciehdr_offset =
  1536. pci_pcie_cap(bridge_pdev);
  1537. pcipriv->ndis_adapter.num4bytes =
  1538. (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10) / 4;
  1539. rtl_pci_get_linkcontrol_field(hw);
  1540. if (pcipriv->ndis_adapter.pcibridge_vendor ==
  1541. PCI_BRIDGE_VENDOR_AMD) {
  1542. pcipriv->ndis_adapter.amd_l1_patch =
  1543. rtl_pci_get_amd_l1_patch(hw);
  1544. }
  1545. }
  1546. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1547. ("pcidev busnumber:devnumber:funcnumber:"
  1548. "vendor:link_ctl %d:%d:%d:%x:%x\n",
  1549. pcipriv->ndis_adapter.busnumber,
  1550. pcipriv->ndis_adapter.devnumber,
  1551. pcipriv->ndis_adapter.funcnumber,
  1552. pdev->vendor, pcipriv->ndis_adapter.linkctrl_reg));
  1553. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1554. ("pci_bridge busnumber:devnumber:funcnumber:vendor:"
  1555. "pcie_cap:link_ctl_reg:amd %d:%d:%d:%x:%x:%x:%x\n",
  1556. pcipriv->ndis_adapter.pcibridge_busnum,
  1557. pcipriv->ndis_adapter.pcibridge_devnum,
  1558. pcipriv->ndis_adapter.pcibridge_funcnum,
  1559. pcibridge_vendors[pcipriv->ndis_adapter.pcibridge_vendor],
  1560. pcipriv->ndis_adapter.pcibridge_pciehdr_offset,
  1561. pcipriv->ndis_adapter.pcibridge_linkctrlreg,
  1562. pcipriv->ndis_adapter.amd_l1_patch));
  1563. rtl_pci_parse_configuration(pdev, hw);
  1564. return true;
  1565. }
  1566. int __devinit rtl_pci_probe(struct pci_dev *pdev,
  1567. const struct pci_device_id *id)
  1568. {
  1569. struct ieee80211_hw *hw = NULL;
  1570. struct rtl_priv *rtlpriv = NULL;
  1571. struct rtl_pci_priv *pcipriv = NULL;
  1572. struct rtl_pci *rtlpci;
  1573. unsigned long pmem_start, pmem_len, pmem_flags;
  1574. int err;
  1575. err = pci_enable_device(pdev);
  1576. if (err) {
  1577. RT_ASSERT(false,
  1578. ("%s : Cannot enable new PCI device\n",
  1579. pci_name(pdev)));
  1580. return err;
  1581. }
  1582. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  1583. if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
  1584. RT_ASSERT(false, ("Unable to obtain 32bit DMA "
  1585. "for consistent allocations\n"));
  1586. pci_disable_device(pdev);
  1587. return -ENOMEM;
  1588. }
  1589. }
  1590. pci_set_master(pdev);
  1591. hw = ieee80211_alloc_hw(sizeof(struct rtl_pci_priv) +
  1592. sizeof(struct rtl_priv), &rtl_ops);
  1593. if (!hw) {
  1594. RT_ASSERT(false,
  1595. ("%s : ieee80211 alloc failed\n", pci_name(pdev)));
  1596. err = -ENOMEM;
  1597. goto fail1;
  1598. }
  1599. SET_IEEE80211_DEV(hw, &pdev->dev);
  1600. pci_set_drvdata(pdev, hw);
  1601. rtlpriv = hw->priv;
  1602. pcipriv = (void *)rtlpriv->priv;
  1603. pcipriv->dev.pdev = pdev;
  1604. /* init cfg & intf_ops */
  1605. rtlpriv->rtlhal.interface = INTF_PCI;
  1606. rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_data);
  1607. rtlpriv->intf_ops = &rtl_pci_ops;
  1608. /*
  1609. *init dbgp flags before all
  1610. *other functions, because we will
  1611. *use it in other funtions like
  1612. *RT_TRACE/RT_PRINT/RTL_PRINT_DATA
  1613. *you can not use these macro
  1614. *before this
  1615. */
  1616. rtl_dbgp_flag_init(hw);
  1617. /* MEM map */
  1618. err = pci_request_regions(pdev, KBUILD_MODNAME);
  1619. if (err) {
  1620. RT_ASSERT(false, ("Can't obtain PCI resources\n"));
  1621. return err;
  1622. }
  1623. pmem_start = pci_resource_start(pdev, rtlpriv->cfg->bar_id);
  1624. pmem_len = pci_resource_len(pdev, rtlpriv->cfg->bar_id);
  1625. pmem_flags = pci_resource_flags(pdev, rtlpriv->cfg->bar_id);
  1626. /*shared mem start */
  1627. rtlpriv->io.pci_mem_start =
  1628. (unsigned long)pci_iomap(pdev,
  1629. rtlpriv->cfg->bar_id, pmem_len);
  1630. if (rtlpriv->io.pci_mem_start == 0) {
  1631. RT_ASSERT(false, ("Can't map PCI mem\n"));
  1632. goto fail2;
  1633. }
  1634. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1635. ("mem mapped space: start: 0x%08lx len:%08lx "
  1636. "flags:%08lx, after map:0x%08lx\n",
  1637. pmem_start, pmem_len, pmem_flags,
  1638. rtlpriv->io.pci_mem_start));
  1639. /* Disable Clk Request */
  1640. pci_write_config_byte(pdev, 0x81, 0);
  1641. /* leave D3 mode */
  1642. pci_write_config_byte(pdev, 0x44, 0);
  1643. pci_write_config_byte(pdev, 0x04, 0x06);
  1644. pci_write_config_byte(pdev, 0x04, 0x07);
  1645. /* find adapter */
  1646. _rtl_pci_find_adapter(pdev, hw);
  1647. /* Init IO handler */
  1648. _rtl_pci_io_handler_init(&pdev->dev, hw);
  1649. /*like read eeprom and so on */
  1650. rtlpriv->cfg->ops->read_eeprom_info(hw);
  1651. if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
  1652. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1653. ("Can't init_sw_vars.\n"));
  1654. goto fail3;
  1655. }
  1656. rtlpriv->cfg->ops->init_sw_leds(hw);
  1657. /*aspm */
  1658. rtl_pci_init_aspm(hw);
  1659. /* Init mac80211 sw */
  1660. err = rtl_init_core(hw);
  1661. if (err) {
  1662. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1663. ("Can't allocate sw for mac80211.\n"));
  1664. goto fail3;
  1665. }
  1666. /* Init PCI sw */
  1667. err = !rtl_pci_init(hw, pdev);
  1668. if (err) {
  1669. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1670. ("Failed to init PCI.\n"));
  1671. goto fail3;
  1672. }
  1673. err = ieee80211_register_hw(hw);
  1674. if (err) {
  1675. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1676. ("Can't register mac80211 hw.\n"));
  1677. goto fail3;
  1678. } else {
  1679. rtlpriv->mac80211.mac80211_registered = 1;
  1680. }
  1681. err = sysfs_create_group(&pdev->dev.kobj, &rtl_attribute_group);
  1682. if (err) {
  1683. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1684. ("failed to create sysfs device attributes\n"));
  1685. goto fail3;
  1686. }
  1687. /*init rfkill */
  1688. rtl_init_rfkill(hw);
  1689. rtlpci = rtl_pcidev(pcipriv);
  1690. err = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt,
  1691. IRQF_SHARED, KBUILD_MODNAME, hw);
  1692. if (err) {
  1693. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1694. ("%s: failed to register IRQ handler\n",
  1695. wiphy_name(hw->wiphy)));
  1696. goto fail3;
  1697. } else {
  1698. rtlpci->irq_alloc = 1;
  1699. }
  1700. set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
  1701. return 0;
  1702. fail3:
  1703. pci_set_drvdata(pdev, NULL);
  1704. rtl_deinit_core(hw);
  1705. _rtl_pci_io_handler_release(hw);
  1706. ieee80211_free_hw(hw);
  1707. if (rtlpriv->io.pci_mem_start != 0)
  1708. pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start);
  1709. fail2:
  1710. pci_release_regions(pdev);
  1711. fail1:
  1712. pci_disable_device(pdev);
  1713. return -ENODEV;
  1714. }
  1715. EXPORT_SYMBOL(rtl_pci_probe);
  1716. void rtl_pci_disconnect(struct pci_dev *pdev)
  1717. {
  1718. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  1719. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1720. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1721. struct rtl_pci *rtlpci = rtl_pcidev(pcipriv);
  1722. struct rtl_mac *rtlmac = rtl_mac(rtlpriv);
  1723. clear_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
  1724. sysfs_remove_group(&pdev->dev.kobj, &rtl_attribute_group);
  1725. /*ieee80211_unregister_hw will call ops_stop */
  1726. if (rtlmac->mac80211_registered == 1) {
  1727. ieee80211_unregister_hw(hw);
  1728. rtlmac->mac80211_registered = 0;
  1729. } else {
  1730. rtl_deinit_deferred_work(hw);
  1731. rtlpriv->intf_ops->adapter_stop(hw);
  1732. }
  1733. /*deinit rfkill */
  1734. rtl_deinit_rfkill(hw);
  1735. rtl_pci_deinit(hw);
  1736. rtl_deinit_core(hw);
  1737. _rtl_pci_io_handler_release(hw);
  1738. rtlpriv->cfg->ops->deinit_sw_vars(hw);
  1739. if (rtlpci->irq_alloc) {
  1740. free_irq(rtlpci->pdev->irq, hw);
  1741. rtlpci->irq_alloc = 0;
  1742. }
  1743. if (rtlpriv->io.pci_mem_start != 0) {
  1744. pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start);
  1745. pci_release_regions(pdev);
  1746. }
  1747. pci_disable_device(pdev);
  1748. rtl_pci_disable_aspm(hw);
  1749. pci_set_drvdata(pdev, NULL);
  1750. ieee80211_free_hw(hw);
  1751. }
  1752. EXPORT_SYMBOL(rtl_pci_disconnect);
  1753. /***************************************
  1754. kernel pci power state define:
  1755. PCI_D0 ((pci_power_t __force) 0)
  1756. PCI_D1 ((pci_power_t __force) 1)
  1757. PCI_D2 ((pci_power_t __force) 2)
  1758. PCI_D3hot ((pci_power_t __force) 3)
  1759. PCI_D3cold ((pci_power_t __force) 4)
  1760. PCI_UNKNOWN ((pci_power_t __force) 5)
  1761. This function is called when system
  1762. goes into suspend state mac80211 will
  1763. call rtl_mac_stop() from the mac80211
  1764. suspend function first, So there is
  1765. no need to call hw_disable here.
  1766. ****************************************/
  1767. int rtl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1768. {
  1769. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  1770. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1771. rtlpriv->cfg->ops->hw_suspend(hw);
  1772. rtl_deinit_rfkill(hw);
  1773. pci_save_state(pdev);
  1774. pci_disable_device(pdev);
  1775. pci_set_power_state(pdev, PCI_D3hot);
  1776. return 0;
  1777. }
  1778. EXPORT_SYMBOL(rtl_pci_suspend);
  1779. int rtl_pci_resume(struct pci_dev *pdev)
  1780. {
  1781. int ret;
  1782. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  1783. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1784. pci_set_power_state(pdev, PCI_D0);
  1785. ret = pci_enable_device(pdev);
  1786. if (ret) {
  1787. RT_ASSERT(false, ("ERR: <======\n"));
  1788. return ret;
  1789. }
  1790. pci_restore_state(pdev);
  1791. rtlpriv->cfg->ops->hw_resume(hw);
  1792. rtl_init_rfkill(hw);
  1793. return 0;
  1794. }
  1795. EXPORT_SYMBOL(rtl_pci_resume);
  1796. struct rtl_intf_ops rtl_pci_ops = {
  1797. .read_efuse_byte = read_efuse_byte,
  1798. .adapter_start = rtl_pci_start,
  1799. .adapter_stop = rtl_pci_stop,
  1800. .adapter_tx = rtl_pci_tx,
  1801. .flush = rtl_pci_flush,
  1802. .reset_trx_ring = rtl_pci_reset_trx_ring,
  1803. .waitq_insert = rtl_pci_tx_chk_waitq_insert,
  1804. .disable_aspm = rtl_pci_disable_aspm,
  1805. .enable_aspm = rtl_pci_enable_aspm,
  1806. };