pci_intf.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 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. *****************************************************************************/
  15. #define _HCI_INTF_C_
  16. #include <drv_types.h>
  17. #include <hal_data.h>
  18. #include <linux/pci_regs.h>
  19. #ifndef CONFIG_PCI_HCI
  20. #error "CONFIG_PCI_HCI shall be on!\n"
  21. #endif
  22. #if defined(PLATFORM_LINUX) && defined(PLATFORM_WINDOWS)
  23. #error "Shall be Linux or Windows, but not both!\n"
  24. #endif
  25. #ifdef CONFIG_80211N_HT
  26. extern int rtw_ht_enable;
  27. extern int rtw_bw_mode;
  28. extern int rtw_ampdu_enable;/* for enable tx_ampdu */
  29. #endif
  30. #ifdef CONFIG_GLOBAL_UI_PID
  31. int ui_pid[3] = {0, 0, 0};
  32. #endif
  33. extern int pm_netdev_open(struct net_device *pnetdev, u8 bnormal);
  34. int rtw_resume_process(_adapter *padapter);
  35. #ifdef CONFIG_PM
  36. static int rtw_pci_suspend(struct pci_dev *pdev, pm_message_t state);
  37. static int rtw_pci_resume(struct pci_dev *pdev);
  38. #endif
  39. static int rtw_drv_init(struct pci_dev *pdev, const struct pci_device_id *pdid);
  40. static void rtw_dev_remove(struct pci_dev *pdev);
  41. static void rtw_dev_shutdown(struct pci_dev *pdev);
  42. static struct specific_device_id specific_device_id_tbl[] = {
  43. {.idVendor = 0x0b05, .idProduct = 0x1791, .flags = SPEC_DEV_ID_DISABLE_HT},
  44. {.idVendor = 0x13D3, .idProduct = 0x3311, .flags = SPEC_DEV_ID_DISABLE_HT},
  45. {}
  46. };
  47. struct pci_device_id rtw_pci_id_tbl[] = {
  48. #ifdef CONFIG_RTL8188E
  49. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8179), .driver_data = RTL8188E},
  50. #endif
  51. #ifdef CONFIG_RTL8812A
  52. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8812), .driver_data = RTL8812},
  53. #endif
  54. #ifdef CONFIG_RTL8821A
  55. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8821), .driver_data = RTL8821},
  56. #endif
  57. #ifdef CONFIG_RTL8192E
  58. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x818B), .driver_data = RTL8192E},
  59. #endif
  60. #ifdef CONFIG_RTL8192F
  61. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0xf192), .driver_data = RTL8192F},
  62. #endif
  63. #ifdef CONFIG_RTL8723B
  64. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0xb723), .driver_data = RTL8723B},
  65. #endif
  66. #ifdef CONFIG_RTL8723D
  67. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0xd723), .driver_data = RTL8723D},
  68. #endif
  69. #ifdef CONFIG_RTL8814A
  70. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0x8813), .driver_data = RTL8814A},
  71. #endif
  72. #ifdef CONFIG_RTL8822B
  73. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0xB822), .driver_data = RTL8822B},
  74. #endif
  75. #ifdef CONFIG_RTL8821C
  76. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0xB821), .driver_data = RTL8821C},
  77. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0xC821), .driver_data = RTL8821C},
  78. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0xC82A), .driver_data = RTL8821C},
  79. {PCI_DEVICE(PCI_VENDER_ID_REALTEK, 0xC82B), .driver_data = RTL8821C},
  80. #endif
  81. {},
  82. };
  83. struct pci_drv_priv {
  84. struct pci_driver rtw_pci_drv;
  85. int drv_registered;
  86. };
  87. static struct pci_drv_priv pci_drvpriv = {
  88. .rtw_pci_drv.name = (char *)DRV_NAME,
  89. .rtw_pci_drv.probe = rtw_drv_init,
  90. .rtw_pci_drv.remove = rtw_dev_remove,
  91. .rtw_pci_drv.shutdown = rtw_dev_shutdown,
  92. .rtw_pci_drv.id_table = rtw_pci_id_tbl,
  93. #ifdef CONFIG_PM
  94. .rtw_pci_drv.suspend = rtw_pci_suspend,
  95. .rtw_pci_drv.resume = rtw_pci_resume,
  96. #endif
  97. };
  98. MODULE_DEVICE_TABLE(pci, rtw_pci_id_tbl);
  99. static u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = {
  100. INTEL_VENDOR_ID,
  101. ATI_VENDOR_ID,
  102. AMD_VENDOR_ID,
  103. SIS_VENDOR_ID
  104. };
  105. #define PCI_PM_CAP_ID 0x01 /* The Capability ID for PME function */
  106. void PlatformClearPciPMEStatus(PADAPTER Adapter)
  107. {
  108. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(Adapter);
  109. struct pci_dev *pdev = pdvobjpriv->ppcidev;
  110. BOOLEAN PCIClkReq = _FALSE;
  111. u8 CapId = 0xff;
  112. u8 CapPointer = 0;
  113. /* u16 CapHdr; */
  114. RT_PCI_CAPABILITIES_HEADER CapHdr;
  115. u8 PMCSReg;
  116. int result;
  117. /* Get the Capability pointer first, */
  118. /* the Capability Pointer is located at offset 0x34 from the Function Header */
  119. result = pci_read_config_byte(pdev, 0x34, &CapPointer);
  120. if (result != 0)
  121. RTW_INFO("%s() pci_read_config_byte 0x34 Failed!\n", __func__);
  122. else {
  123. RTW_INFO("PlatformClearPciPMEStatus(): PCI configration 0x34 = 0x%2x\n", CapPointer);
  124. do {
  125. /* end of pci capability */
  126. if (CapPointer == 0x00) {
  127. CapId = 0xff;
  128. break;
  129. }
  130. /* result = pci_read_config_word(pdev, CapPointer, &CapHdr); */
  131. result = pci_read_config_byte(pdev, CapPointer, &CapHdr.CapabilityID);
  132. if (result != 0) {
  133. RTW_INFO("%s() pci_read_config_byte %x Failed!\n", __func__, CapPointer);
  134. CapId = 0xff;
  135. break;
  136. }
  137. result = pci_read_config_byte(pdev, CapPointer + 1, &CapHdr.Next);
  138. if (result != 0) {
  139. RTW_INFO("%s() pci_read_config_byte %x Failed!\n", __func__, CapPointer);
  140. CapId = 0xff;
  141. break;
  142. }
  143. /* CapId = CapHdr & 0xFF; */
  144. CapId = CapHdr.CapabilityID;
  145. RTW_INFO("PlatformClearPciPMEStatus(): in pci configration1, CapPointer%x = %x\n", CapPointer, CapId);
  146. if (CapId == PCI_PM_CAP_ID)
  147. break;
  148. else {
  149. /* point to next Capability */
  150. /* CapPointer = (CapHdr >> 8) & 0xFF; */
  151. CapPointer = CapHdr.Next;
  152. }
  153. } while (_TRUE);
  154. if (CapId == PCI_PM_CAP_ID) {
  155. /* Get the PM CSR (Control/Status Register), */
  156. /* The PME_Status is located at PM Capatibility offset 5, bit 7 */
  157. result = pci_read_config_byte(pdev, CapPointer + 5, &PMCSReg);
  158. if (PMCSReg & BIT7) {
  159. /* PME event occured, clear the PM_Status by write 1 */
  160. PMCSReg = PMCSReg | BIT7;
  161. pci_write_config_byte(pdev, CapPointer + 5, PMCSReg);
  162. PCIClkReq = _TRUE;
  163. /* Read it back to check */
  164. pci_read_config_byte(pdev, CapPointer + 5, &PMCSReg);
  165. RTW_INFO("PlatformClearPciPMEStatus(): Clear PME status 0x%2x to 0x%2x\n", CapPointer + 5, PMCSReg);
  166. } else
  167. RTW_INFO("PlatformClearPciPMEStatus(): PME status(0x%2x) = 0x%2x\n", CapPointer + 5, PMCSReg);
  168. } else
  169. RTW_INFO("PlatformClearPciPMEStatus(): Cannot find PME Capability\n");
  170. }
  171. RTW_INFO("PME, value_offset = %x, PME EN = %x\n", CapPointer + 5, PCIClkReq);
  172. }
  173. void rtw_pci_aspm_config_clkreql0sl1(_adapter *padapter)
  174. {
  175. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  176. u8 tmp8 = 0;
  177. u16 tmp16 = 0;
  178. /* 0x70f Bit7 for L0s */
  179. tmp8 = rtw_hal_pci_dbi_read(padapter, 0x70f);
  180. if (pHalData->pci_backdoor_ctrl & PCI_BC_ASPM_L0s)
  181. tmp8 |= BIT7;
  182. else
  183. tmp8 &= (~BIT7);
  184. /* Default set L1 entrance latency to 16us */
  185. /* L0s: b[0-2], L1: b[3-5]*/
  186. if (pHalData->pci_backdoor_ctrl & PCI_BC_ASPM_L1) {
  187. tmp8 &= (~0x38);
  188. tmp8 |= 0x20;
  189. #ifdef CONFIG_PCI_DYNAMIC_ASPM
  190. pHalData->bAspmL1LastIdle = 1;
  191. #endif
  192. }
  193. rtw_hal_pci_dbi_write(padapter, 0x70f, tmp8);
  194. /* 0x719 Bit 3 for L1 , Bit4 for clock req */
  195. tmp8 = rtw_hal_pci_dbi_read(padapter, 0x719);
  196. if (pHalData->pci_backdoor_ctrl & PCI_BC_ASPM_L1)
  197. tmp8 |= BIT3;
  198. else
  199. tmp8 &= (~BIT3);
  200. if (pHalData->pci_backdoor_ctrl & PCI_BC_CLK_REQ)
  201. tmp8 |= BIT4;
  202. else
  203. tmp8 &= (~BIT4);
  204. rtw_hal_pci_dbi_write(padapter, 0x719, tmp8);
  205. if (pHalData->pci_backdoor_ctrl & PCI_BC_CLK_REQ) {
  206. tmp16 = rtw_hal_pci_mdio_read(padapter, 0x10);
  207. rtw_hal_pci_mdio_write(padapter, 0x10, (tmp16 | BIT2));
  208. }
  209. }
  210. void rtw_pci_aspm_config_l1off(_adapter *padapter)
  211. {
  212. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  213. u8 enable_l1off = _FALSE;
  214. if (pHalData->pci_backdoor_ctrl & PCI_BC_ASPM_L1Off)
  215. enable_l1off = rtw_hal_pci_l1off_nic_support(padapter);
  216. padapter->hal_func.hal_set_l1ssbackdoor_handler(padapter, enable_l1off);
  217. }
  218. void rtw_pci_aspm_config_l1off_general(_adapter *padapter, u8 enablel1off)
  219. {
  220. u8 tmp8;
  221. u16 tmp16;
  222. if (enablel1off) {
  223. /* 0x718 Bit5 for L1SS */
  224. tmp8 = rtw_hal_pci_dbi_read(padapter, 0x718);
  225. rtw_hal_pci_dbi_write(padapter, 0x718, (tmp8 | BIT5));
  226. tmp16 = rtw_hal_pci_mdio_read(padapter, 0x1b);
  227. rtw_hal_pci_mdio_write(padapter, 0x1b, (tmp16 | BIT4));
  228. } else {
  229. tmp8 = rtw_hal_pci_dbi_read(padapter, 0x718);
  230. rtw_hal_pci_dbi_write(padapter, 0x718, (tmp8 & (~BIT5)));
  231. }
  232. }
  233. #ifdef CONFIG_PCI_DYNAMIC_ASPM
  234. void rtw_pci_aspm_config_dynamic_l1_ilde_time(_adapter *padapter)
  235. {
  236. BOOLEAN bCurrentIdle = 1; /* Default idle 4us (0x70F = 0x17)*/
  237. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  238. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  239. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  240. int current_tx_tp = pdvobjpriv->traffic_stat.cur_tx_tp;
  241. int current_rx_tp = pdvobjpriv->traffic_stat.cur_rx_tp;
  242. int current_tp = current_tx_tp + current_rx_tp;
  243. u8 tmp8 = 0;
  244. if (padapter->registrypriv.wifi_spec)
  245. return;
  246. if (!(pHalData->pci_backdoor_ctrl & PCI_BC_ASPM_L1))
  247. return;
  248. #if 0
  249. RTW_INFO("current_tx_tp = %d\n", current_tx_tp);
  250. RTW_INFO("current_rx_tp = %d\n", current_rx_tp);
  251. RTW_INFO("current_tp = %d\n", current_tp);
  252. #endif
  253. if ((rtw_linked_check(padapter) == _TRUE) &&
  254. ((current_tx_tp >= 50)||
  255. (current_rx_tp >= 50)))
  256. /*(current_rx_tp >= 10))*/
  257. /*(current_tp >= 10))*/
  258. {
  259. bCurrentIdle = 0;
  260. }
  261. else
  262. {
  263. bCurrentIdle = 1;
  264. }
  265. if(bCurrentIdle != pHalData->bAspmL1LastIdle)
  266. {
  267. pHalData->bAspmL1LastIdle = bCurrentIdle;
  268. tmp8 = rtw_hal_pci_dbi_read(padapter, 0x70F);
  269. tmp8 &= (~0x38);
  270. if(bCurrentIdle) {
  271. /*tmp8 |= 0x10; *//*L1 entrance latency: 4us*/
  272. /*tmp8 |= 0x18; *//*L1 entrance latency: 8us*/
  273. tmp8 |= 0x20; /*L1 entrance latency: 16us*/
  274. rtw_hal_pci_dbi_write(padapter, 0x70F, tmp8 );
  275. }
  276. else {
  277. tmp8 |= 0x28; /*L1 entrance latency: 32us*/
  278. rtw_hal_pci_dbi_write(padapter, 0x70F, tmp8 );
  279. }
  280. }
  281. }
  282. #endif
  283. void rtw_pci_dump_aspm_info(_adapter *padapter)
  284. {
  285. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  286. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  287. struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv);
  288. u8 tmp8 = 0;
  289. u16 tmp16 = 0;
  290. u32 tmp32 = 0;
  291. u8 l1_idle = 0;
  292. RTW_INFO("***** ASPM Capability *****\n");
  293. pci_read_config_dword(pdvobjpriv->ppcidev, pcipriv->pciehdr_offset + PCI_EXP_LNKCAP, &tmp32);
  294. RTW_INFO("CLK REQ: %s\n", (tmp32&PCI_EXP_LNKCAP_CLKPM) ? "Enable" : "Disable");
  295. RTW_INFO("ASPM L0s: %s\n", (tmp32&BIT10) ? "Enable" : "Disable");
  296. RTW_INFO("ASPM L1: %s\n", (tmp32&BIT11) ? "Enable" : "Disable");
  297. tmp8 = rtw_hal_pci_l1off_capability(padapter);
  298. RTW_INFO("ASPM L1OFF:%s\n", tmp8 ? "Enable" : "Disable");
  299. RTW_INFO("***** ASPM CTRL Reg *****\n");
  300. pci_read_config_word(pdvobjpriv->ppcidev, pcipriv->pciehdr_offset + PCI_EXP_LNKCTL, &tmp16);
  301. RTW_INFO("CLK REQ: %s\n", (tmp16&PCI_EXP_LNKCTL_CLKREQ_EN) ? "Enable" : "Disable");
  302. RTW_INFO("ASPM L0s: %s\n", (tmp16&BIT0) ? "Enable" : "Disable");
  303. RTW_INFO("ASPM L1: %s\n", (tmp16&BIT1) ? "Enable" : "Disable");
  304. tmp8 = rtw_hal_pci_l1off_nic_support(padapter);
  305. RTW_INFO("ASPM L1OFF:%s\n", tmp8 ? "Enable" : "Disable");
  306. RTW_INFO("***** ASPM Backdoor *****\n");
  307. tmp8 = rtw_hal_pci_dbi_read(padapter, 0x719);
  308. RTW_INFO("CLK REQ: %s\n", (tmp8 & BIT4) ? "Enable" : "Disable");
  309. tmp8 = rtw_hal_pci_dbi_read(padapter, 0x70f);
  310. l1_idle = tmp8 & 0x38;
  311. RTW_INFO("ASPM L0s: %s\n", (tmp8&BIT7) ? "Enable" : "Disable");
  312. tmp8 = rtw_hal_pci_dbi_read(padapter, 0x719);
  313. RTW_INFO("ASPM L1: %s\n", (tmp8 & BIT3) ? "Enable" : "Disable");
  314. tmp8 = rtw_hal_pci_dbi_read(padapter, 0x718);
  315. RTW_INFO("ASPM L1OFF:%s\n", (tmp8 & BIT5) ? "Enable" : "Disable");
  316. RTW_INFO("********* MISC **********\n");
  317. RTW_INFO("ASPM L1 Idel Time: 0x%x\n", l1_idle>>3);
  318. RTW_INFO("*************************\n");
  319. }
  320. void rtw_pci_aspm_config(_adapter *padapter)
  321. {
  322. rtw_pci_aspm_config_clkreql0sl1(padapter);
  323. rtw_pci_aspm_config_l1off(padapter);
  324. rtw_pci_dump_aspm_info(padapter);
  325. }
  326. static u8 rtw_pci_platform_switch_device_pci_aspm(_adapter *padapter, u8 value)
  327. {
  328. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  329. struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv);
  330. BOOLEAN bResult = _FALSE;
  331. int Result = 0;
  332. int error;
  333. Result = pci_write_config_byte(pdvobjpriv->ppcidev, pcipriv->pciehdr_offset + 0x10, value); /* enable I/O space */
  334. RTW_INFO("PlatformSwitchDevicePciASPM(0x%x) = 0x%x\n", pcipriv->pciehdr_offset + 0x10, value);
  335. if (Result != 0) {
  336. RTW_INFO("PlatformSwitchDevicePciASPM() Failed!\n");
  337. bResult = _FALSE;
  338. } else
  339. bResult = _TRUE;
  340. return bResult;
  341. }
  342. /*
  343. * When we set 0x01 to enable clk request. Set 0x0 to disable clk req.
  344. */
  345. static u8 rtw_pci_switch_clk_req(_adapter *padapter, u8 value)
  346. {
  347. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  348. u8 buffer, bResult = _FALSE;
  349. int error;
  350. buffer = value;
  351. if (!rtw_is_hw_init_completed(padapter))
  352. return bResult;
  353. /* the clock request is located at offset 0x81, suppose the PCIE Capability register is located at offset 0x70 */
  354. /* the correct code should be: search the PCIE capability register first and then the clock request is located offset 0x11 */
  355. error = pci_write_config_byte(pdvobjpriv->ppcidev, 0x81, buffer);
  356. if (error != 0)
  357. RTW_INFO("rtw_pci_switch_clk_req error (%d)\n", error);
  358. else
  359. bResult = _TRUE;
  360. return bResult;
  361. }
  362. /*Disable RTL8192SE ASPM & Disable Pci Bridge ASPM*/
  363. void rtw_pci_disable_aspm(_adapter *padapter)
  364. {
  365. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  366. struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(pdvobjpriv);
  367. struct pci_dev *pdev = pdvobjpriv->ppcidev;
  368. struct pci_dev *bridge_pdev = pdev->bus->self;
  369. struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv);
  370. u8 linkctrl_reg;
  371. u8 pcibridge_linkctrlreg, aspmlevel = 0;
  372. /* We shall check RF Off Level for ASPM function instead of registry settings, revised by Roger, 2013.03.29. */
  373. if (!(pwrpriv->reg_rfps_level & (RT_RF_LPS_LEVEL_ASPM | RT_RF_PS_LEVEL_ALWAYS_ASPM)))
  374. return;
  375. if (!rtw_is_hw_init_completed(padapter))
  376. return;
  377. if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN)
  378. return;
  379. linkctrl_reg = pcipriv->linkctrl_reg;
  380. pcibridge_linkctrlreg = pcipriv->pcibridge_linkctrlreg;
  381. /* Set corresponding value. */
  382. aspmlevel |= BIT(0) | BIT(1);
  383. linkctrl_reg &= ~aspmlevel;
  384. pcibridge_linkctrlreg &= ~aspmlevel;
  385. /* */
  386. /* 09/08/21 MH From Sd1 suggestion. we need to adjust ASPM enable sequence */
  387. /* CLK_REQ ==> delay 50us ==> Device ==> Host ==> delay 50us */
  388. /* */
  389. if (pwrpriv->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) {
  390. RT_CLEAR_PS_LEVEL(pwrpriv, RT_RF_OFF_LEVL_CLK_REQ);
  391. rtw_pci_switch_clk_req(padapter, 0x0);
  392. }
  393. {
  394. /*for promising device will in L0 state after an I/O.*/
  395. u8 tmp_u1b;
  396. pci_read_config_byte(pdev, (pcipriv->pciehdr_offset + 0x10), &tmp_u1b);
  397. }
  398. rtw_pci_platform_switch_device_pci_aspm(padapter, linkctrl_reg);
  399. rtw_udelay_os(50);
  400. /* When there exists anyone's BusNum, DevNum, and FuncNum that are set to 0xff, */
  401. /* we do not execute any action and return. Added by tynli. */
  402. if ((pcipriv->busnumber == 0xff && pcipriv->devnumber == 0xff && pcipriv->funcnumber == 0xff) ||
  403. (pcipriv->pcibridge_busnum == 0xff && pcipriv->pcibridge_devnum == 0xff && pcipriv->pcibridge_funcnum == 0xff)) {
  404. /* Do Nothing!! */
  405. } else {
  406. /* 4 */ /* Disable Pci Bridge ASPM */
  407. pci_write_config_byte(bridge_pdev, (pcipriv->pcibridge_pciehdr_offset + 0x10), pcibridge_linkctrlreg);
  408. RTW_INFO("PlatformDisableASPM():PciBridge Write reg[%x] = %x\n",
  409. (pcipriv->pcibridge_pciehdr_offset + 0x10), pcibridge_linkctrlreg);
  410. rtw_udelay_os(50);
  411. }
  412. }
  413. /*Enable RTL8192SE ASPM & Enable Pci Bridge ASPM for
  414. * power saving We should follow the sequence to enable
  415. * RTL8192SE first then enable Pci Bridge ASPM
  416. * or the system will show bluescreen.
  417. */
  418. void rtw_pci_enable_aspm(_adapter *padapter)
  419. {
  420. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  421. struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(pdvobjpriv);
  422. struct pci_dev *pdev = pdvobjpriv->ppcidev;
  423. struct pci_dev *bridge_pdev = pdev->bus->self;
  424. struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv);
  425. u16 aspmlevel = 0;
  426. u8 u_pcibridge_aspmsetting = 0;
  427. u8 u_device_aspmsetting = 0;
  428. u32 u_device_aspmsupportsetting = 0;
  429. /* We shall check RF Off Level for ASPM function instead of registry settings, revised by Roger, 2013.03.29. */
  430. if (!(pwrpriv->reg_rfps_level & (RT_RF_LPS_LEVEL_ASPM | RT_RF_PS_LEVEL_ALWAYS_ASPM)))
  431. return;
  432. /* When there exists anyone's BusNum, DevNum, and FuncNum that are set to 0xff, */
  433. /* we do not execute any action and return. Added by tynli. */
  434. if ((pcipriv->busnumber == 0xff && pcipriv->devnumber == 0xff && pcipriv->funcnumber == 0xff) ||
  435. (pcipriv->pcibridge_busnum == 0xff && pcipriv->pcibridge_devnum == 0xff && pcipriv->pcibridge_funcnum == 0xff)) {
  436. RTW_INFO("rtw_pci_enable_aspm(): Fail to enable ASPM. Cannot find the Bus of PCI(Bridge).\n");
  437. return;
  438. }
  439. /* Get Bridge ASPM Support
  440. * not to enable bridge aspm if bridge does not support
  441. * Added by sherry 20100803
  442. */
  443. {
  444. /* Get the Link Capability, it ls located at offset 0x0c from the PCIE Capability */
  445. pci_read_config_dword(bridge_pdev, (pcipriv->pcibridge_pciehdr_offset + 0x0C), &u_device_aspmsupportsetting);
  446. RTW_INFO("rtw_pci_enable_aspm(): Bridge ASPM support %x\n", u_device_aspmsupportsetting);
  447. if (((u_device_aspmsupportsetting & BIT(11)) != BIT(11)) || ((u_device_aspmsupportsetting & BIT(10)) != BIT(10))) {
  448. if (pdvobjpriv->const_devicepci_aspm_setting == 3) {
  449. RTW_INFO("rtw_pci_enable_aspm(): Bridge not support L0S or L1\n");
  450. return;
  451. } else if (pdvobjpriv->const_devicepci_aspm_setting == 2) {
  452. if ((u_device_aspmsupportsetting & BIT(11)) != BIT(11)) {
  453. RTW_INFO("rtw_pci_enable_aspm(): Bridge not support L1\n");
  454. return;
  455. }
  456. } else if (pdvobjpriv->const_devicepci_aspm_setting == 1) {
  457. if ((u_device_aspmsupportsetting & BIT(10)) != BIT(10)) {
  458. RTW_INFO("rtw_pci_enable_aspm(): Bridge not support L0s\n");
  459. return;
  460. }
  461. }
  462. } else
  463. RTW_INFO("rtw_pci_enable_aspm(): Bridge support L0s and L1\n");
  464. }
  465. /*
  466. * Skip following settings if ASPM has already enabled, added by Roger, 2013.03.15.
  467. */
  468. if ((pcipriv->pcibridge_linkctrlreg & (BIT0 | BIT1)) &&
  469. (pcipriv->linkctrl_reg & (BIT0 | BIT1))) {
  470. /* BIT0: L0S, BIT1:L1 */
  471. RTW_INFO("PlatformEnableASPM(): ASPM is already enabled, skip incoming settings!!\n");
  472. return;
  473. }
  474. /* 4 Enable Pci Bridge ASPM */
  475. /* Write PCI bridge PCIE-capability Link Control Register */
  476. /* Justin: Can we change the ASPM Control register ? */
  477. /* The system BIOS should set this register with a correct value */
  478. /* If we change the force enable the ASPM L1/L0s, this may cause the system hang */
  479. u_pcibridge_aspmsetting = pcipriv->pcibridge_linkctrlreg;
  480. u_pcibridge_aspmsetting |= pdvobjpriv->const_hostpci_aspm_setting;
  481. if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL ||
  482. pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_SIS)
  483. u_pcibridge_aspmsetting &= ~BIT(0); /* for intel host 42 device 43 */
  484. pci_write_config_byte(bridge_pdev, (pcipriv->pcibridge_pciehdr_offset + 0x10), u_pcibridge_aspmsetting);
  485. RTW_INFO("PlatformEnableASPM():PciBridge Write reg[%x] = %x\n",
  486. (pcipriv->pcibridge_pciehdr_offset + 0x10),
  487. u_pcibridge_aspmsetting);
  488. rtw_udelay_os(50);
  489. /*Get ASPM level (with/without Clock Req)*/
  490. aspmlevel |= pdvobjpriv->const_devicepci_aspm_setting;
  491. u_device_aspmsetting = pcipriv->linkctrl_reg;
  492. u_device_aspmsetting |= aspmlevel; /* device 43 */
  493. rtw_pci_platform_switch_device_pci_aspm(padapter, u_device_aspmsetting);
  494. if (pwrpriv->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) {
  495. rtw_pci_switch_clk_req(padapter, (pwrpriv->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) ? 1 : 0);
  496. RT_SET_PS_LEVEL(pwrpriv, RT_RF_OFF_LEVL_CLK_REQ);
  497. }
  498. rtw_udelay_os(50);
  499. }
  500. static u8 rtw_pci_get_amd_l1_patch(struct dvobj_priv *pdvobjpriv, struct pci_dev *pdev)
  501. {
  502. u8 status = _FALSE;
  503. u8 offset_e0;
  504. u32 offset_e4;
  505. pci_write_config_byte(pdev, 0xE0, 0xA0);
  506. pci_read_config_byte(pdev, 0xE0, &offset_e0);
  507. if (offset_e0 == 0xA0) {
  508. pci_read_config_dword(pdev, 0xE4, &offset_e4);
  509. if (offset_e4 & BIT(23))
  510. status = _TRUE;
  511. }
  512. return status;
  513. }
  514. static s32 rtw_pci_get_linkcontrol_reg(struct pci_dev *pdev, u8 *LinkCtrlReg, u8 *HdrOffset)
  515. {
  516. u8 CapabilityPointer;
  517. RT_PCI_CAPABILITIES_HEADER CapabilityHdr;
  518. s32 status = _FAIL;
  519. /* get CapabilityOffset */
  520. pci_read_config_byte(pdev, 0x34, &CapabilityPointer); /* the capability pointer is located offset 0x34 */
  521. /* Loop through the capabilities in search of the power management capability. */
  522. /* The list is NULL-terminated, so the last offset will always be zero. */
  523. while (CapabilityPointer != 0) {
  524. /* Read the header of the capability at this offset. If the retrieved capability is not */
  525. /* the power management capability that we are looking for, follow the link to the */
  526. /* next capability and continue looping. */
  527. /* 4 get CapabilityHdr */
  528. /* pci_read_config_word(pdev, CapabilityPointer, (u16 *)&CapabilityHdr); */
  529. pci_read_config_byte(pdev, CapabilityPointer, (u8 *)&CapabilityHdr.CapabilityID);
  530. pci_read_config_byte(pdev, CapabilityPointer + 1, (u8 *)&CapabilityHdr.Next);
  531. /* Found the PCI express capability */
  532. if (CapabilityHdr.CapabilityID == PCI_CAPABILITY_ID_PCI_EXPRESS)
  533. break;
  534. else {
  535. /* This is some other capability. Keep looking for the PCI express capability. */
  536. CapabilityPointer = CapabilityHdr.Next;
  537. }
  538. }
  539. /* Get the Link Control Register, it located at offset 0x10 from the Capability Header */
  540. if (CapabilityHdr.CapabilityID == PCI_CAPABILITY_ID_PCI_EXPRESS) {
  541. *HdrOffset = CapabilityPointer;
  542. pci_read_config_byte(pdev, CapabilityPointer + 0x10, LinkCtrlReg);
  543. status = _SUCCESS;
  544. } else {
  545. /* We didn't find a PCIe capability. */
  546. RTW_INFO("GetPciLinkCtrlReg(): Cannot Find PCIe Capability\n");
  547. }
  548. return status;
  549. }
  550. static s32 rtw_set_pci_cache_line_size(struct pci_dev *pdev, u8 CacheLineSizeToSet)
  551. {
  552. u8 ucPciCacheLineSize;
  553. s32 Result;
  554. /* ucPciCacheLineSize = pPciConfig->CacheLineSize; */
  555. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &ucPciCacheLineSize);
  556. if (ucPciCacheLineSize < 8 || ucPciCacheLineSize > 16) {
  557. RTW_INFO("Driver Sets default Cache Line Size...\n");
  558. ucPciCacheLineSize = CacheLineSizeToSet;
  559. Result = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, ucPciCacheLineSize);
  560. if (Result != 0) {
  561. RTW_INFO("pci_write_config_byte (CacheLineSize) Result=%d\n", Result);
  562. goto _SET_CACHELINE_SIZE_FAIL;
  563. }
  564. Result = pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &ucPciCacheLineSize);
  565. if (Result != 0) {
  566. RTW_INFO("pci_read_config_byte (PciCacheLineSize) Result=%d\n", Result);
  567. goto _SET_CACHELINE_SIZE_FAIL;
  568. }
  569. if (ucPciCacheLineSize != CacheLineSizeToSet) {
  570. RTW_INFO("Failed to set Cache Line Size to 0x%x! ucPciCacheLineSize=%x\n", CacheLineSizeToSet, ucPciCacheLineSize);
  571. goto _SET_CACHELINE_SIZE_FAIL;
  572. }
  573. }
  574. return _SUCCESS;
  575. _SET_CACHELINE_SIZE_FAIL:
  576. return _FAIL;
  577. }
  578. #define PCI_CMD_ENABLE_BUS_MASTER BIT(2)
  579. #define PCI_CMD_DISABLE_INTERRUPT BIT(10)
  580. #define CMD_BUS_MASTER BIT(2)
  581. static s32 rtw_pci_parse_configuration(struct pci_dev *pdev, struct dvobj_priv *pdvobjpriv)
  582. {
  583. struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv);
  584. /* PPCI_COMMON_CONFIG pPciConfig = (PPCI_COMMON_CONFIG) pucBuffer; */
  585. /* u16 usPciCommand = pPciConfig->Command; */
  586. u16 usPciCommand = 0;
  587. int Result, ret = _FAIL;
  588. u8 CapabilityOffset;
  589. RT_PCI_CAPABILITIES_HEADER CapabilityHdr;
  590. u8 PCIeCap;
  591. u8 LinkCtrlReg;
  592. u8 ClkReqReg;
  593. /* RTW_INFO("%s==>\n", __func__); */
  594. pci_read_config_word(pdev, PCI_COMMAND, &usPciCommand);
  595. do {
  596. /* 3 Enable bus matering if it isn't enabled by the BIOS */
  597. if (!(usPciCommand & PCI_CMD_ENABLE_BUS_MASTER)) {
  598. RTW_INFO("Bus master is not enabled by BIOS! usPciCommand=%x\n", usPciCommand);
  599. usPciCommand |= CMD_BUS_MASTER;
  600. Result = pci_write_config_word(pdev, PCI_COMMAND, usPciCommand);
  601. if (Result != 0) {
  602. RTW_INFO("pci_write_config_word (Command) Result=%d\n", Result);
  603. ret = _FAIL;
  604. break;
  605. }
  606. Result = pci_read_config_word(pdev, PCI_COMMAND, &usPciCommand);
  607. if (Result != 0) {
  608. RTW_INFO("pci_read_config_word (Command) Result=%d\n", Result);
  609. ret = _FAIL;
  610. break;
  611. }
  612. if (!(usPciCommand & PCI_CMD_ENABLE_BUS_MASTER)) {
  613. RTW_INFO("Failed to enable bus master! usPciCommand=%x\n", usPciCommand);
  614. ret = _FAIL;
  615. break;
  616. }
  617. }
  618. RTW_INFO("Bus master is enabled. usPciCommand=%x\n", usPciCommand);
  619. /* 3 Enable interrupt */
  620. if ((usPciCommand & PCI_CMD_DISABLE_INTERRUPT)) {
  621. RTW_INFO("INTDIS==1 usPciCommand=%x\n", usPciCommand);
  622. usPciCommand &= (~PCI_CMD_DISABLE_INTERRUPT);
  623. Result = pci_write_config_word(pdev, PCI_COMMAND, usPciCommand);
  624. if (Result != 0) {
  625. RTW_INFO("pci_write_config_word (Command) Result=%d\n", Result);
  626. ret = _FAIL;
  627. break;
  628. }
  629. Result = pci_read_config_word(pdev, PCI_COMMAND, &usPciCommand);
  630. if (Result != 0) {
  631. RTW_INFO("pci_read_config_word (Command) Result=%d\n", Result);
  632. ret = _FAIL;
  633. break;
  634. }
  635. if ((usPciCommand & PCI_CMD_DISABLE_INTERRUPT)) {
  636. RTW_INFO("Failed to set INTDIS to 0! usPciCommand=%x\n", usPciCommand);
  637. ret = _FAIL;
  638. break;
  639. }
  640. }
  641. /* */
  642. /* Description: Find PCI express capability offset. Porting from 818xB by tynli 2008.12.19 */
  643. /* */
  644. /* ------------------------------------------------------------- */
  645. /* 3 PCIeCap */
  646. /* The device supports capability lists. Find the capabilities. */
  647. /* CapabilityOffset = pPciConfig->u.type0.CapabilitiesPtr; */
  648. pci_read_config_byte(pdev, PCI_CAPABILITY_LIST, &CapabilityOffset);
  649. /* Loop through the capabilities in search of the power management capability. */
  650. /* The list is NULL-terminated, so the last offset will always be zero. */
  651. while (CapabilityOffset != 0) {
  652. /* Read the header of the capability at this offset. If the retrieved capability is not */
  653. /* the power management capability that we are looking for, follow the link to the */
  654. /* next capability and continue looping. */
  655. /* Result = pci_read_config_word(pdev, CapabilityOffset, (u16 *)&CapabilityHdr); */
  656. Result = pci_read_config_byte(pdev, CapabilityOffset, (u8 *)&CapabilityHdr.CapabilityID);
  657. if (Result != 0)
  658. break;
  659. Result = pci_read_config_byte(pdev, CapabilityOffset + 1, (u8 *)&CapabilityHdr.Next);
  660. if (Result != 0)
  661. break;
  662. /* Found the PCI express capability */
  663. if (CapabilityHdr.CapabilityID == PCI_CAPABILITY_ID_PCI_EXPRESS)
  664. break;
  665. else {
  666. /* This is some other capability. Keep looking for the PCI express capability. */
  667. CapabilityOffset = CapabilityHdr.Next;
  668. }
  669. }
  670. if (Result != 0) {
  671. RTW_INFO("pci_read_config_word (RT_PCI_CAPABILITIES_HEADER) Result=%d\n", Result);
  672. break;
  673. }
  674. if (CapabilityHdr.CapabilityID == PCI_CAPABILITY_ID_PCI_EXPRESS) {
  675. pcipriv->pciehdr_offset = CapabilityOffset;
  676. RTW_INFO("PCIe Header Offset =%x\n", CapabilityOffset);
  677. /* Skip past the capabilities header and read the PCI express capability */
  678. /* Justin: The PCI-e capability size should be 2 bytes, why we just get 1 byte */
  679. /* Beside, this PCIeCap seems no one reference it in the driver code */
  680. Result = pci_read_config_byte(pdev, CapabilityOffset + 2, &PCIeCap);
  681. if (Result != 0) {
  682. RTW_INFO("pci_read_config_byte (PCIE Capability) Result=%d\n", Result);
  683. break;
  684. }
  685. pcipriv->pcie_cap = PCIeCap;
  686. RTW_INFO("PCIe Capability =%x\n", PCIeCap);
  687. /* 3 Link Control Register */
  688. /* Read "Link Control Register" Field (80h ~81h) */
  689. Result = pci_read_config_byte(pdev, CapabilityOffset + 0x10, &LinkCtrlReg);
  690. if (Result != 0) {
  691. RTW_INFO("pci_read_config_byte (Link Control Register) Result=%d\n", Result);
  692. break;
  693. }
  694. pcipriv->linkctrl_reg = LinkCtrlReg;
  695. RTW_INFO("Link Control Register =%x\n", LinkCtrlReg);
  696. /* 3 Get Capability of PCI Clock Request */
  697. /* The clock request setting is located at 0x81[0] */
  698. Result = pci_read_config_byte(pdev, CapabilityOffset + 0x11, &ClkReqReg);
  699. if (Result != 0) {
  700. pcipriv->pci_clk_req = _FALSE;
  701. RTW_INFO("pci_read_config_byte (Clock Request Register) Result=%d\n", Result);
  702. break;
  703. }
  704. if (ClkReqReg & BIT(0))
  705. pcipriv->pci_clk_req = _TRUE;
  706. else
  707. pcipriv->pci_clk_req = _FALSE;
  708. RTW_INFO("Clock Request =%x\n", pcipriv->pci_clk_req);
  709. } else {
  710. /* We didn't find a PCIe capability. */
  711. RTW_INFO("Didn't Find PCIe Capability\n");
  712. break;
  713. }
  714. /* 3 Fill Cacheline */
  715. ret = rtw_set_pci_cache_line_size(pdev, 8);
  716. if (ret != _SUCCESS) {
  717. RTW_INFO("rtw_set_pci_cache_line_size fail\n");
  718. break;
  719. }
  720. /* Include 92C suggested by SD1. Added by tynli. 2009.11.25.
  721. * Enable the Backdoor
  722. */
  723. {
  724. u8 tmp;
  725. Result = pci_read_config_byte(pdev, 0x98, &tmp);
  726. tmp |= BIT4;
  727. Result = pci_write_config_byte(pdev, 0x98, tmp);
  728. }
  729. ret = _SUCCESS;
  730. } while (_FALSE);
  731. return ret;
  732. }
  733. /*
  734. * Update PCI dependent default settings.
  735. *
  736. */
  737. static void rtw_pci_update_default_setting(_adapter *padapter)
  738. {
  739. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  740. struct pci_priv *pcipriv = &(pdvobjpriv->pcipriv);
  741. struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(pdvobjpriv);
  742. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  743. /* reset pPSC->reg_rfps_level & priv->b_support_aspm */
  744. pwrpriv->reg_rfps_level = 0;
  745. /* Update PCI ASPM setting */
  746. /* pwrpriv->const_amdpci_aspm = pdvobjpriv->const_amdpci_aspm; */
  747. switch (pdvobjpriv->const_pci_aspm) {
  748. case 0: /* No ASPM */
  749. break;
  750. case 1: /* ASPM dynamically enabled/disable. */
  751. pwrpriv->reg_rfps_level |= RT_RF_LPS_LEVEL_ASPM;
  752. break;
  753. case 2: /* ASPM with Clock Req dynamically enabled/disable. */
  754. pwrpriv->reg_rfps_level |= (RT_RF_LPS_LEVEL_ASPM | RT_RF_OFF_LEVL_CLK_REQ);
  755. break;
  756. case 3: /* Always enable ASPM and Clock Req from initialization to halt. */
  757. pwrpriv->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM);
  758. pwrpriv->reg_rfps_level |= (RT_RF_PS_LEVEL_ALWAYS_ASPM | RT_RF_OFF_LEVL_CLK_REQ);
  759. break;
  760. case 4: /* Always enable ASPM without Clock Req from initialization to halt. */
  761. pwrpriv->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM | RT_RF_OFF_LEVL_CLK_REQ);
  762. pwrpriv->reg_rfps_level |= RT_RF_PS_LEVEL_ALWAYS_ASPM;
  763. break;
  764. case 5: /* Linux do not support ASPM OSC, added by Roger, 2013.03.27. */
  765. break;
  766. }
  767. pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC;
  768. /* Update Radio OFF setting */
  769. switch (pdvobjpriv->const_hwsw_rfoff_d3) {
  770. case 1:
  771. if (pwrpriv->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM)
  772. pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM;
  773. break;
  774. case 2:
  775. if (pwrpriv->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM)
  776. pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM;
  777. pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC;
  778. break;
  779. case 3:
  780. pwrpriv->reg_rfps_level |= RT_RF_OFF_LEVL_PCI_D3;
  781. break;
  782. }
  783. /* Update Rx 2R setting */
  784. /* pPSC->reg_rfps_level |= ((pDevice->RegLPS2RDisable) ? RT_RF_LPS_DISALBE_2R : 0); */
  785. /* */
  786. /* Set HW definition to determine if it supports ASPM. */
  787. /* */
  788. switch (pdvobjpriv->const_support_pciaspm) {
  789. case 1: { /* Support ASPM. */
  790. u8 b_support_backdoor = _TRUE;
  791. u8 b_support_l1_on_amd = _FALSE;
  792. rtw_hal_get_def_var(padapter, HAL_DEF_PCI_AMD_L1_SUPPORT, &b_support_l1_on_amd);
  793. if (pHalData->CustomerID == RT_CID_TOSHIBA &&
  794. pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_AMD &&
  795. !pcipriv->amd_l1_patch && !b_support_l1_on_amd) {
  796. RTW_INFO("%s(): Disable L1 Backdoor!!\n", __func__);
  797. b_support_backdoor = _FALSE;
  798. }
  799. rtw_hal_set_def_var(padapter, HAL_DEF_PCI_SUUPORT_L1_BACKDOOR, &b_support_backdoor);
  800. }
  801. break;
  802. default:
  803. /* Do nothing. Set when finding the chipset. */
  804. break;
  805. }
  806. }
  807. static void rtw_pci_initialize_adapter_common(_adapter *padapter)
  808. {
  809. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  810. rtw_pci_update_default_setting(padapter);
  811. if (pwrpriv->reg_rfps_level & RT_RF_PS_LEVEL_ALWAYS_ASPM) {
  812. /* Always enable ASPM & Clock Req. */
  813. rtw_pci_enable_aspm(padapter);
  814. RT_SET_PS_LEVEL(pwrpriv, RT_RF_PS_LEVEL_ALWAYS_ASPM);
  815. }
  816. }
  817. /*
  818. * 2009/10/28 MH Enable rtl8192ce DMA64 function. We need to enable 0x719 BIT5
  819. * */
  820. #ifdef CONFIG_64BIT_DMA
  821. u8 PlatformEnableDMA64(PADAPTER Adapter)
  822. {
  823. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(Adapter);
  824. struct pci_dev *pdev = pdvobjpriv->ppcidev;
  825. u8 bResult = _TRUE;
  826. u8 value;
  827. pci_read_config_byte(pdev, 0x719, &value);
  828. /* 0x719 Bit5 is DMA64 bit fetch. */
  829. value |= (BIT5);
  830. pci_write_config_byte(pdev, 0x719, value);
  831. return bResult;
  832. }
  833. #endif
  834. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)) || (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
  835. #define rtw_pci_interrupt(x, y, z) rtw_pci_interrupt(x, y)
  836. #endif
  837. static irqreturn_t rtw_pci_interrupt(int irq, void *priv, struct pt_regs *regs)
  838. {
  839. struct dvobj_priv *dvobj = (struct dvobj_priv *)priv;
  840. _adapter *adapter = dvobj_get_primary_adapter(dvobj);
  841. if (dvobj->irq_enabled == 0)
  842. return IRQ_HANDLED;
  843. if (rtw_hal_interrupt_handler(adapter) == _FAIL)
  844. return IRQ_HANDLED;
  845. /* return IRQ_NONE; */
  846. return IRQ_HANDLED;
  847. }
  848. #ifdef RTK_DMP_PLATFORM
  849. #define pci_iounmap(x, y) iounmap(y)
  850. #endif
  851. int pci_alloc_irq(struct dvobj_priv *dvobj)
  852. {
  853. int err;
  854. struct pci_dev *pdev = dvobj->ppcidev;
  855. int ret;
  856. ret = pci_enable_msi(pdev);
  857. RTW_INFO("pci_enable_msi ret=%d\n", ret);
  858. #if defined(IRQF_SHARED)
  859. err = request_irq(pdev->irq, &rtw_pci_interrupt, IRQF_SHARED, DRV_NAME, dvobj);
  860. #else
  861. err = request_irq(pdev->irq, &rtw_pci_interrupt, SA_SHIRQ, DRV_NAME, dvobj);
  862. #endif
  863. if (err)
  864. RTW_INFO("Error allocating IRQ %d", pdev->irq);
  865. else {
  866. dvobj->irq_alloc = 1;
  867. dvobj->irq = pdev->irq;
  868. RTW_INFO("Request_irq OK, IRQ %d\n", pdev->irq);
  869. }
  870. return err ? _FAIL : _SUCCESS;
  871. }
  872. static void rtw_decide_chip_type_by_pci_driver_data(struct dvobj_priv *pdvobj, const struct pci_device_id *pdid)
  873. {
  874. pdvobj->chip_type = pdid->driver_data;
  875. #ifdef CONFIG_RTL8188E
  876. if (pdvobj->chip_type == RTL8188E) {
  877. pdvobj->HardwareType = HARDWARE_TYPE_RTL8188EE;
  878. RTW_INFO("CHIP TYPE: RTL8188E\n");
  879. }
  880. #endif
  881. #ifdef CONFIG_RTL8812A
  882. if (pdvobj->chip_type == RTL8812) {
  883. pdvobj->HardwareType = HARDWARE_TYPE_RTL8812E;
  884. RTW_INFO("CHIP TYPE: RTL8812AE\n");
  885. }
  886. #endif
  887. #ifdef CONFIG_RTL8821A
  888. if (pdvobj->chip_type == RTL8821) {
  889. pdvobj->HardwareType = HARDWARE_TYPE_RTL8821E;
  890. RTW_INFO("CHIP TYPE: RTL8821AE\n");
  891. }
  892. #endif
  893. #ifdef CONFIG_RTL8723B
  894. if (pdvobj->chip_type == RTL8723B) {
  895. pdvobj->HardwareType = HARDWARE_TYPE_RTL8723BE;
  896. RTW_INFO("CHIP TYPE: RTL8723BE\n");
  897. }
  898. #endif
  899. #ifdef CONFIG_RTL8723D
  900. if (pdvobj->chip_type == RTL8723D) {
  901. pdvobj->HardwareType = HARDWARE_TYPE_RTL8723DE;
  902. RTW_INFO("CHIP TYPE: RTL8723DE\n");
  903. }
  904. #endif
  905. #ifdef CONFIG_RTL8192E
  906. if (pdvobj->chip_type == RTL8192E) {
  907. pdvobj->HardwareType = HARDWARE_TYPE_RTL8192EE;
  908. RTW_INFO("CHIP TYPE: RTL8192EE\n");
  909. }
  910. #endif
  911. #ifdef CONFIG_RTL8192F
  912. if (pdvobj->chip_type == RTL8192F) {
  913. pdvobj->HardwareType = HARDWARE_TYPE_RTL8192FE;
  914. RTW_INFO("CHIP TYPE: RTL8192FE\n");
  915. }
  916. #endif
  917. #ifdef CONFIG_RTL8814A
  918. if (pdvobj->chip_type == RTL8814A) {
  919. pdvobj->HardwareType = HARDWARE_TYPE_RTL8814AE;
  920. RTW_INFO("CHIP TYPE: RTL8814AE\n");
  921. }
  922. #endif
  923. #if defined(CONFIG_RTL8822B)
  924. if (pdvobj->chip_type == RTL8822B) {
  925. pdvobj->HardwareType = HARDWARE_TYPE_RTL8822BE;
  926. RTW_INFO("CHIP TYPE: RTL8822BE\n");
  927. }
  928. #endif
  929. #if defined(CONFIG_RTL8821C)
  930. if (pdvobj->chip_type == RTL8821C) {
  931. pdvobj->HardwareType = HARDWARE_TYPE_RTL8821CE;
  932. RTW_INFO("CHIP TYPE: RTL8821CE\n");
  933. }
  934. #endif
  935. }
  936. static struct dvobj_priv *pci_dvobj_init(struct pci_dev *pdev, const struct pci_device_id *pdid)
  937. {
  938. int err;
  939. u32 status = _FAIL;
  940. struct dvobj_priv *dvobj = NULL;
  941. struct pci_priv *pcipriv = NULL;
  942. struct pci_dev *bridge_pdev = pdev->bus->self;
  943. /* u32 pci_cfg_space[16]; */
  944. unsigned long pmem_start, pmem_len, pmem_flags;
  945. u8 tmp;
  946. u8 PciBgVIdIdx;
  947. int i;
  948. dvobj = devobj_init();
  949. if (dvobj == NULL)
  950. goto exit;
  951. dvobj->ppcidev = pdev;
  952. pcipriv = &(dvobj->pcipriv);
  953. pci_set_drvdata(pdev, dvobj);
  954. err = pci_enable_device(pdev);
  955. if (err != 0) {
  956. RTW_ERR("%s : Cannot enable new PCI device\n", pci_name(pdev));
  957. goto free_dvobj;
  958. }
  959. #ifdef CONFIG_64BIT_DMA
  960. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
  961. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  962. #else
  963. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  964. #endif
  965. RTW_INFO("RTL819xCE: Using 64bit DMA\n");
  966. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
  967. err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
  968. #else
  969. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  970. #endif
  971. if (err != 0) {
  972. RTW_ERR("Unable to obtain 64bit DMA for consistent allocations\n");
  973. goto disable_picdev;
  974. }
  975. dvobj->bdma64 = _TRUE;
  976. } else
  977. #endif
  978. {
  979. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
  980. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
  981. #else
  982. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  983. #endif
  984. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
  985. err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  986. #else
  987. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  988. #endif
  989. if (err != 0) {
  990. RTW_ERR("Unable to obtain 32bit DMA for consistent allocations\n");
  991. goto disable_picdev;
  992. }
  993. }
  994. dvobj->bdma64 = _FALSE;
  995. }
  996. pci_set_master(pdev);
  997. err = pci_request_regions(pdev, DRV_NAME);
  998. if (err != 0) {
  999. RTW_ERR("Can't obtain PCI resources\n");
  1000. goto disable_picdev;
  1001. }
  1002. #ifdef RTK_129X_PLATFORM
  1003. if (pdev->bus->number == 0x00) {
  1004. pmem_start = PCIE_SLOT1_MEM_START;
  1005. pmem_len = PCIE_SLOT1_MEM_LEN;
  1006. pmem_flags = 0;
  1007. RTW_PRINT("RTD129X: PCIE SLOT1\n");
  1008. } else if (pdev->bus->number == 0x01) {
  1009. pmem_start = PCIE_SLOT2_MEM_START;
  1010. pmem_len = PCIE_SLOT2_MEM_LEN;
  1011. pmem_flags = 0;
  1012. RTW_PRINT("RTD129X: PCIE SLOT2\n");
  1013. } else {
  1014. RTW_ERR(KERN_ERR "RTD129X: Wrong Slot Num\n");
  1015. goto release_regions;
  1016. }
  1017. #else
  1018. /* Search for memory map resource (index 0~5) */
  1019. for (i = 0 ; i < 6 ; i++) {
  1020. pmem_start = pci_resource_start(pdev, i);
  1021. pmem_len = pci_resource_len(pdev, i);
  1022. pmem_flags = pci_resource_flags(pdev, i);
  1023. if (pmem_flags & IORESOURCE_MEM)
  1024. break;
  1025. }
  1026. if (i == 6) {
  1027. RTW_ERR("%s: No MMIO resource found, abort!\n", __func__);
  1028. goto release_regions;
  1029. }
  1030. #endif /* RTK_DMP_PLATFORM */
  1031. #ifdef RTK_DMP_PLATFORM
  1032. dvobj->pci_mem_start = (unsigned long)ioremap_nocache(pmem_start, pmem_len);
  1033. #elif defined(RTK_129X_PLATFORM)
  1034. if (pdev->bus->number == 0x00)
  1035. dvobj->ctrl_start =
  1036. (unsigned long)ioremap(PCIE_SLOT1_CTRL_START, 0x200);
  1037. else if (pdev->bus->number == 0x01)
  1038. dvobj->ctrl_start =
  1039. (unsigned long)ioremap(PCIE_SLOT2_CTRL_START, 0x200);
  1040. if (dvobj->ctrl_start == 0) {
  1041. RTW_ERR("RTD129X: Can't map CTRL mem\n");
  1042. goto release_regions;
  1043. }
  1044. dvobj->mask_addr = dvobj->ctrl_start + PCIE_MASK_OFFSET;
  1045. dvobj->tran_addr = dvobj->ctrl_start + PCIE_TRANSLATE_OFFSET;
  1046. dvobj->pci_mem_start =
  1047. (unsigned long)ioremap_nocache(pmem_start, pmem_len);
  1048. #else
  1049. /* shared mem start */
  1050. dvobj->pci_mem_start = (unsigned long)pci_iomap(pdev, i, pmem_len);
  1051. #endif
  1052. if (dvobj->pci_mem_start == 0) {
  1053. RTW_ERR("Can't map PCI mem\n");
  1054. goto release_regions;
  1055. }
  1056. RTW_INFO("Memory mapped space start: 0x%08lx len:%08lx flags:%08lx, after map:0x%08lx\n",
  1057. pmem_start, pmem_len, pmem_flags, dvobj->pci_mem_start);
  1058. /*find bus info*/
  1059. pcipriv->busnumber = pdev->bus->number;
  1060. pcipriv->devnumber = PCI_SLOT(pdev->devfn);
  1061. pcipriv->funcnumber = PCI_FUNC(pdev->devfn);
  1062. /*find bridge info*/
  1063. if (bridge_pdev) {
  1064. pcipriv->pcibridge_busnum = bridge_pdev->bus->number;
  1065. pcipriv->pcibridge_devnum = PCI_SLOT(bridge_pdev->devfn);
  1066. pcipriv->pcibridge_funcnum = PCI_FUNC(bridge_pdev->devfn);
  1067. pcipriv->pcibridge_vendor = PCI_BRIDGE_VENDOR_UNKNOWN;
  1068. pcipriv->pcibridge_vendorid = bridge_pdev->vendor;
  1069. pcipriv->pcibridge_deviceid = bridge_pdev->device;
  1070. }
  1071. #if 0
  1072. /* Read PCI configuration Space Header */
  1073. for (i = 0; i < 16; i++)
  1074. pci_read_config_dword(pdev, (i << 2), &pci_cfg_space[i]);
  1075. #endif
  1076. /*step 1-1., decide the chip_type via device info*/
  1077. dvobj->interface_type = RTW_PCIE;
  1078. rtw_decide_chip_type_by_pci_driver_data(dvobj, pdid);
  1079. /* rtw_pci_parse_configuration(pdev, dvobj, (u8 *)&pci_cfg_space); */
  1080. rtw_pci_parse_configuration(pdev, dvobj);
  1081. for (PciBgVIdIdx = 0; PciBgVIdIdx < PCI_BRIDGE_VENDOR_MAX; PciBgVIdIdx++) {
  1082. if (pcipriv->pcibridge_vendorid == pcibridge_vendors[PciBgVIdIdx]) {
  1083. pcipriv->pcibridge_vendor = PciBgVIdIdx;
  1084. RTW_INFO("Pci Bridge Vendor is found: VID=0x%x, VendorIdx=%d\n", pcipriv->pcibridge_vendorid, PciBgVIdIdx);
  1085. break;
  1086. }
  1087. }
  1088. if (pcipriv->pcibridge_vendor != PCI_BRIDGE_VENDOR_UNKNOWN) {
  1089. rtw_pci_get_linkcontrol_reg(bridge_pdev, &pcipriv->pcibridge_linkctrlreg, &pcipriv->pcibridge_pciehdr_offset);
  1090. if (pcipriv->pcibridge_vendor == PCI_BRIDGE_VENDOR_AMD)
  1091. pcipriv->amd_l1_patch = rtw_pci_get_amd_l1_patch(dvobj, bridge_pdev);
  1092. }
  1093. status = _SUCCESS;
  1094. iounmap:
  1095. if (status != _SUCCESS && dvobj->pci_mem_start != 0) {
  1096. #if 1/* def RTK_DMP_PLATFORM */
  1097. pci_iounmap(pdev, (void *)dvobj->pci_mem_start);
  1098. #endif
  1099. dvobj->pci_mem_start = 0;
  1100. }
  1101. #ifdef RTK_129X_PLATFORM
  1102. if (status != _SUCCESS && dvobj->ctrl_start != 0) {
  1103. pci_iounmap(pdev, (void *)dvobj->ctrl_start);
  1104. dvobj->ctrl_start = 0;
  1105. }
  1106. #endif
  1107. release_regions:
  1108. if (status != _SUCCESS)
  1109. pci_release_regions(pdev);
  1110. disable_picdev:
  1111. if (status != _SUCCESS)
  1112. pci_disable_device(pdev);
  1113. free_dvobj:
  1114. if (status != _SUCCESS && dvobj) {
  1115. pci_set_drvdata(pdev, NULL);
  1116. devobj_deinit(dvobj);
  1117. dvobj = NULL;
  1118. }
  1119. exit:
  1120. return dvobj;
  1121. }
  1122. static void pci_dvobj_deinit(struct pci_dev *pdev)
  1123. {
  1124. struct dvobj_priv *dvobj = pci_get_drvdata(pdev);
  1125. pci_set_drvdata(pdev, NULL);
  1126. if (dvobj) {
  1127. if (dvobj->irq_alloc) {
  1128. free_irq(pdev->irq, dvobj);
  1129. pci_disable_msi(pdev);
  1130. dvobj->irq_alloc = 0;
  1131. }
  1132. if (dvobj->pci_mem_start != 0) {
  1133. #if 1/* def RTK_DMP_PLATFORM */
  1134. pci_iounmap(pdev, (void *)dvobj->pci_mem_start);
  1135. #endif
  1136. dvobj->pci_mem_start = 0;
  1137. }
  1138. #ifdef RTK_129X_PLATFORM
  1139. if (dvobj->ctrl_start != 0) {
  1140. pci_iounmap(pdev, (void *)dvobj->ctrl_start);
  1141. dvobj->ctrl_start = 0;
  1142. }
  1143. #endif
  1144. devobj_deinit(dvobj);
  1145. }
  1146. pci_release_regions(pdev);
  1147. pci_disable_device(pdev);
  1148. }
  1149. u8 rtw_set_hal_ops(_adapter *padapter)
  1150. {
  1151. /* alloc memory for HAL DATA */
  1152. if (rtw_hal_data_init(padapter) == _FAIL)
  1153. return _FAIL;
  1154. #ifdef CONFIG_RTL8188E
  1155. if (rtw_get_chip_type(padapter) == RTL8188E)
  1156. rtl8188ee_set_hal_ops(padapter);
  1157. #endif
  1158. #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  1159. if ((rtw_get_chip_type(padapter) == RTL8812) || (rtw_get_chip_type(padapter) == RTL8821))
  1160. rtl8812ae_set_hal_ops(padapter);
  1161. #endif
  1162. #ifdef CONFIG_RTL8723B
  1163. if (rtw_get_chip_type(padapter) == RTL8723B)
  1164. rtl8723be_set_hal_ops(padapter);
  1165. #endif
  1166. #ifdef CONFIG_RTL8723D
  1167. if (rtw_get_chip_type(padapter) == RTL8723D)
  1168. rtl8723de_set_hal_ops(padapter);
  1169. #endif
  1170. #ifdef CONFIG_RTL8192E
  1171. if (rtw_get_chip_type(padapter) == RTL8192E)
  1172. rtl8192ee_set_hal_ops(padapter);
  1173. #endif
  1174. #ifdef CONFIG_RTL8192F
  1175. if (rtw_get_chip_type(padapter) == RTL8192F)
  1176. rtl8192fe_set_hal_ops(padapter);
  1177. #endif
  1178. #ifdef CONFIG_RTL8814A
  1179. if (rtw_get_chip_type(padapter) == RTL8814A)
  1180. rtl8814ae_set_hal_ops(padapter);
  1181. #endif
  1182. #if defined(CONFIG_RTL8822B)
  1183. if (rtw_get_chip_type(padapter) == RTL8822B)
  1184. rtl8822be_set_hal_ops(padapter);
  1185. #endif
  1186. #if defined(CONFIG_RTL8821C)
  1187. if (rtw_get_chip_type(padapter) == RTL8821C)
  1188. rtl8821ce_set_hal_ops(padapter);
  1189. #endif
  1190. if (rtw_hal_ops_check(padapter) == _FAIL)
  1191. return _FAIL;
  1192. if (hal_spec_init(padapter) == _FAIL)
  1193. return _FAIL;
  1194. return _SUCCESS;
  1195. }
  1196. void pci_set_intf_ops(_adapter *padapter, struct _io_ops *pops)
  1197. {
  1198. #ifdef CONFIG_RTL8188E
  1199. if (rtw_get_chip_type(padapter) == RTL8188E)
  1200. rtl8188ee_set_intf_ops(pops);
  1201. #endif
  1202. #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  1203. if ((rtw_get_chip_type(padapter) == RTL8812) || (rtw_get_chip_type(padapter) == RTL8821))
  1204. rtl8812ae_set_intf_ops(pops);
  1205. #endif
  1206. #ifdef CONFIG_RTL8723B
  1207. if (rtw_get_chip_type(padapter) == RTL8723B)
  1208. rtl8723be_set_intf_ops(pops);
  1209. #endif
  1210. #ifdef CONFIG_RTL8723D
  1211. if (rtw_get_chip_type(padapter) == RTL8723D)
  1212. rtl8723de_set_intf_ops(pops);
  1213. #endif
  1214. #ifdef CONFIG_RTL8192E
  1215. if (rtw_get_chip_type(padapter) == RTL8192E)
  1216. rtl8192ee_set_intf_ops(pops);
  1217. #endif
  1218. #ifdef CONFIG_RTL8192F
  1219. if (rtw_get_chip_type(padapter) == RTL8192F)
  1220. rtl8192fe_set_intf_ops(pops);
  1221. #endif
  1222. #ifdef CONFIG_RTL8814A
  1223. if (rtw_get_chip_type(padapter) == RTL8814A)
  1224. rtl8814ae_set_intf_ops(pops);
  1225. #endif
  1226. #if defined(CONFIG_RTL8822B)
  1227. if (rtw_get_chip_type(padapter) == RTL8822B)
  1228. rtl8822be_set_intf_ops(pops);
  1229. #endif
  1230. #if defined(CONFIG_RTL8821C)
  1231. if (rtw_get_chip_type(padapter) == RTL8821C)
  1232. rtl8821ce_set_intf_ops(pops);
  1233. #endif
  1234. }
  1235. static void pci_intf_start(_adapter *padapter)
  1236. {
  1237. RTW_INFO("+pci_intf_start\n");
  1238. /* Enable hw interrupt */
  1239. rtw_hal_enable_interrupt(padapter);
  1240. RTW_INFO("-pci_intf_start\n");
  1241. }
  1242. static void rtw_mi_pci_tasklets_kill(_adapter *padapter)
  1243. {
  1244. int i;
  1245. _adapter *iface;
  1246. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  1247. for (i = 0; i < dvobj->iface_nums; i++) {
  1248. iface = dvobj->padapters[i];
  1249. if ((iface) && rtw_is_adapter_up(iface)) {
  1250. tasklet_kill(&(padapter->recvpriv.recv_tasklet));
  1251. tasklet_kill(&(padapter->recvpriv.irq_prepare_beacon_tasklet));
  1252. tasklet_kill(&(padapter->xmitpriv.xmit_tasklet));
  1253. }
  1254. }
  1255. }
  1256. static void pci_intf_stop(_adapter *padapter)
  1257. {
  1258. /* Disable hw interrupt */
  1259. if (!rtw_is_surprise_removed(padapter)) {
  1260. /* device still exists, so driver can do i/o operation */
  1261. rtw_hal_disable_interrupt(padapter);
  1262. rtw_mi_pci_tasklets_kill(padapter);
  1263. rtw_hal_set_hwreg(padapter, HW_VAR_PCIE_STOP_TX_DMA, 0);
  1264. rtw_hal_irp_reset(padapter);
  1265. } else {
  1266. /* Clear irq_enabled to prevent handle interrupt function. */
  1267. adapter_to_dvobj(padapter)->irq_enabled = 0;
  1268. }
  1269. }
  1270. static void disable_ht_for_spec_devid(const struct pci_device_id *pdid)
  1271. {
  1272. #ifdef CONFIG_80211N_HT
  1273. u16 vid, pid;
  1274. u32 flags;
  1275. int i;
  1276. int num = sizeof(specific_device_id_tbl) / sizeof(struct specific_device_id);
  1277. for (i = 0; i < num; i++) {
  1278. vid = specific_device_id_tbl[i].idVendor;
  1279. pid = specific_device_id_tbl[i].idProduct;
  1280. flags = specific_device_id_tbl[i].flags;
  1281. if ((pdid->vendor == vid) && (pdid->device == pid) && (flags & SPEC_DEV_ID_DISABLE_HT)) {
  1282. rtw_ht_enable = 0;
  1283. rtw_bw_mode = 0;
  1284. rtw_ampdu_enable = 0;
  1285. }
  1286. }
  1287. #endif
  1288. }
  1289. #ifdef CONFIG_PM
  1290. static int rtw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1291. {
  1292. int ret = 0;
  1293. struct dvobj_priv *dvobj = pci_get_drvdata(pdev);
  1294. _adapter *padapter = dvobj_get_primary_adapter(dvobj);
  1295. ret = rtw_suspend_common(padapter);
  1296. ret = pci_save_state(pdev);
  1297. if (ret != 0) {
  1298. RTW_INFO("%s Failed on pci_save_state (%d)\n", __func__, ret);
  1299. goto exit;
  1300. }
  1301. #ifdef CONFIG_WOWLAN
  1302. device_set_wakeup_enable(&pdev->dev, true);
  1303. #endif
  1304. pci_disable_device(pdev);
  1305. #ifdef CONFIG_WOWLAN
  1306. ret = pci_enable_wake(pdev, pci_choose_state(pdev, state), true);
  1307. if (ret != 0)
  1308. RTW_INFO("%s Failed on pci_enable_wake (%d)\n", __func__, ret);
  1309. #endif
  1310. ret = pci_set_power_state(pdev, pci_choose_state(pdev, state));
  1311. if (ret != 0)
  1312. RTW_INFO("%s Failed on pci_set_power_state (%d)\n", __func__, ret);
  1313. exit:
  1314. return ret;
  1315. }
  1316. int rtw_resume_process(_adapter *padapter)
  1317. {
  1318. return rtw_resume_common(padapter);
  1319. }
  1320. static int rtw_pci_resume(struct pci_dev *pdev)
  1321. {
  1322. struct dvobj_priv *dvobj = pci_get_drvdata(pdev);
  1323. _adapter *padapter = dvobj_get_primary_adapter(dvobj);
  1324. struct net_device *pnetdev = padapter->pnetdev;
  1325. struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
  1326. int err = 0;
  1327. err = pci_set_power_state(pdev, PCI_D0);
  1328. if (err != 0) {
  1329. RTW_INFO("%s Failed on pci_set_power_state (%d)\n", __func__, err);
  1330. goto exit;
  1331. }
  1332. err = pci_enable_device(pdev);
  1333. if (err != 0) {
  1334. RTW_INFO("%s Failed on pci_enable_device (%d)\n", __func__, err);
  1335. goto exit;
  1336. }
  1337. #ifdef CONFIG_WOWLAN
  1338. err = pci_enable_wake(pdev, PCI_D0, 0);
  1339. if (err != 0) {
  1340. RTW_INFO("%s Failed on pci_enable_wake (%d)\n", __func__, err);
  1341. goto exit;
  1342. }
  1343. #endif
  1344. #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37))
  1345. pci_restore_state(pdev);
  1346. #else
  1347. err = pci_restore_state(pdev);
  1348. if (err != 0) {
  1349. RTW_INFO("%s Failed on pci_restore_state (%d)\n", __func__, err);
  1350. goto exit;
  1351. }
  1352. #endif
  1353. #ifdef CONFIG_WOWLAN
  1354. device_set_wakeup_enable(&pdev->dev, false);
  1355. #endif
  1356. if (pwrpriv->wowlan_mode || pwrpriv->wowlan_ap_mode) {
  1357. rtw_resume_lock_suspend();
  1358. err = rtw_resume_process(padapter);
  1359. rtw_resume_unlock_suspend();
  1360. } else {
  1361. #ifdef CONFIG_RESUME_IN_WORKQUEUE
  1362. rtw_resume_in_workqueue(pwrpriv);
  1363. #else
  1364. if (rtw_is_earlysuspend_registered(pwrpriv)) {
  1365. /* jeff: bypass resume here, do in late_resume */
  1366. rtw_set_do_late_resume(pwrpriv, _TRUE);
  1367. } else {
  1368. rtw_resume_lock_suspend();
  1369. err = rtw_resume_process(padapter);
  1370. rtw_resume_unlock_suspend();
  1371. }
  1372. #endif
  1373. }
  1374. exit:
  1375. return err;
  1376. }
  1377. #endif/* CONFIG_PM */
  1378. _adapter *rtw_pci_primary_adapter_init(struct dvobj_priv *dvobj, struct pci_dev *pdev)
  1379. {
  1380. _adapter *padapter = NULL;
  1381. int status = _FAIL;
  1382. padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter));
  1383. if (padapter == NULL)
  1384. goto exit;
  1385. if (loadparam(padapter) != _SUCCESS)
  1386. goto free_adapter;
  1387. padapter->dvobj = dvobj;
  1388. rtw_set_drv_stopped(padapter);/*init*/
  1389. dvobj->padapters[dvobj->iface_nums++] = padapter;
  1390. padapter->iface_id = IFACE_ID0;
  1391. /* set adapter_type/iface type for primary padapter */
  1392. padapter->isprimary = _TRUE;
  1393. padapter->adapter_type = PRIMARY_ADAPTER;
  1394. #ifdef CONFIG_MI_WITH_MBSSID_CAM
  1395. padapter->hw_port = HW_PORT0;
  1396. #else
  1397. padapter->hw_port = HW_PORT0;
  1398. #endif
  1399. if (rtw_init_io_priv(padapter, pci_set_intf_ops) == _FAIL)
  1400. goto free_adapter;
  1401. /* step 2. hook HalFunc, allocate HalData */
  1402. /* hal_set_hal_ops(padapter); */
  1403. if (rtw_set_hal_ops(padapter) == _FAIL)
  1404. goto free_hal_data;
  1405. /* step 3. */
  1406. padapter->intf_start = &pci_intf_start;
  1407. padapter->intf_stop = &pci_intf_stop;
  1408. /* .3 */
  1409. rtw_hal_read_chip_version(padapter);
  1410. /* .4 */
  1411. rtw_hal_chip_configure(padapter);
  1412. #ifdef CONFIG_BT_COEXIST
  1413. rtw_btcoex_Initialize(padapter);
  1414. #endif
  1415. rtw_btcoex_wifionly_initialize(padapter);
  1416. /* step 4. read efuse/eeprom data and get mac_addr */
  1417. if (rtw_hal_read_chip_info(padapter) == _FAIL)
  1418. goto free_hal_data;
  1419. /* step 5. */
  1420. if (rtw_init_drv_sw(padapter) == _FAIL)
  1421. goto free_hal_data;
  1422. if (rtw_hal_inirp_init(padapter) == _FAIL)
  1423. goto free_hal_data;
  1424. rtw_macaddr_cfg(adapter_mac_addr(padapter), get_hal_mac_addr(padapter));
  1425. #ifdef CONFIG_MI_WITH_MBSSID_CAM
  1426. rtw_mbid_camid_alloc(padapter, adapter_mac_addr(padapter));
  1427. #endif
  1428. #ifdef CONFIG_P2P
  1429. rtw_init_wifidirect_addrs(padapter, adapter_mac_addr(padapter), adapter_mac_addr(padapter));
  1430. #endif /* CONFIG_P2P */
  1431. rtw_hal_disable_interrupt(padapter);
  1432. /* step 6. Init pci related configuration */
  1433. rtw_pci_initialize_adapter_common(padapter);
  1434. RTW_INFO("bDriverStopped:%s, bSurpriseRemoved:%s, bup:%d, hw_init_completed:%s\n"
  1435. , rtw_is_drv_stopped(padapter) ? "True" : "False"
  1436. , rtw_is_surprise_removed(padapter) ? "True" : "False"
  1437. , padapter->bup
  1438. , rtw_is_hw_init_completed(padapter) ? "True" : "False"
  1439. );
  1440. status = _SUCCESS;
  1441. free_hal_data:
  1442. if (status != _SUCCESS && padapter->HalData)
  1443. rtw_hal_free_data(padapter);
  1444. free_adapter:
  1445. if (status != _SUCCESS && padapter) {
  1446. #ifdef RTW_HALMAC
  1447. rtw_halmac_deinit_adapter(dvobj);
  1448. #endif
  1449. rtw_vmfree((u8 *)padapter, sizeof(*padapter));
  1450. padapter = NULL;
  1451. }
  1452. exit:
  1453. return padapter;
  1454. }
  1455. static void rtw_pci_primary_adapter_deinit(_adapter *padapter)
  1456. {
  1457. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1458. /* padapter->intf_stop(padapter); */
  1459. if (check_fwstate(pmlmepriv, _FW_LINKED))
  1460. rtw_disassoc_cmd(padapter, 0, RTW_CMDF_DIRECTLY);
  1461. #ifdef CONFIG_AP_MODE
  1462. if (MLME_IS_AP(padapter) || MLME_IS_MESH(padapter)) {
  1463. free_mlme_ap_info(padapter);
  1464. #ifdef CONFIG_HOSTAPD_MLME
  1465. hostapd_mode_unload(padapter);
  1466. #endif
  1467. }
  1468. #endif
  1469. /*rtw_cancel_all_timer(padapte);*/
  1470. #ifdef CONFIG_WOWLAN
  1471. adapter_to_pwrctl(padapter)->wowlan_mode = _FALSE;
  1472. #endif /* CONFIG_WOWLAN */
  1473. rtw_dev_unload(padapter);
  1474. RTW_INFO("%s, hw_init_completed=%s\n", __func__, rtw_is_hw_init_completed(padapter) ? "_TRUE" : "_FALSE");
  1475. rtw_hal_inirp_deinit(padapter);
  1476. rtw_free_drv_sw(padapter);
  1477. /* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */
  1478. rtw_os_ndev_free(padapter);
  1479. #ifdef RTW_HALMAC
  1480. rtw_halmac_deinit_adapter(adapter_to_dvobj(padapter));
  1481. #endif /* RTW_HALMAC */
  1482. rtw_vmfree((u8 *)padapter, sizeof(_adapter));
  1483. #ifdef CONFIG_PLATFORM_RTD2880B
  1484. RTW_INFO("wlan link down\n");
  1485. rtd2885_wlan_netlink_sendMsg("linkdown", "8712");
  1486. #endif
  1487. }
  1488. /*
  1489. * drv_init() - a device potentially for us
  1490. *
  1491. * notes: drv_init() is called when the bus driver has located a card for us to support.
  1492. * We accept the new device by returning 0.
  1493. */
  1494. static int rtw_drv_init(struct pci_dev *pdev, const struct pci_device_id *pdid)
  1495. {
  1496. int i, err = -ENODEV;
  1497. int status = _FAIL;
  1498. _adapter *padapter = NULL;
  1499. struct dvobj_priv *dvobj;
  1500. struct net_device *pnetdev;
  1501. /* RTW_INFO("+rtw_drv_init\n"); */
  1502. /* step 0. */
  1503. disable_ht_for_spec_devid(pdid);
  1504. /* Initialize dvobj_priv */
  1505. dvobj = pci_dvobj_init(pdev, pdid);
  1506. if (dvobj == NULL)
  1507. goto exit;
  1508. /* Initialize primary adapter */
  1509. padapter = rtw_pci_primary_adapter_init(dvobj, pdev);
  1510. if (padapter == NULL) {
  1511. RTW_INFO("rtw_pci_primary_adapter_init Failed!\n");
  1512. goto free_dvobj;
  1513. }
  1514. /* Initialize virtual interface */
  1515. #ifdef CONFIG_CONCURRENT_MODE
  1516. if (padapter->registrypriv.virtual_iface_num > (CONFIG_IFACE_NUMBER - 1))
  1517. padapter->registrypriv.virtual_iface_num = (CONFIG_IFACE_NUMBER - 1);
  1518. for (i = 0; i < padapter->registrypriv.virtual_iface_num; i++) {
  1519. if (rtw_drv_add_vir_if(padapter, pci_set_intf_ops) == NULL) {
  1520. RTW_INFO("rtw_drv_add_iface failed! (%d)\n", i);
  1521. goto free_if_vir;
  1522. }
  1523. }
  1524. #endif
  1525. #ifdef CONFIG_GLOBAL_UI_PID
  1526. if (ui_pid[1] != 0) {
  1527. RTW_INFO("ui_pid[1]:%d\n", ui_pid[1]);
  1528. rtw_signal_process(ui_pid[1], SIGUSR2);
  1529. }
  1530. #endif
  1531. /* dev_alloc_name && register_netdev */
  1532. if (rtw_os_ndevs_init(dvobj) != _SUCCESS)
  1533. goto free_if_vir;
  1534. #ifdef CONFIG_HOSTAPD_MLME
  1535. hostapd_mode_init(padapter);
  1536. #endif
  1537. #ifdef CONFIG_PLATFORM_RTD2880B
  1538. RTW_INFO("wlan link up\n");
  1539. rtd2885_wlan_netlink_sendMsg("linkup", "8712");
  1540. #endif
  1541. /* alloc irq */
  1542. if (pci_alloc_irq(dvobj) != _SUCCESS)
  1543. goto os_ndevs_deinit;
  1544. /* RTW_INFO("-871x_drv - drv_init, success!\n"); */
  1545. status = _SUCCESS;
  1546. os_ndevs_deinit:
  1547. if (status != _SUCCESS)
  1548. rtw_os_ndevs_deinit(dvobj);
  1549. free_if_vir:
  1550. if (status != _SUCCESS) {
  1551. #ifdef CONFIG_CONCURRENT_MODE
  1552. rtw_drv_stop_vir_ifaces(dvobj);
  1553. rtw_drv_free_vir_ifaces(dvobj);
  1554. #endif
  1555. }
  1556. if (status != _SUCCESS && padapter)
  1557. rtw_pci_primary_adapter_deinit(padapter);
  1558. free_dvobj:
  1559. if (status != _SUCCESS)
  1560. pci_dvobj_deinit(pdev);
  1561. exit:
  1562. return status == _SUCCESS ? 0 : -ENODEV;
  1563. }
  1564. /*
  1565. * dev_remove() - our device is being removed
  1566. */
  1567. /* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both */
  1568. static void rtw_dev_remove(struct pci_dev *pdev)
  1569. {
  1570. struct dvobj_priv *pdvobjpriv = pci_get_drvdata(pdev);
  1571. _adapter *padapter = dvobj_get_primary_adapter(pdvobjpriv);
  1572. struct net_device *pnetdev = padapter->pnetdev;
  1573. if (pdvobjpriv->processing_dev_remove == _TRUE) {
  1574. RTW_WARN("%s-line%d: Warning! device has been removed!\n", __func__, __LINE__);
  1575. return;
  1576. }
  1577. RTW_INFO("+rtw_dev_remove\n");
  1578. pdvobjpriv->processing_dev_remove = _TRUE;
  1579. if (unlikely(!padapter))
  1580. return;
  1581. /* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */
  1582. rtw_os_ndevs_unregister(pdvobjpriv);
  1583. #if 0
  1584. #ifdef RTK_DMP_PLATFORM
  1585. rtw_clr_surprise_removed(padapter); /* always trate as device exists*/
  1586. /* this will let the driver to disable it's interrupt */
  1587. #else
  1588. if (pci_drvpriv.drv_registered == _TRUE) {
  1589. /* RTW_INFO("r871xu_dev_remove():padapter->bSurpriseRemoved == _TRUE\n"); */
  1590. rtw_set_surprise_removed(padapter);
  1591. }
  1592. /*else
  1593. {
  1594. rtw_set_hw_init_completed(padapter, _FALSE);
  1595. }*/
  1596. #endif
  1597. #endif
  1598. #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
  1599. rtw_unregister_early_suspend(dvobj_to_pwrctl(pdvobjpriv));
  1600. #endif
  1601. if (GET_HAL_DATA(padapter)->bFWReady == _TRUE) {
  1602. rtw_pm_set_ips(padapter, IPS_NONE);
  1603. rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
  1604. LeaveAllPowerSaveMode(padapter);
  1605. }
  1606. rtw_set_drv_stopped(padapter); /*for stop thread*/
  1607. rtw_stop_cmd_thread(padapter);
  1608. #ifdef CONFIG_CONCURRENT_MODE
  1609. rtw_drv_stop_vir_ifaces(pdvobjpriv);
  1610. #endif
  1611. #ifdef CONFIG_BT_COEXIST
  1612. #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
  1613. if (GET_HAL_DATA(padapter)->EEPROMBluetoothCoexist)
  1614. rtw_btcoex_close_socket(padapter);
  1615. #endif
  1616. rtw_btcoex_HaltNotify(padapter);
  1617. #endif
  1618. rtw_pci_primary_adapter_deinit(padapter);
  1619. #ifdef CONFIG_CONCURRENT_MODE
  1620. rtw_drv_free_vir_ifaces(pdvobjpriv);
  1621. #endif
  1622. pci_dvobj_deinit(pdev);
  1623. RTW_INFO("-r871xu_dev_remove, done\n");
  1624. return;
  1625. }
  1626. static void rtw_dev_shutdown(struct pci_dev *pdev)
  1627. {
  1628. struct dvobj_priv *pdvobjpriv = pci_get_drvdata(pdev);
  1629. _adapter *padapter = dvobj_get_primary_adapter(pdvobjpriv);
  1630. struct net_device *pnetdev = padapter->pnetdev;
  1631. #ifdef CONFIG_RTL8723D
  1632. if (IS_HARDWARE_TYPE_8723DE(padapter)) {
  1633. u1Byte u1Tmp;
  1634. u1Tmp = PlatformEFIORead1Byte(padapter, 0x75 /*REG_HCI_OPT_CTRL_8723D+1*/);
  1635. PlatformEFIOWrite1Byte(padapter, 0x75 /*REG_HCI_OPT_CTRL_8723D+1*/, (u1Tmp|BIT0));/*Disable USB Suspend Signal*/
  1636. }
  1637. #endif
  1638. rtw_dev_remove(pdev);
  1639. }
  1640. static int __init rtw_drv_entry(void)
  1641. {
  1642. int ret = 0;
  1643. RTW_PRINT("module init start\n");
  1644. dump_drv_version(RTW_DBGDUMP);
  1645. #ifdef BTCOEXVERSION
  1646. RTW_PRINT(DRV_NAME" BT-Coex version = %s\n", BTCOEXVERSION);
  1647. #endif /* BTCOEXVERSION */
  1648. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
  1649. /* console_suspend_enabled=0; */
  1650. #endif
  1651. pci_drvpriv.drv_registered = _TRUE;
  1652. rtw_suspend_lock_init();
  1653. rtw_drv_proc_init();
  1654. rtw_ndev_notifier_register();
  1655. rtw_inetaddr_notifier_register();
  1656. ret = pci_register_driver(&pci_drvpriv.rtw_pci_drv);
  1657. if (ret != 0) {
  1658. pci_drvpriv.drv_registered = _FALSE;
  1659. rtw_suspend_lock_uninit();
  1660. rtw_drv_proc_deinit();
  1661. rtw_ndev_notifier_unregister();
  1662. rtw_inetaddr_notifier_unregister();
  1663. goto exit;
  1664. }
  1665. exit:
  1666. RTW_PRINT("module init ret=%d\n", ret);
  1667. return ret;
  1668. }
  1669. static void __exit rtw_drv_halt(void)
  1670. {
  1671. RTW_PRINT("module exit start\n");
  1672. pci_drvpriv.drv_registered = _FALSE;
  1673. pci_unregister_driver(&pci_drvpriv.rtw_pci_drv);
  1674. rtw_suspend_lock_uninit();
  1675. rtw_drv_proc_deinit();
  1676. rtw_ndev_notifier_unregister();
  1677. rtw_inetaddr_notifier_unregister();
  1678. RTW_PRINT("module exit success\n");
  1679. rtw_mstat_dump(RTW_DBGDUMP);
  1680. }
  1681. module_init(rtw_drv_entry);
  1682. module_exit(rtw_drv_halt);