pci.c 56 KB

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