pci.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190
  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. rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc,
  1296. info, skb, hw_queue, ptcb_desc);
  1297. __skb_queue_tail(&ring->queue, skb);
  1298. rtlpriv->cfg->ops->set_desc((u8 *)pdesc, true,
  1299. HW_DESC_OWN, (u8 *)&temp_one);
  1300. if ((ring->entries - skb_queue_len(&ring->queue)) < 2 &&
  1301. hw_queue != BEACON_QUEUE) {
  1302. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  1303. ("less desc left, stop skb_queue@%d, "
  1304. "ring->idx = %d,"
  1305. "idx = %d, skb_queue_len = 0x%d\n",
  1306. hw_queue, ring->idx, idx,
  1307. skb_queue_len(&ring->queue)));
  1308. ieee80211_stop_queue(hw, skb_get_queue_mapping(skb));
  1309. }
  1310. spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
  1311. rtlpriv->cfg->ops->tx_polling(hw, hw_queue);
  1312. return 0;
  1313. }
  1314. static void rtl_pci_flush(struct ieee80211_hw *hw, bool drop)
  1315. {
  1316. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1317. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1318. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1319. u16 i = 0;
  1320. int queue_id;
  1321. struct rtl8192_tx_ring *ring;
  1322. for (queue_id = RTL_PCI_MAX_TX_QUEUE_COUNT - 1; queue_id >= 0;) {
  1323. u32 queue_len;
  1324. ring = &pcipriv->dev.tx_ring[queue_id];
  1325. queue_len = skb_queue_len(&ring->queue);
  1326. if (queue_len == 0 || queue_id == BEACON_QUEUE ||
  1327. queue_id == TXCMD_QUEUE) {
  1328. queue_id--;
  1329. continue;
  1330. } else {
  1331. msleep(20);
  1332. i++;
  1333. }
  1334. /* we just wait 1s for all queues */
  1335. if (rtlpriv->psc.rfpwr_state == ERFOFF ||
  1336. is_hal_stop(rtlhal) || i >= 200)
  1337. return;
  1338. }
  1339. }
  1340. void rtl_pci_deinit(struct ieee80211_hw *hw)
  1341. {
  1342. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1343. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1344. _rtl_pci_deinit_trx_ring(hw);
  1345. synchronize_irq(rtlpci->pdev->irq);
  1346. tasklet_kill(&rtlpriv->works.irq_tasklet);
  1347. flush_workqueue(rtlpriv->works.rtl_wq);
  1348. destroy_workqueue(rtlpriv->works.rtl_wq);
  1349. }
  1350. int rtl_pci_init(struct ieee80211_hw *hw, struct pci_dev *pdev)
  1351. {
  1352. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1353. int err;
  1354. _rtl_pci_init_struct(hw, pdev);
  1355. err = _rtl_pci_init_trx_ring(hw);
  1356. if (err) {
  1357. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1358. ("tx ring initialization failed"));
  1359. return err;
  1360. }
  1361. return 1;
  1362. }
  1363. int rtl_pci_start(struct ieee80211_hw *hw)
  1364. {
  1365. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1366. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1367. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1368. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1369. int err;
  1370. rtl_pci_reset_trx_ring(hw);
  1371. rtlpci->driver_is_goingto_unload = false;
  1372. err = rtlpriv->cfg->ops->hw_init(hw);
  1373. if (err) {
  1374. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1375. ("Failed to config hardware!\n"));
  1376. return err;
  1377. }
  1378. rtlpriv->cfg->ops->enable_interrupt(hw);
  1379. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("enable_interrupt OK\n"));
  1380. rtl_init_rx_config(hw);
  1381. /*should after adapter start and interrupt enable. */
  1382. set_hal_start(rtlhal);
  1383. RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1384. rtlpci->up_first_time = false;
  1385. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("OK\n"));
  1386. return 0;
  1387. }
  1388. void rtl_pci_stop(struct ieee80211_hw *hw)
  1389. {
  1390. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1391. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1392. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1393. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1394. unsigned long flags;
  1395. u8 RFInProgressTimeOut = 0;
  1396. /*
  1397. *should before disable interrrupt&adapter
  1398. *and will do it immediately.
  1399. */
  1400. set_hal_stop(rtlhal);
  1401. rtlpriv->cfg->ops->disable_interrupt(hw);
  1402. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
  1403. while (ppsc->rfchange_inprogress) {
  1404. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags);
  1405. if (RFInProgressTimeOut > 100) {
  1406. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
  1407. break;
  1408. }
  1409. mdelay(1);
  1410. RFInProgressTimeOut++;
  1411. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
  1412. }
  1413. ppsc->rfchange_inprogress = true;
  1414. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags);
  1415. rtlpci->driver_is_goingto_unload = true;
  1416. rtlpriv->cfg->ops->hw_disable(hw);
  1417. rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
  1418. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
  1419. ppsc->rfchange_inprogress = false;
  1420. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags);
  1421. rtl_pci_enable_aspm(hw);
  1422. }
  1423. static bool _rtl_pci_find_adapter(struct pci_dev *pdev,
  1424. struct ieee80211_hw *hw)
  1425. {
  1426. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1427. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1428. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1429. struct pci_dev *bridge_pdev = pdev->bus->self;
  1430. u16 venderid;
  1431. u16 deviceid;
  1432. u8 revisionid;
  1433. u16 irqline;
  1434. u8 tmp;
  1435. venderid = pdev->vendor;
  1436. deviceid = pdev->device;
  1437. pci_read_config_byte(pdev, 0x8, &revisionid);
  1438. pci_read_config_word(pdev, 0x3C, &irqline);
  1439. if (deviceid == RTL_PCI_8192_DID ||
  1440. deviceid == RTL_PCI_0044_DID ||
  1441. deviceid == RTL_PCI_0047_DID ||
  1442. deviceid == RTL_PCI_8192SE_DID ||
  1443. deviceid == RTL_PCI_8174_DID ||
  1444. deviceid == RTL_PCI_8173_DID ||
  1445. deviceid == RTL_PCI_8172_DID ||
  1446. deviceid == RTL_PCI_8171_DID) {
  1447. switch (revisionid) {
  1448. case RTL_PCI_REVISION_ID_8192PCIE:
  1449. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1450. ("8192 PCI-E is found - "
  1451. "vid/did=%x/%x\n", venderid, deviceid));
  1452. rtlhal->hw_type = HARDWARE_TYPE_RTL8192E;
  1453. break;
  1454. case RTL_PCI_REVISION_ID_8192SE:
  1455. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1456. ("8192SE is found - "
  1457. "vid/did=%x/%x\n", venderid, deviceid));
  1458. rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE;
  1459. break;
  1460. default:
  1461. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1462. ("Err: Unknown device - "
  1463. "vid/did=%x/%x\n", venderid, deviceid));
  1464. rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE;
  1465. break;
  1466. }
  1467. } else if (deviceid == RTL_PCI_8192CET_DID ||
  1468. deviceid == RTL_PCI_8192CE_DID ||
  1469. deviceid == RTL_PCI_8191CE_DID ||
  1470. deviceid == RTL_PCI_8188CE_DID) {
  1471. rtlhal->hw_type = HARDWARE_TYPE_RTL8192CE;
  1472. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1473. ("8192C PCI-E is found - "
  1474. "vid/did=%x/%x\n", venderid, deviceid));
  1475. } else if (deviceid == RTL_PCI_8192DE_DID ||
  1476. deviceid == RTL_PCI_8192DE_DID2) {
  1477. rtlhal->hw_type = HARDWARE_TYPE_RTL8192DE;
  1478. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1479. ("8192D PCI-E is found - "
  1480. "vid/did=%x/%x\n", venderid, deviceid));
  1481. } else {
  1482. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1483. ("Err: Unknown device -"
  1484. " vid/did=%x/%x\n", venderid, deviceid));
  1485. rtlhal->hw_type = RTL_DEFAULT_HARDWARE_TYPE;
  1486. }
  1487. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE) {
  1488. if (revisionid == 0 || revisionid == 1) {
  1489. if (revisionid == 0) {
  1490. RT_TRACE(rtlpriv, COMP_INIT,
  1491. DBG_LOUD, ("Find 92DE MAC0.\n"));
  1492. rtlhal->interfaceindex = 0;
  1493. } else if (revisionid == 1) {
  1494. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1495. ("Find 92DE MAC1.\n"));
  1496. rtlhal->interfaceindex = 1;
  1497. }
  1498. } else {
  1499. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1500. ("Unknown device - "
  1501. "VendorID/DeviceID=%x/%x, Revision=%x\n",
  1502. venderid, deviceid, revisionid));
  1503. rtlhal->interfaceindex = 0;
  1504. }
  1505. }
  1506. /*find bus info */
  1507. pcipriv->ndis_adapter.busnumber = pdev->bus->number;
  1508. pcipriv->ndis_adapter.devnumber = PCI_SLOT(pdev->devfn);
  1509. pcipriv->ndis_adapter.funcnumber = PCI_FUNC(pdev->devfn);
  1510. /*find bridge info */
  1511. pcipriv->ndis_adapter.pcibridge_vendorid = bridge_pdev->vendor;
  1512. for (tmp = 0; tmp < PCI_BRIDGE_VENDOR_MAX; tmp++) {
  1513. if (bridge_pdev->vendor == pcibridge_vendors[tmp]) {
  1514. pcipriv->ndis_adapter.pcibridge_vendor = tmp;
  1515. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1516. ("Pci Bridge Vendor is found index: %d\n",
  1517. tmp));
  1518. break;
  1519. }
  1520. }
  1521. if (pcipriv->ndis_adapter.pcibridge_vendor !=
  1522. PCI_BRIDGE_VENDOR_UNKNOWN) {
  1523. pcipriv->ndis_adapter.pcibridge_busnum =
  1524. bridge_pdev->bus->number;
  1525. pcipriv->ndis_adapter.pcibridge_devnum =
  1526. PCI_SLOT(bridge_pdev->devfn);
  1527. pcipriv->ndis_adapter.pcibridge_funcnum =
  1528. PCI_FUNC(bridge_pdev->devfn);
  1529. pcipriv->ndis_adapter.pcicfg_addrport =
  1530. (pcipriv->ndis_adapter.pcibridge_busnum << 16) |
  1531. (pcipriv->ndis_adapter.pcibridge_devnum << 11) |
  1532. (pcipriv->ndis_adapter.pcibridge_funcnum << 8) | (1 << 31);
  1533. pcipriv->ndis_adapter.pcibridge_pciehdr_offset =
  1534. pci_pcie_cap(bridge_pdev);
  1535. pcipriv->ndis_adapter.num4bytes =
  1536. (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10) / 4;
  1537. rtl_pci_get_linkcontrol_field(hw);
  1538. if (pcipriv->ndis_adapter.pcibridge_vendor ==
  1539. PCI_BRIDGE_VENDOR_AMD) {
  1540. pcipriv->ndis_adapter.amd_l1_patch =
  1541. rtl_pci_get_amd_l1_patch(hw);
  1542. }
  1543. }
  1544. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1545. ("pcidev busnumber:devnumber:funcnumber:"
  1546. "vendor:link_ctl %d:%d:%d:%x:%x\n",
  1547. pcipriv->ndis_adapter.busnumber,
  1548. pcipriv->ndis_adapter.devnumber,
  1549. pcipriv->ndis_adapter.funcnumber,
  1550. pdev->vendor, pcipriv->ndis_adapter.linkctrl_reg));
  1551. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1552. ("pci_bridge busnumber:devnumber:funcnumber:vendor:"
  1553. "pcie_cap:link_ctl_reg:amd %d:%d:%d:%x:%x:%x:%x\n",
  1554. pcipriv->ndis_adapter.pcibridge_busnum,
  1555. pcipriv->ndis_adapter.pcibridge_devnum,
  1556. pcipriv->ndis_adapter.pcibridge_funcnum,
  1557. pcibridge_vendors[pcipriv->ndis_adapter.pcibridge_vendor],
  1558. pcipriv->ndis_adapter.pcibridge_pciehdr_offset,
  1559. pcipriv->ndis_adapter.pcibridge_linkctrlreg,
  1560. pcipriv->ndis_adapter.amd_l1_patch));
  1561. rtl_pci_parse_configuration(pdev, hw);
  1562. return true;
  1563. }
  1564. int __devinit rtl_pci_probe(struct pci_dev *pdev,
  1565. const struct pci_device_id *id)
  1566. {
  1567. struct ieee80211_hw *hw = NULL;
  1568. struct rtl_priv *rtlpriv = NULL;
  1569. struct rtl_pci_priv *pcipriv = NULL;
  1570. struct rtl_pci *rtlpci;
  1571. unsigned long pmem_start, pmem_len, pmem_flags;
  1572. int err;
  1573. err = pci_enable_device(pdev);
  1574. if (err) {
  1575. RT_ASSERT(false,
  1576. ("%s : Cannot enable new PCI device\n",
  1577. pci_name(pdev)));
  1578. return err;
  1579. }
  1580. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  1581. if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
  1582. RT_ASSERT(false, ("Unable to obtain 32bit DMA "
  1583. "for consistent allocations\n"));
  1584. pci_disable_device(pdev);
  1585. return -ENOMEM;
  1586. }
  1587. }
  1588. pci_set_master(pdev);
  1589. hw = ieee80211_alloc_hw(sizeof(struct rtl_pci_priv) +
  1590. sizeof(struct rtl_priv), &rtl_ops);
  1591. if (!hw) {
  1592. RT_ASSERT(false,
  1593. ("%s : ieee80211 alloc failed\n", pci_name(pdev)));
  1594. err = -ENOMEM;
  1595. goto fail1;
  1596. }
  1597. SET_IEEE80211_DEV(hw, &pdev->dev);
  1598. pci_set_drvdata(pdev, hw);
  1599. rtlpriv = hw->priv;
  1600. pcipriv = (void *)rtlpriv->priv;
  1601. pcipriv->dev.pdev = pdev;
  1602. /* init cfg & intf_ops */
  1603. rtlpriv->rtlhal.interface = INTF_PCI;
  1604. rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_data);
  1605. rtlpriv->intf_ops = &rtl_pci_ops;
  1606. /*
  1607. *init dbgp flags before all
  1608. *other functions, because we will
  1609. *use it in other funtions like
  1610. *RT_TRACE/RT_PRINT/RTL_PRINT_DATA
  1611. *you can not use these macro
  1612. *before this
  1613. */
  1614. rtl_dbgp_flag_init(hw);
  1615. /* MEM map */
  1616. err = pci_request_regions(pdev, KBUILD_MODNAME);
  1617. if (err) {
  1618. RT_ASSERT(false, ("Can't obtain PCI resources\n"));
  1619. return err;
  1620. }
  1621. pmem_start = pci_resource_start(pdev, rtlpriv->cfg->bar_id);
  1622. pmem_len = pci_resource_len(pdev, rtlpriv->cfg->bar_id);
  1623. pmem_flags = pci_resource_flags(pdev, rtlpriv->cfg->bar_id);
  1624. /*shared mem start */
  1625. rtlpriv->io.pci_mem_start =
  1626. (unsigned long)pci_iomap(pdev,
  1627. rtlpriv->cfg->bar_id, pmem_len);
  1628. if (rtlpriv->io.pci_mem_start == 0) {
  1629. RT_ASSERT(false, ("Can't map PCI mem\n"));
  1630. goto fail2;
  1631. }
  1632. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1633. ("mem mapped space: start: 0x%08lx len:%08lx "
  1634. "flags:%08lx, after map:0x%08lx\n",
  1635. pmem_start, pmem_len, pmem_flags,
  1636. rtlpriv->io.pci_mem_start));
  1637. /* Disable Clk Request */
  1638. pci_write_config_byte(pdev, 0x81, 0);
  1639. /* leave D3 mode */
  1640. pci_write_config_byte(pdev, 0x44, 0);
  1641. pci_write_config_byte(pdev, 0x04, 0x06);
  1642. pci_write_config_byte(pdev, 0x04, 0x07);
  1643. /* find adapter */
  1644. _rtl_pci_find_adapter(pdev, hw);
  1645. /* Init IO handler */
  1646. _rtl_pci_io_handler_init(&pdev->dev, hw);
  1647. /*like read eeprom and so on */
  1648. rtlpriv->cfg->ops->read_eeprom_info(hw);
  1649. if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
  1650. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1651. ("Can't init_sw_vars.\n"));
  1652. goto fail3;
  1653. }
  1654. rtlpriv->cfg->ops->init_sw_leds(hw);
  1655. /*aspm */
  1656. rtl_pci_init_aspm(hw);
  1657. /* Init mac80211 sw */
  1658. err = rtl_init_core(hw);
  1659. if (err) {
  1660. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1661. ("Can't allocate sw for mac80211.\n"));
  1662. goto fail3;
  1663. }
  1664. /* Init PCI sw */
  1665. err = !rtl_pci_init(hw, pdev);
  1666. if (err) {
  1667. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1668. ("Failed to init PCI.\n"));
  1669. goto fail3;
  1670. }
  1671. err = ieee80211_register_hw(hw);
  1672. if (err) {
  1673. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1674. ("Can't register mac80211 hw.\n"));
  1675. goto fail3;
  1676. } else {
  1677. rtlpriv->mac80211.mac80211_registered = 1;
  1678. }
  1679. err = sysfs_create_group(&pdev->dev.kobj, &rtl_attribute_group);
  1680. if (err) {
  1681. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1682. ("failed to create sysfs device attributes\n"));
  1683. goto fail3;
  1684. }
  1685. /*init rfkill */
  1686. rtl_init_rfkill(hw);
  1687. rtlpci = rtl_pcidev(pcipriv);
  1688. err = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt,
  1689. IRQF_SHARED, KBUILD_MODNAME, hw);
  1690. if (err) {
  1691. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1692. ("%s: failed to register IRQ handler\n",
  1693. wiphy_name(hw->wiphy)));
  1694. goto fail3;
  1695. } else {
  1696. rtlpci->irq_alloc = 1;
  1697. }
  1698. set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
  1699. return 0;
  1700. fail3:
  1701. pci_set_drvdata(pdev, NULL);
  1702. rtl_deinit_core(hw);
  1703. _rtl_pci_io_handler_release(hw);
  1704. ieee80211_free_hw(hw);
  1705. if (rtlpriv->io.pci_mem_start != 0)
  1706. pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start);
  1707. fail2:
  1708. pci_release_regions(pdev);
  1709. fail1:
  1710. pci_disable_device(pdev);
  1711. return -ENODEV;
  1712. }
  1713. EXPORT_SYMBOL(rtl_pci_probe);
  1714. void rtl_pci_disconnect(struct pci_dev *pdev)
  1715. {
  1716. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  1717. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1718. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1719. struct rtl_pci *rtlpci = rtl_pcidev(pcipriv);
  1720. struct rtl_mac *rtlmac = rtl_mac(rtlpriv);
  1721. clear_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
  1722. sysfs_remove_group(&pdev->dev.kobj, &rtl_attribute_group);
  1723. /*ieee80211_unregister_hw will call ops_stop */
  1724. if (rtlmac->mac80211_registered == 1) {
  1725. ieee80211_unregister_hw(hw);
  1726. rtlmac->mac80211_registered = 0;
  1727. } else {
  1728. rtl_deinit_deferred_work(hw);
  1729. rtlpriv->intf_ops->adapter_stop(hw);
  1730. }
  1731. /*deinit rfkill */
  1732. rtl_deinit_rfkill(hw);
  1733. rtl_pci_deinit(hw);
  1734. rtl_deinit_core(hw);
  1735. _rtl_pci_io_handler_release(hw);
  1736. rtlpriv->cfg->ops->deinit_sw_vars(hw);
  1737. if (rtlpci->irq_alloc) {
  1738. free_irq(rtlpci->pdev->irq, hw);
  1739. rtlpci->irq_alloc = 0;
  1740. }
  1741. if (rtlpriv->io.pci_mem_start != 0) {
  1742. pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start);
  1743. pci_release_regions(pdev);
  1744. }
  1745. pci_disable_device(pdev);
  1746. rtl_pci_disable_aspm(hw);
  1747. pci_set_drvdata(pdev, NULL);
  1748. ieee80211_free_hw(hw);
  1749. }
  1750. EXPORT_SYMBOL(rtl_pci_disconnect);
  1751. /***************************************
  1752. kernel pci power state define:
  1753. PCI_D0 ((pci_power_t __force) 0)
  1754. PCI_D1 ((pci_power_t __force) 1)
  1755. PCI_D2 ((pci_power_t __force) 2)
  1756. PCI_D3hot ((pci_power_t __force) 3)
  1757. PCI_D3cold ((pci_power_t __force) 4)
  1758. PCI_UNKNOWN ((pci_power_t __force) 5)
  1759. This function is called when system
  1760. goes into suspend state mac80211 will
  1761. call rtl_mac_stop() from the mac80211
  1762. suspend function first, So there is
  1763. no need to call hw_disable here.
  1764. ****************************************/
  1765. int rtl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1766. {
  1767. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  1768. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1769. rtlpriv->cfg->ops->hw_suspend(hw);
  1770. rtl_deinit_rfkill(hw);
  1771. pci_save_state(pdev);
  1772. pci_disable_device(pdev);
  1773. pci_set_power_state(pdev, PCI_D3hot);
  1774. return 0;
  1775. }
  1776. EXPORT_SYMBOL(rtl_pci_suspend);
  1777. int rtl_pci_resume(struct pci_dev *pdev)
  1778. {
  1779. int ret;
  1780. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  1781. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1782. pci_set_power_state(pdev, PCI_D0);
  1783. ret = pci_enable_device(pdev);
  1784. if (ret) {
  1785. RT_ASSERT(false, ("ERR: <======\n"));
  1786. return ret;
  1787. }
  1788. pci_restore_state(pdev);
  1789. rtlpriv->cfg->ops->hw_resume(hw);
  1790. rtl_init_rfkill(hw);
  1791. return 0;
  1792. }
  1793. EXPORT_SYMBOL(rtl_pci_resume);
  1794. struct rtl_intf_ops rtl_pci_ops = {
  1795. .read_efuse_byte = read_efuse_byte,
  1796. .adapter_start = rtl_pci_start,
  1797. .adapter_stop = rtl_pci_stop,
  1798. .adapter_tx = rtl_pci_tx,
  1799. .flush = rtl_pci_flush,
  1800. .reset_trx_ring = rtl_pci_reset_trx_ring,
  1801. .waitq_insert = rtl_pci_tx_chk_waitq_insert,
  1802. .disable_aspm = rtl_pci_disable_aspm,
  1803. .enable_aspm = rtl_pci_enable_aspm,
  1804. };