main.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  1. /*
  2. * Marvell Wireless LAN device driver: major functions
  3. *
  4. * Copyright (C) 2011-2014, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include <linux/suspend.h>
  20. #include "main.h"
  21. #include "wmm.h"
  22. #include "cfg80211.h"
  23. #include "11n.h"
  24. #define VERSION "1.0"
  25. #define MFG_FIRMWARE "mwifiex_mfg.bin"
  26. static unsigned int debug_mask = MWIFIEX_DEFAULT_DEBUG_MASK;
  27. module_param(debug_mask, uint, 0);
  28. MODULE_PARM_DESC(debug_mask, "bitmap for debug flags");
  29. const char driver_version[] = "mwifiex " VERSION " (%s) ";
  30. static char *cal_data_cfg;
  31. module_param(cal_data_cfg, charp, 0);
  32. static unsigned short driver_mode;
  33. module_param(driver_mode, ushort, 0);
  34. MODULE_PARM_DESC(driver_mode,
  35. "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
  36. bool mfg_mode;
  37. module_param(mfg_mode, bool, 0);
  38. MODULE_PARM_DESC(mfg_mode, "manufacturing mode enable:1, disable:0");
  39. /*
  40. * This function registers the device and performs all the necessary
  41. * initializations.
  42. *
  43. * The following initialization operations are performed -
  44. * - Allocate adapter structure
  45. * - Save interface specific operations table in adapter
  46. * - Call interface specific initialization routine
  47. * - Allocate private structures
  48. * - Set default adapter structure parameters
  49. * - Initialize locks
  50. *
  51. * In case of any errors during inittialization, this function also ensures
  52. * proper cleanup before exiting.
  53. */
  54. static int mwifiex_register(void *card, struct device *dev,
  55. struct mwifiex_if_ops *if_ops, void **padapter)
  56. {
  57. struct mwifiex_adapter *adapter;
  58. int i;
  59. adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
  60. if (!adapter)
  61. return -ENOMEM;
  62. *padapter = adapter;
  63. adapter->dev = dev;
  64. adapter->card = card;
  65. /* Save interface specific operations in adapter */
  66. memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops));
  67. adapter->debug_mask = debug_mask;
  68. /* card specific initialization has been deferred until now .. */
  69. if (adapter->if_ops.init_if)
  70. if (adapter->if_ops.init_if(adapter))
  71. goto error;
  72. adapter->priv_num = 0;
  73. for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
  74. /* Allocate memory for private structure */
  75. adapter->priv[i] =
  76. kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL);
  77. if (!adapter->priv[i])
  78. goto error;
  79. adapter->priv[i]->adapter = adapter;
  80. adapter->priv_num++;
  81. }
  82. mwifiex_init_lock_list(adapter);
  83. setup_timer(&adapter->cmd_timer, mwifiex_cmd_timeout_func,
  84. (unsigned long)adapter);
  85. return 0;
  86. error:
  87. mwifiex_dbg(adapter, ERROR,
  88. "info: leave mwifiex_register with error\n");
  89. for (i = 0; i < adapter->priv_num; i++)
  90. kfree(adapter->priv[i]);
  91. kfree(adapter);
  92. return -1;
  93. }
  94. /*
  95. * This function unregisters the device and performs all the necessary
  96. * cleanups.
  97. *
  98. * The following cleanup operations are performed -
  99. * - Free the timers
  100. * - Free beacon buffers
  101. * - Free private structures
  102. * - Free adapter structure
  103. */
  104. static int mwifiex_unregister(struct mwifiex_adapter *adapter)
  105. {
  106. s32 i;
  107. if (adapter->if_ops.cleanup_if)
  108. adapter->if_ops.cleanup_if(adapter);
  109. del_timer_sync(&adapter->cmd_timer);
  110. /* Free private structures */
  111. for (i = 0; i < adapter->priv_num; i++) {
  112. if (adapter->priv[i]) {
  113. mwifiex_free_curr_bcn(adapter->priv[i]);
  114. kfree(adapter->priv[i]);
  115. }
  116. }
  117. if (adapter->nd_info) {
  118. for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
  119. kfree(adapter->nd_info->matches[i]);
  120. kfree(adapter->nd_info);
  121. adapter->nd_info = NULL;
  122. }
  123. kfree(adapter->regd);
  124. kfree(adapter);
  125. return 0;
  126. }
  127. void mwifiex_queue_main_work(struct mwifiex_adapter *adapter)
  128. {
  129. unsigned long flags;
  130. spin_lock_irqsave(&adapter->main_proc_lock, flags);
  131. if (adapter->mwifiex_processing) {
  132. adapter->more_task_flag = true;
  133. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  134. } else {
  135. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  136. queue_work(adapter->workqueue, &adapter->main_work);
  137. }
  138. }
  139. EXPORT_SYMBOL_GPL(mwifiex_queue_main_work);
  140. static void mwifiex_queue_rx_work(struct mwifiex_adapter *adapter)
  141. {
  142. unsigned long flags;
  143. spin_lock_irqsave(&adapter->rx_proc_lock, flags);
  144. if (adapter->rx_processing) {
  145. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  146. } else {
  147. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  148. queue_work(adapter->rx_workqueue, &adapter->rx_work);
  149. }
  150. }
  151. static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
  152. {
  153. unsigned long flags;
  154. struct sk_buff *skb;
  155. struct mwifiex_rxinfo *rx_info;
  156. spin_lock_irqsave(&adapter->rx_proc_lock, flags);
  157. if (adapter->rx_processing || adapter->rx_locked) {
  158. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  159. goto exit_rx_proc;
  160. } else {
  161. adapter->rx_processing = true;
  162. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  163. }
  164. /* Check for Rx data */
  165. while ((skb = skb_dequeue(&adapter->rx_data_q))) {
  166. atomic_dec(&adapter->rx_pending);
  167. if ((adapter->delay_main_work ||
  168. adapter->iface_type == MWIFIEX_USB) &&
  169. (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) {
  170. if (adapter->if_ops.submit_rem_rx_urbs)
  171. adapter->if_ops.submit_rem_rx_urbs(adapter);
  172. adapter->delay_main_work = false;
  173. mwifiex_queue_main_work(adapter);
  174. }
  175. rx_info = MWIFIEX_SKB_RXCB(skb);
  176. if (rx_info->buf_type == MWIFIEX_TYPE_AGGR_DATA) {
  177. if (adapter->if_ops.deaggr_pkt)
  178. adapter->if_ops.deaggr_pkt(adapter, skb);
  179. dev_kfree_skb_any(skb);
  180. } else {
  181. mwifiex_handle_rx_packet(adapter, skb);
  182. }
  183. }
  184. spin_lock_irqsave(&adapter->rx_proc_lock, flags);
  185. adapter->rx_processing = false;
  186. spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
  187. exit_rx_proc:
  188. return 0;
  189. }
  190. /*
  191. * The main process.
  192. *
  193. * This function is the main procedure of the driver and handles various driver
  194. * operations. It runs in a loop and provides the core functionalities.
  195. *
  196. * The main responsibilities of this function are -
  197. * - Ensure concurrency control
  198. * - Handle pending interrupts and call interrupt handlers
  199. * - Wake up the card if required
  200. * - Handle command responses and call response handlers
  201. * - Handle events and call event handlers
  202. * - Execute pending commands
  203. * - Transmit pending data packets
  204. */
  205. int mwifiex_main_process(struct mwifiex_adapter *adapter)
  206. {
  207. int ret = 0;
  208. unsigned long flags;
  209. spin_lock_irqsave(&adapter->main_proc_lock, flags);
  210. /* Check if already processing */
  211. if (adapter->mwifiex_processing || adapter->main_locked) {
  212. adapter->more_task_flag = true;
  213. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  214. return 0;
  215. } else {
  216. adapter->mwifiex_processing = true;
  217. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  218. }
  219. process_start:
  220. do {
  221. if (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY)
  222. break;
  223. /* For non-USB interfaces, If we process interrupts first, it
  224. * would increase RX pending even further. Avoid this by
  225. * checking if rx_pending has crossed high threshold and
  226. * schedule rx work queue and then process interrupts.
  227. * For USB interface, there are no interrupts. We already have
  228. * HIGH_RX_PENDING check in usb.c
  229. */
  230. if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING &&
  231. adapter->iface_type != MWIFIEX_USB) {
  232. adapter->delay_main_work = true;
  233. mwifiex_queue_rx_work(adapter);
  234. break;
  235. }
  236. /* Handle pending interrupt if any */
  237. if (adapter->int_status) {
  238. if (adapter->hs_activated)
  239. mwifiex_process_hs_config(adapter);
  240. if (adapter->if_ops.process_int_status)
  241. adapter->if_ops.process_int_status(adapter);
  242. }
  243. if (adapter->rx_work_enabled && adapter->data_received)
  244. mwifiex_queue_rx_work(adapter);
  245. /* Need to wake up the card ? */
  246. if ((adapter->ps_state == PS_STATE_SLEEP) &&
  247. (adapter->pm_wakeup_card_req &&
  248. !adapter->pm_wakeup_fw_try) &&
  249. (is_command_pending(adapter) ||
  250. !skb_queue_empty(&adapter->tx_data_q) ||
  251. !mwifiex_bypass_txlist_empty(adapter) ||
  252. !mwifiex_wmm_lists_empty(adapter))) {
  253. adapter->pm_wakeup_fw_try = true;
  254. mod_timer(&adapter->wakeup_timer, jiffies + (HZ*3));
  255. adapter->if_ops.wakeup(adapter);
  256. continue;
  257. }
  258. if (IS_CARD_RX_RCVD(adapter)) {
  259. adapter->data_received = false;
  260. adapter->pm_wakeup_fw_try = false;
  261. del_timer(&adapter->wakeup_timer);
  262. if (adapter->ps_state == PS_STATE_SLEEP)
  263. adapter->ps_state = PS_STATE_AWAKE;
  264. } else {
  265. /* We have tried to wakeup the card already */
  266. if (adapter->pm_wakeup_fw_try)
  267. break;
  268. if (adapter->ps_state == PS_STATE_PRE_SLEEP)
  269. mwifiex_check_ps_cond(adapter);
  270. if (adapter->ps_state != PS_STATE_AWAKE)
  271. break;
  272. if (adapter->tx_lock_flag) {
  273. if (adapter->iface_type == MWIFIEX_USB) {
  274. if (!adapter->usb_mc_setup)
  275. break;
  276. } else
  277. break;
  278. }
  279. if ((!adapter->scan_chan_gap_enabled &&
  280. adapter->scan_processing) || adapter->data_sent ||
  281. mwifiex_is_tdls_chan_switching
  282. (mwifiex_get_priv(adapter,
  283. MWIFIEX_BSS_ROLE_STA)) ||
  284. (mwifiex_wmm_lists_empty(adapter) &&
  285. mwifiex_bypass_txlist_empty(adapter) &&
  286. skb_queue_empty(&adapter->tx_data_q))) {
  287. if (adapter->cmd_sent || adapter->curr_cmd ||
  288. !mwifiex_is_send_cmd_allowed
  289. (mwifiex_get_priv(adapter,
  290. MWIFIEX_BSS_ROLE_STA)) ||
  291. (!is_command_pending(adapter)))
  292. break;
  293. }
  294. }
  295. /* Check for event */
  296. if (adapter->event_received) {
  297. adapter->event_received = false;
  298. mwifiex_process_event(adapter);
  299. }
  300. /* Check for Cmd Resp */
  301. if (adapter->cmd_resp_received) {
  302. adapter->cmd_resp_received = false;
  303. mwifiex_process_cmdresp(adapter);
  304. /* call mwifiex back when init_fw is done */
  305. if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
  306. adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  307. mwifiex_init_fw_complete(adapter);
  308. }
  309. }
  310. /* Check if we need to confirm Sleep Request
  311. received previously */
  312. if (adapter->ps_state == PS_STATE_PRE_SLEEP)
  313. mwifiex_check_ps_cond(adapter);
  314. /* * The ps_state may have been changed during processing of
  315. * Sleep Request event.
  316. */
  317. if ((adapter->ps_state == PS_STATE_SLEEP) ||
  318. (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
  319. (adapter->ps_state == PS_STATE_SLEEP_CFM)) {
  320. continue;
  321. }
  322. if (adapter->tx_lock_flag) {
  323. if (adapter->iface_type == MWIFIEX_USB) {
  324. if (!adapter->usb_mc_setup)
  325. continue;
  326. } else
  327. continue;
  328. }
  329. if (!adapter->cmd_sent && !adapter->curr_cmd &&
  330. mwifiex_is_send_cmd_allowed
  331. (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
  332. if (mwifiex_exec_next_cmd(adapter) == -1) {
  333. ret = -1;
  334. break;
  335. }
  336. }
  337. /** If USB Multi channel setup ongoing,
  338. * wait for ready to tx data.
  339. */
  340. if (adapter->iface_type == MWIFIEX_USB &&
  341. adapter->usb_mc_setup)
  342. continue;
  343. if ((adapter->scan_chan_gap_enabled ||
  344. !adapter->scan_processing) &&
  345. !adapter->data_sent &&
  346. !skb_queue_empty(&adapter->tx_data_q)) {
  347. mwifiex_process_tx_queue(adapter);
  348. if (adapter->hs_activated) {
  349. adapter->is_hs_configured = false;
  350. mwifiex_hs_activated_event
  351. (mwifiex_get_priv
  352. (adapter, MWIFIEX_BSS_ROLE_ANY),
  353. false);
  354. }
  355. }
  356. if ((adapter->scan_chan_gap_enabled ||
  357. !adapter->scan_processing) &&
  358. !adapter->data_sent &&
  359. !mwifiex_bypass_txlist_empty(adapter) &&
  360. !mwifiex_is_tdls_chan_switching
  361. (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
  362. mwifiex_process_bypass_tx(adapter);
  363. if (adapter->hs_activated) {
  364. adapter->is_hs_configured = false;
  365. mwifiex_hs_activated_event
  366. (mwifiex_get_priv
  367. (adapter, MWIFIEX_BSS_ROLE_ANY),
  368. false);
  369. }
  370. }
  371. if ((adapter->scan_chan_gap_enabled ||
  372. !adapter->scan_processing) &&
  373. !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter) &&
  374. !mwifiex_is_tdls_chan_switching
  375. (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
  376. mwifiex_wmm_process_tx(adapter);
  377. if (adapter->hs_activated) {
  378. adapter->is_hs_configured = false;
  379. mwifiex_hs_activated_event
  380. (mwifiex_get_priv
  381. (adapter, MWIFIEX_BSS_ROLE_ANY),
  382. false);
  383. }
  384. }
  385. if (adapter->delay_null_pkt && !adapter->cmd_sent &&
  386. !adapter->curr_cmd && !is_command_pending(adapter) &&
  387. (mwifiex_wmm_lists_empty(adapter) &&
  388. mwifiex_bypass_txlist_empty(adapter) &&
  389. skb_queue_empty(&adapter->tx_data_q))) {
  390. if (!mwifiex_send_null_packet
  391. (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
  392. MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
  393. MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
  394. adapter->delay_null_pkt = false;
  395. adapter->ps_state = PS_STATE_SLEEP;
  396. }
  397. break;
  398. }
  399. } while (true);
  400. spin_lock_irqsave(&adapter->main_proc_lock, flags);
  401. if (adapter->more_task_flag) {
  402. adapter->more_task_flag = false;
  403. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  404. goto process_start;
  405. }
  406. adapter->mwifiex_processing = false;
  407. spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
  408. return ret;
  409. }
  410. EXPORT_SYMBOL_GPL(mwifiex_main_process);
  411. /*
  412. * This function frees the adapter structure.
  413. *
  414. * Additionally, this closes the netlink socket, frees the timers
  415. * and private structures.
  416. */
  417. static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
  418. {
  419. if (!adapter) {
  420. pr_err("%s: adapter is NULL\n", __func__);
  421. return;
  422. }
  423. mwifiex_unregister(adapter);
  424. pr_debug("info: %s: free adapter\n", __func__);
  425. }
  426. /*
  427. * This function cancels all works in the queue and destroys
  428. * the main workqueue.
  429. */
  430. static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
  431. {
  432. if (adapter->workqueue) {
  433. flush_workqueue(adapter->workqueue);
  434. destroy_workqueue(adapter->workqueue);
  435. adapter->workqueue = NULL;
  436. }
  437. if (adapter->rx_workqueue) {
  438. flush_workqueue(adapter->rx_workqueue);
  439. destroy_workqueue(adapter->rx_workqueue);
  440. adapter->rx_workqueue = NULL;
  441. }
  442. }
  443. /*
  444. * This function gets firmware and initializes it.
  445. *
  446. * The main initialization steps followed are -
  447. * - Download the correct firmware to card
  448. * - Issue the init commands to firmware
  449. */
  450. static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context)
  451. {
  452. int ret;
  453. char fmt[64];
  454. struct mwifiex_adapter *adapter = context;
  455. struct mwifiex_fw_image fw;
  456. bool init_failed = false;
  457. struct wireless_dev *wdev;
  458. struct completion *fw_done = adapter->fw_done;
  459. if (!firmware) {
  460. mwifiex_dbg(adapter, ERROR,
  461. "Failed to get firmware %s\n", adapter->fw_name);
  462. goto err_dnld_fw;
  463. }
  464. memset(&fw, 0, sizeof(struct mwifiex_fw_image));
  465. adapter->firmware = firmware;
  466. fw.fw_buf = (u8 *) adapter->firmware->data;
  467. fw.fw_len = adapter->firmware->size;
  468. if (adapter->if_ops.dnld_fw) {
  469. ret = adapter->if_ops.dnld_fw(adapter, &fw);
  470. } else {
  471. ret = mwifiex_dnld_fw(adapter, &fw);
  472. }
  473. if (ret == -1)
  474. goto err_dnld_fw;
  475. mwifiex_dbg(adapter, MSG, "WLAN FW is active\n");
  476. if (cal_data_cfg) {
  477. if ((request_firmware(&adapter->cal_data, cal_data_cfg,
  478. adapter->dev)) < 0)
  479. mwifiex_dbg(adapter, ERROR,
  480. "Cal data request_firmware() failed\n");
  481. }
  482. /* enable host interrupt after fw dnld is successful */
  483. if (adapter->if_ops.enable_int) {
  484. if (adapter->if_ops.enable_int(adapter))
  485. goto err_dnld_fw;
  486. }
  487. adapter->init_wait_q_woken = false;
  488. ret = mwifiex_init_fw(adapter);
  489. if (ret == -1) {
  490. goto err_init_fw;
  491. } else if (!ret) {
  492. adapter->hw_status = MWIFIEX_HW_STATUS_READY;
  493. goto done;
  494. }
  495. /* Wait for mwifiex_init to complete */
  496. if (!adapter->mfg_mode) {
  497. wait_event_interruptible(adapter->init_wait_q,
  498. adapter->init_wait_q_woken);
  499. if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
  500. goto err_init_fw;
  501. }
  502. if (!adapter->wiphy) {
  503. if (mwifiex_register_cfg80211(adapter)) {
  504. mwifiex_dbg(adapter, ERROR,
  505. "cannot register with cfg80211\n");
  506. goto err_init_fw;
  507. }
  508. }
  509. if (mwifiex_init_channel_scan_gap(adapter)) {
  510. mwifiex_dbg(adapter, ERROR,
  511. "could not init channel stats table\n");
  512. goto err_init_fw;
  513. }
  514. if (driver_mode) {
  515. driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK;
  516. driver_mode |= MWIFIEX_DRIVER_MODE_STA;
  517. }
  518. rtnl_lock();
  519. /* Create station interface by default */
  520. wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", NET_NAME_ENUM,
  521. NL80211_IFTYPE_STATION, NULL);
  522. if (IS_ERR(wdev)) {
  523. mwifiex_dbg(adapter, ERROR,
  524. "cannot create default STA interface\n");
  525. rtnl_unlock();
  526. goto err_add_intf;
  527. }
  528. if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) {
  529. wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d", NET_NAME_ENUM,
  530. NL80211_IFTYPE_AP, NULL);
  531. if (IS_ERR(wdev)) {
  532. mwifiex_dbg(adapter, ERROR,
  533. "cannot create AP interface\n");
  534. rtnl_unlock();
  535. goto err_add_intf;
  536. }
  537. }
  538. if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) {
  539. wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d", NET_NAME_ENUM,
  540. NL80211_IFTYPE_P2P_CLIENT, NULL);
  541. if (IS_ERR(wdev)) {
  542. mwifiex_dbg(adapter, ERROR,
  543. "cannot create p2p client interface\n");
  544. rtnl_unlock();
  545. goto err_add_intf;
  546. }
  547. }
  548. rtnl_unlock();
  549. mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
  550. mwifiex_dbg(adapter, MSG, "driver_version = %s\n", fmt);
  551. goto done;
  552. err_add_intf:
  553. vfree(adapter->chan_stats);
  554. wiphy_unregister(adapter->wiphy);
  555. wiphy_free(adapter->wiphy);
  556. err_init_fw:
  557. if (adapter->if_ops.disable_int)
  558. adapter->if_ops.disable_int(adapter);
  559. err_dnld_fw:
  560. mwifiex_dbg(adapter, ERROR,
  561. "info: %s: unregister device\n", __func__);
  562. if (adapter->if_ops.unregister_dev)
  563. adapter->if_ops.unregister_dev(adapter);
  564. adapter->surprise_removed = true;
  565. mwifiex_terminate_workqueue(adapter);
  566. if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
  567. pr_debug("info: %s: shutdown mwifiex\n", __func__);
  568. mwifiex_shutdown_drv(adapter);
  569. }
  570. init_failed = true;
  571. done:
  572. if (adapter->cal_data) {
  573. release_firmware(adapter->cal_data);
  574. adapter->cal_data = NULL;
  575. }
  576. if (adapter->firmware) {
  577. release_firmware(adapter->firmware);
  578. adapter->firmware = NULL;
  579. }
  580. if (init_failed)
  581. mwifiex_free_adapter(adapter);
  582. /* Tell all current and future waiters we're finished */
  583. complete_all(fw_done);
  584. return init_failed ? -EIO : 0;
  585. }
  586. static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
  587. {
  588. _mwifiex_fw_dpc(firmware, context);
  589. }
  590. /*
  591. * This function gets the firmware and (if called asynchronously) kicks off the
  592. * HW init when done.
  593. */
  594. static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter,
  595. bool req_fw_nowait)
  596. {
  597. int ret;
  598. /* Override default firmware with manufacturing one if
  599. * manufacturing mode is enabled
  600. */
  601. if (mfg_mode) {
  602. if (strlcpy(adapter->fw_name, MFG_FIRMWARE,
  603. sizeof(adapter->fw_name)) >=
  604. sizeof(adapter->fw_name)) {
  605. pr_err("%s: fw_name too long!\n", __func__);
  606. return -1;
  607. }
  608. }
  609. if (req_fw_nowait) {
  610. ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
  611. adapter->dev, GFP_KERNEL, adapter,
  612. mwifiex_fw_dpc);
  613. } else {
  614. ret = request_firmware(&adapter->firmware,
  615. adapter->fw_name,
  616. adapter->dev);
  617. }
  618. if (ret < 0)
  619. mwifiex_dbg(adapter, ERROR, "request_firmware%s error %d\n",
  620. req_fw_nowait ? "_nowait" : "", ret);
  621. return ret;
  622. }
  623. /*
  624. * CFG802.11 network device handler for open.
  625. *
  626. * Starts the data queue.
  627. */
  628. static int
  629. mwifiex_open(struct net_device *dev)
  630. {
  631. netif_carrier_off(dev);
  632. return 0;
  633. }
  634. /*
  635. * CFG802.11 network device handler for close.
  636. */
  637. static int
  638. mwifiex_close(struct net_device *dev)
  639. {
  640. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  641. if (priv->scan_request) {
  642. struct cfg80211_scan_info info = {
  643. .aborted = true,
  644. };
  645. mwifiex_dbg(priv->adapter, INFO,
  646. "aborting scan on ndo_stop\n");
  647. cfg80211_scan_done(priv->scan_request, &info);
  648. priv->scan_request = NULL;
  649. priv->scan_aborting = true;
  650. }
  651. if (priv->sched_scanning) {
  652. mwifiex_dbg(priv->adapter, INFO,
  653. "aborting bgscan on ndo_stop\n");
  654. mwifiex_stop_bg_scan(priv);
  655. cfg80211_sched_scan_stopped(priv->wdev.wiphy, 0);
  656. }
  657. return 0;
  658. }
  659. static bool
  660. mwifiex_bypass_tx_queue(struct mwifiex_private *priv,
  661. struct sk_buff *skb)
  662. {
  663. struct ethhdr *eth_hdr = (struct ethhdr *)skb->data;
  664. if (ntohs(eth_hdr->h_proto) == ETH_P_PAE ||
  665. mwifiex_is_skb_mgmt_frame(skb) ||
  666. (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
  667. ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
  668. (ntohs(eth_hdr->h_proto) == ETH_P_TDLS))) {
  669. mwifiex_dbg(priv->adapter, DATA,
  670. "bypass txqueue; eth type %#x, mgmt %d\n",
  671. ntohs(eth_hdr->h_proto),
  672. mwifiex_is_skb_mgmt_frame(skb));
  673. return true;
  674. }
  675. return false;
  676. }
  677. /*
  678. * Add buffer into wmm tx queue and queue work to transmit it.
  679. */
  680. int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
  681. {
  682. struct netdev_queue *txq;
  683. int index = mwifiex_1d_to_wmm_queue[skb->priority];
  684. if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
  685. txq = netdev_get_tx_queue(priv->netdev, index);
  686. if (!netif_tx_queue_stopped(txq)) {
  687. netif_tx_stop_queue(txq);
  688. mwifiex_dbg(priv->adapter, DATA,
  689. "stop queue: %d\n", index);
  690. }
  691. }
  692. if (mwifiex_bypass_tx_queue(priv, skb)) {
  693. atomic_inc(&priv->adapter->tx_pending);
  694. atomic_inc(&priv->adapter->bypass_tx_pending);
  695. mwifiex_wmm_add_buf_bypass_txqueue(priv, skb);
  696. } else {
  697. atomic_inc(&priv->adapter->tx_pending);
  698. mwifiex_wmm_add_buf_txqueue(priv, skb);
  699. }
  700. mwifiex_queue_main_work(priv->adapter);
  701. return 0;
  702. }
  703. struct sk_buff *
  704. mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv,
  705. struct sk_buff *skb, u8 flag, u64 *cookie)
  706. {
  707. struct sk_buff *orig_skb = skb;
  708. struct mwifiex_txinfo *tx_info, *orig_tx_info;
  709. skb = skb_clone(skb, GFP_ATOMIC);
  710. if (skb) {
  711. unsigned long flags;
  712. int id;
  713. spin_lock_irqsave(&priv->ack_status_lock, flags);
  714. id = idr_alloc(&priv->ack_status_frames, orig_skb,
  715. 1, 0x10, GFP_ATOMIC);
  716. spin_unlock_irqrestore(&priv->ack_status_lock, flags);
  717. if (id >= 0) {
  718. tx_info = MWIFIEX_SKB_TXCB(skb);
  719. tx_info->ack_frame_id = id;
  720. tx_info->flags |= flag;
  721. orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb);
  722. orig_tx_info->ack_frame_id = id;
  723. orig_tx_info->flags |= flag;
  724. if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie)
  725. orig_tx_info->cookie = *cookie;
  726. } else if (skb_shared(skb)) {
  727. kfree_skb(orig_skb);
  728. } else {
  729. kfree_skb(skb);
  730. skb = orig_skb;
  731. }
  732. } else {
  733. /* couldn't clone -- lose tx status ... */
  734. skb = orig_skb;
  735. }
  736. return skb;
  737. }
  738. /*
  739. * CFG802.11 network device handler for data transmission.
  740. */
  741. static int
  742. mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  743. {
  744. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  745. struct sk_buff *new_skb;
  746. struct mwifiex_txinfo *tx_info;
  747. bool multicast;
  748. mwifiex_dbg(priv->adapter, DATA,
  749. "data: %lu BSS(%d-%d): Data <= kernel\n",
  750. jiffies, priv->bss_type, priv->bss_num);
  751. if (priv->adapter->surprise_removed) {
  752. kfree_skb(skb);
  753. priv->stats.tx_dropped++;
  754. return 0;
  755. }
  756. if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
  757. mwifiex_dbg(priv->adapter, ERROR,
  758. "Tx: bad skb len %d\n", skb->len);
  759. kfree_skb(skb);
  760. priv->stats.tx_dropped++;
  761. return 0;
  762. }
  763. if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
  764. mwifiex_dbg(priv->adapter, DATA,
  765. "data: Tx: insufficient skb headroom %d\n",
  766. skb_headroom(skb));
  767. /* Insufficient skb headroom - allocate a new skb */
  768. new_skb =
  769. skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
  770. if (unlikely(!new_skb)) {
  771. mwifiex_dbg(priv->adapter, ERROR,
  772. "Tx: cannot alloca new_skb\n");
  773. kfree_skb(skb);
  774. priv->stats.tx_dropped++;
  775. return 0;
  776. }
  777. kfree_skb(skb);
  778. skb = new_skb;
  779. mwifiex_dbg(priv->adapter, INFO,
  780. "info: new skb headroomd %d\n",
  781. skb_headroom(skb));
  782. }
  783. tx_info = MWIFIEX_SKB_TXCB(skb);
  784. memset(tx_info, 0, sizeof(*tx_info));
  785. tx_info->bss_num = priv->bss_num;
  786. tx_info->bss_type = priv->bss_type;
  787. tx_info->pkt_len = skb->len;
  788. multicast = is_multicast_ether_addr(skb->data);
  789. if (unlikely(!multicast && skb->sk &&
  790. skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS &&
  791. priv->adapter->fw_api_ver == MWIFIEX_FW_V15))
  792. skb = mwifiex_clone_skb_for_tx_status(priv,
  793. skb,
  794. MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL);
  795. /* Record the current time the packet was queued; used to
  796. * determine the amount of time the packet was queued in
  797. * the driver before it was sent to the firmware.
  798. * The delay is then sent along with the packet to the
  799. * firmware for aggregate delay calculation for stats and
  800. * MSDU lifetime expiry.
  801. */
  802. __net_timestamp(skb);
  803. if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
  804. priv->bss_type == MWIFIEX_BSS_TYPE_STA &&
  805. !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) {
  806. if (priv->adapter->auto_tdls && priv->check_tdls_tx)
  807. mwifiex_tdls_check_tx(priv, skb);
  808. }
  809. mwifiex_queue_tx_pkt(priv, skb);
  810. return 0;
  811. }
  812. /*
  813. * CFG802.11 network device handler for setting MAC address.
  814. */
  815. static int
  816. mwifiex_set_mac_address(struct net_device *dev, void *addr)
  817. {
  818. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  819. struct sockaddr *hw_addr = addr;
  820. int ret;
  821. memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
  822. /* Send request to firmware */
  823. ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
  824. HostCmd_ACT_GEN_SET, 0, NULL, true);
  825. if (!ret)
  826. memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
  827. else
  828. mwifiex_dbg(priv->adapter, ERROR,
  829. "set mac address failed: ret=%d\n", ret);
  830. memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
  831. return ret;
  832. }
  833. /*
  834. * CFG802.11 network device handler for setting multicast list.
  835. */
  836. static void mwifiex_set_multicast_list(struct net_device *dev)
  837. {
  838. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  839. struct mwifiex_multicast_list mcast_list;
  840. if (dev->flags & IFF_PROMISC) {
  841. mcast_list.mode = MWIFIEX_PROMISC_MODE;
  842. } else if (dev->flags & IFF_ALLMULTI ||
  843. netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
  844. mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
  845. } else {
  846. mcast_list.mode = MWIFIEX_MULTICAST_MODE;
  847. mcast_list.num_multicast_addr =
  848. mwifiex_copy_mcast_addr(&mcast_list, dev);
  849. }
  850. mwifiex_request_set_multicast_list(priv, &mcast_list);
  851. }
  852. /*
  853. * CFG802.11 network device handler for transmission timeout.
  854. */
  855. static void
  856. mwifiex_tx_timeout(struct net_device *dev)
  857. {
  858. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  859. priv->num_tx_timeout++;
  860. priv->tx_timeout_cnt++;
  861. mwifiex_dbg(priv->adapter, ERROR,
  862. "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
  863. jiffies, priv->tx_timeout_cnt, priv->bss_type,
  864. priv->bss_num);
  865. mwifiex_set_trans_start(dev);
  866. if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
  867. priv->adapter->if_ops.card_reset) {
  868. mwifiex_dbg(priv->adapter, ERROR,
  869. "tx_timeout_cnt exceeds threshold.\t"
  870. "Triggering card reset!\n");
  871. priv->adapter->if_ops.card_reset(priv->adapter);
  872. }
  873. }
  874. void mwifiex_multi_chan_resync(struct mwifiex_adapter *adapter)
  875. {
  876. struct usb_card_rec *card = adapter->card;
  877. struct mwifiex_private *priv;
  878. u16 tx_buf_size;
  879. int i, ret;
  880. card->mc_resync_flag = true;
  881. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
  882. if (atomic_read(&card->port[i].tx_data_urb_pending)) {
  883. mwifiex_dbg(adapter, WARN, "pending data urb in sys\n");
  884. return;
  885. }
  886. }
  887. card->mc_resync_flag = false;
  888. tx_buf_size = 0xffff;
  889. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  890. ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
  891. HostCmd_ACT_GEN_SET, 0, &tx_buf_size, false);
  892. if (ret)
  893. mwifiex_dbg(adapter, ERROR,
  894. "send reconfig tx buf size cmd err\n");
  895. }
  896. EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync);
  897. int mwifiex_drv_info_dump(struct mwifiex_adapter *adapter, void **drv_info)
  898. {
  899. void *p;
  900. char drv_version[64];
  901. struct usb_card_rec *cardp;
  902. struct sdio_mmc_card *sdio_card;
  903. struct mwifiex_private *priv;
  904. int i, idx;
  905. struct netdev_queue *txq;
  906. struct mwifiex_debug_info *debug_info;
  907. void *drv_info_dump;
  908. mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump start===\n");
  909. /* memory allocate here should be free in mwifiex_upload_device_dump*/
  910. drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX);
  911. if (!drv_info_dump)
  912. return 0;
  913. p = (char *)(drv_info_dump);
  914. p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
  915. mwifiex_drv_get_driver_version(adapter, drv_version,
  916. sizeof(drv_version) - 1);
  917. p += sprintf(p, "driver_version = %s\n", drv_version);
  918. if (adapter->iface_type == MWIFIEX_USB) {
  919. cardp = (struct usb_card_rec *)adapter->card;
  920. p += sprintf(p, "tx_cmd_urb_pending = %d\n",
  921. atomic_read(&cardp->tx_cmd_urb_pending));
  922. p += sprintf(p, "tx_data_urb_pending_port_0 = %d\n",
  923. atomic_read(&cardp->port[0].tx_data_urb_pending));
  924. p += sprintf(p, "tx_data_urb_pending_port_1 = %d\n",
  925. atomic_read(&cardp->port[1].tx_data_urb_pending));
  926. p += sprintf(p, "rx_cmd_urb_pending = %d\n",
  927. atomic_read(&cardp->rx_cmd_urb_pending));
  928. p += sprintf(p, "rx_data_urb_pending = %d\n",
  929. atomic_read(&cardp->rx_data_urb_pending));
  930. }
  931. p += sprintf(p, "tx_pending = %d\n",
  932. atomic_read(&adapter->tx_pending));
  933. p += sprintf(p, "rx_pending = %d\n",
  934. atomic_read(&adapter->rx_pending));
  935. if (adapter->iface_type == MWIFIEX_SDIO) {
  936. sdio_card = (struct sdio_mmc_card *)adapter->card;
  937. p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
  938. sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port);
  939. p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
  940. sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port);
  941. }
  942. for (i = 0; i < adapter->priv_num; i++) {
  943. if (!adapter->priv[i] || !adapter->priv[i]->netdev)
  944. continue;
  945. priv = adapter->priv[i];
  946. p += sprintf(p, "\n[interface : \"%s\"]\n",
  947. priv->netdev->name);
  948. p += sprintf(p, "wmm_tx_pending[0] = %d\n",
  949. atomic_read(&priv->wmm_tx_pending[0]));
  950. p += sprintf(p, "wmm_tx_pending[1] = %d\n",
  951. atomic_read(&priv->wmm_tx_pending[1]));
  952. p += sprintf(p, "wmm_tx_pending[2] = %d\n",
  953. atomic_read(&priv->wmm_tx_pending[2]));
  954. p += sprintf(p, "wmm_tx_pending[3] = %d\n",
  955. atomic_read(&priv->wmm_tx_pending[3]));
  956. p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ?
  957. "Disconnected" : "Connected");
  958. p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev)
  959. ? "on" : "off"));
  960. for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) {
  961. txq = netdev_get_tx_queue(priv->netdev, idx);
  962. p += sprintf(p, "tx queue %d:%s ", idx,
  963. netif_tx_queue_stopped(txq) ?
  964. "stopped" : "started");
  965. }
  966. p += sprintf(p, "\n%s: num_tx_timeout = %d\n",
  967. priv->netdev->name, priv->num_tx_timeout);
  968. }
  969. if (adapter->iface_type == MWIFIEX_SDIO ||
  970. adapter->iface_type == MWIFIEX_PCIE) {
  971. p += sprintf(p, "\n=== %s register dump===\n",
  972. adapter->iface_type == MWIFIEX_SDIO ?
  973. "SDIO" : "PCIE");
  974. if (adapter->if_ops.reg_dump)
  975. p += adapter->if_ops.reg_dump(adapter, p);
  976. }
  977. p += sprintf(p, "\n=== more debug information\n");
  978. debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL);
  979. if (debug_info) {
  980. for (i = 0; i < adapter->priv_num; i++) {
  981. if (!adapter->priv[i] || !adapter->priv[i]->netdev)
  982. continue;
  983. priv = adapter->priv[i];
  984. mwifiex_get_debug_info(priv, debug_info);
  985. p += mwifiex_debug_info_to_buffer(priv, p, debug_info);
  986. break;
  987. }
  988. kfree(debug_info);
  989. }
  990. mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump end===\n");
  991. *drv_info = drv_info_dump;
  992. return p - drv_info_dump;
  993. }
  994. EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump);
  995. void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter, void *drv_info,
  996. int drv_info_size)
  997. {
  998. u8 idx, *dump_data, *fw_dump_ptr;
  999. u32 dump_len;
  1000. dump_len = (strlen("========Start dump driverinfo========\n") +
  1001. drv_info_size +
  1002. strlen("\n========End dump========\n"));
  1003. for (idx = 0; idx < adapter->num_mem_types; idx++) {
  1004. struct memory_type_mapping *entry =
  1005. &adapter->mem_type_mapping_tbl[idx];
  1006. if (entry->mem_ptr) {
  1007. dump_len += (strlen("========Start dump ") +
  1008. strlen(entry->mem_name) +
  1009. strlen("========\n") +
  1010. (entry->mem_size + 1) +
  1011. strlen("\n========End dump========\n"));
  1012. }
  1013. }
  1014. dump_data = vzalloc(dump_len + 1);
  1015. if (!dump_data)
  1016. goto done;
  1017. fw_dump_ptr = dump_data;
  1018. /* Dump all the memory data into single file, a userspace script will
  1019. * be used to split all the memory data to multiple files
  1020. */
  1021. mwifiex_dbg(adapter, MSG,
  1022. "== mwifiex dump information to /sys/class/devcoredump start");
  1023. strcpy(fw_dump_ptr, "========Start dump driverinfo========\n");
  1024. fw_dump_ptr += strlen("========Start dump driverinfo========\n");
  1025. memcpy(fw_dump_ptr, drv_info, drv_info_size);
  1026. fw_dump_ptr += drv_info_size;
  1027. strcpy(fw_dump_ptr, "\n========End dump========\n");
  1028. fw_dump_ptr += strlen("\n========End dump========\n");
  1029. for (idx = 0; idx < adapter->num_mem_types; idx++) {
  1030. struct memory_type_mapping *entry =
  1031. &adapter->mem_type_mapping_tbl[idx];
  1032. if (entry->mem_ptr) {
  1033. strcpy(fw_dump_ptr, "========Start dump ");
  1034. fw_dump_ptr += strlen("========Start dump ");
  1035. strcpy(fw_dump_ptr, entry->mem_name);
  1036. fw_dump_ptr += strlen(entry->mem_name);
  1037. strcpy(fw_dump_ptr, "========\n");
  1038. fw_dump_ptr += strlen("========\n");
  1039. memcpy(fw_dump_ptr, entry->mem_ptr, entry->mem_size);
  1040. fw_dump_ptr += entry->mem_size;
  1041. strcpy(fw_dump_ptr, "\n========End dump========\n");
  1042. fw_dump_ptr += strlen("\n========End dump========\n");
  1043. }
  1044. }
  1045. /* device dump data will be free in device coredump release function
  1046. * after 5 min
  1047. */
  1048. dev_coredumpv(adapter->dev, dump_data, dump_len, GFP_KERNEL);
  1049. mwifiex_dbg(adapter, MSG,
  1050. "== mwifiex dump information to /sys/class/devcoredump end");
  1051. done:
  1052. for (idx = 0; idx < adapter->num_mem_types; idx++) {
  1053. struct memory_type_mapping *entry =
  1054. &adapter->mem_type_mapping_tbl[idx];
  1055. vfree(entry->mem_ptr);
  1056. entry->mem_ptr = NULL;
  1057. entry->mem_size = 0;
  1058. }
  1059. vfree(drv_info);
  1060. }
  1061. EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump);
  1062. /*
  1063. * CFG802.11 network device handler for statistics retrieval.
  1064. */
  1065. static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
  1066. {
  1067. struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
  1068. return &priv->stats;
  1069. }
  1070. static u16
  1071. mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
  1072. void *accel_priv, select_queue_fallback_t fallback)
  1073. {
  1074. skb->priority = cfg80211_classify8021d(skb, NULL);
  1075. return mwifiex_1d_to_wmm_queue[skb->priority];
  1076. }
  1077. /* Network device handlers */
  1078. static const struct net_device_ops mwifiex_netdev_ops = {
  1079. .ndo_open = mwifiex_open,
  1080. .ndo_stop = mwifiex_close,
  1081. .ndo_start_xmit = mwifiex_hard_start_xmit,
  1082. .ndo_set_mac_address = mwifiex_set_mac_address,
  1083. .ndo_validate_addr = eth_validate_addr,
  1084. .ndo_tx_timeout = mwifiex_tx_timeout,
  1085. .ndo_get_stats = mwifiex_get_stats,
  1086. .ndo_set_rx_mode = mwifiex_set_multicast_list,
  1087. .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
  1088. };
  1089. /*
  1090. * This function initializes the private structure parameters.
  1091. *
  1092. * The following wait queues are initialized -
  1093. * - IOCTL wait queue
  1094. * - Command wait queue
  1095. * - Statistics wait queue
  1096. *
  1097. * ...and the following default parameters are set -
  1098. * - Current key index : Set to 0
  1099. * - Rate index : Set to auto
  1100. * - Media connected : Set to disconnected
  1101. * - Adhoc link sensed : Set to false
  1102. * - Nick name : Set to null
  1103. * - Number of Tx timeout : Set to 0
  1104. * - Device address : Set to current address
  1105. * - Rx histogram statistc : Set to 0
  1106. *
  1107. * In addition, the CFG80211 work queue is also created.
  1108. */
  1109. void mwifiex_init_priv_params(struct mwifiex_private *priv,
  1110. struct net_device *dev)
  1111. {
  1112. dev->netdev_ops = &mwifiex_netdev_ops;
  1113. dev->destructor = free_netdev;
  1114. /* Initialize private structure */
  1115. priv->current_key_index = 0;
  1116. priv->media_connected = false;
  1117. memset(priv->mgmt_ie, 0,
  1118. sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
  1119. priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
  1120. priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
  1121. priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
  1122. priv->gen_idx = MWIFIEX_AUTO_IDX_MASK;
  1123. priv->num_tx_timeout = 0;
  1124. ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr);
  1125. memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
  1126. if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
  1127. GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
  1128. priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL);
  1129. if (priv->hist_data)
  1130. mwifiex_hist_data_reset(priv);
  1131. }
  1132. }
  1133. /*
  1134. * This function check if command is pending.
  1135. */
  1136. int is_command_pending(struct mwifiex_adapter *adapter)
  1137. {
  1138. unsigned long flags;
  1139. int is_cmd_pend_q_empty;
  1140. spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
  1141. is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
  1142. spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
  1143. return !is_cmd_pend_q_empty;
  1144. }
  1145. /*
  1146. * This is the RX work queue function.
  1147. *
  1148. * It handles the RX operations.
  1149. */
  1150. static void mwifiex_rx_work_queue(struct work_struct *work)
  1151. {
  1152. struct mwifiex_adapter *adapter =
  1153. container_of(work, struct mwifiex_adapter, rx_work);
  1154. if (adapter->surprise_removed)
  1155. return;
  1156. mwifiex_process_rx(adapter);
  1157. }
  1158. /*
  1159. * This is the main work queue function.
  1160. *
  1161. * It handles the main process, which in turn handles the complete
  1162. * driver operations.
  1163. */
  1164. static void mwifiex_main_work_queue(struct work_struct *work)
  1165. {
  1166. struct mwifiex_adapter *adapter =
  1167. container_of(work, struct mwifiex_adapter, main_work);
  1168. if (adapter->surprise_removed)
  1169. return;
  1170. mwifiex_main_process(adapter);
  1171. }
  1172. /*
  1173. * This function gets called during PCIe function level reset. Required
  1174. * code is extracted from mwifiex_remove_card()
  1175. */
  1176. int
  1177. mwifiex_shutdown_sw(struct mwifiex_adapter *adapter)
  1178. {
  1179. struct mwifiex_private *priv;
  1180. int i;
  1181. if (!adapter)
  1182. goto exit_return;
  1183. wait_for_completion(adapter->fw_done);
  1184. /* Caller should ensure we aren't suspending while this happens */
  1185. reinit_completion(adapter->fw_done);
  1186. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  1187. mwifiex_deauthenticate(priv, NULL);
  1188. /* We can no longer handle interrupts once we start doing the teardown
  1189. * below.
  1190. */
  1191. if (adapter->if_ops.disable_int)
  1192. adapter->if_ops.disable_int(adapter);
  1193. adapter->surprise_removed = true;
  1194. mwifiex_terminate_workqueue(adapter);
  1195. /* Stop data */
  1196. for (i = 0; i < adapter->priv_num; i++) {
  1197. priv = adapter->priv[i];
  1198. if (priv && priv->netdev) {
  1199. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  1200. if (netif_carrier_ok(priv->netdev))
  1201. netif_carrier_off(priv->netdev);
  1202. netif_device_detach(priv->netdev);
  1203. }
  1204. }
  1205. mwifiex_dbg(adapter, CMD, "cmd: calling mwifiex_shutdown_drv...\n");
  1206. mwifiex_shutdown_drv(adapter);
  1207. if (adapter->if_ops.down_dev)
  1208. adapter->if_ops.down_dev(adapter);
  1209. mwifiex_dbg(adapter, CMD, "cmd: mwifiex_shutdown_drv done\n");
  1210. if (atomic_read(&adapter->rx_pending) ||
  1211. atomic_read(&adapter->tx_pending) ||
  1212. atomic_read(&adapter->cmd_pending)) {
  1213. mwifiex_dbg(adapter, ERROR,
  1214. "rx_pending=%d, tx_pending=%d,\t"
  1215. "cmd_pending=%d\n",
  1216. atomic_read(&adapter->rx_pending),
  1217. atomic_read(&adapter->tx_pending),
  1218. atomic_read(&adapter->cmd_pending));
  1219. }
  1220. for (i = 0; i < adapter->priv_num; i++) {
  1221. priv = adapter->priv[i];
  1222. if (!priv)
  1223. continue;
  1224. rtnl_lock();
  1225. if (priv->netdev &&
  1226. priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
  1227. mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
  1228. rtnl_unlock();
  1229. }
  1230. vfree(adapter->chan_stats);
  1231. mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
  1232. exit_return:
  1233. return 0;
  1234. }
  1235. EXPORT_SYMBOL_GPL(mwifiex_shutdown_sw);
  1236. /* This function gets called during PCIe function level reset. Required
  1237. * code is extracted from mwifiex_add_card()
  1238. */
  1239. int
  1240. mwifiex_reinit_sw(struct mwifiex_adapter *adapter)
  1241. {
  1242. int ret;
  1243. mwifiex_init_lock_list(adapter);
  1244. if (adapter->if_ops.up_dev)
  1245. adapter->if_ops.up_dev(adapter);
  1246. adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
  1247. adapter->surprise_removed = false;
  1248. init_waitqueue_head(&adapter->init_wait_q);
  1249. adapter->is_suspended = false;
  1250. adapter->hs_activated = false;
  1251. adapter->is_cmd_timedout = 0;
  1252. init_waitqueue_head(&adapter->hs_activate_wait_q);
  1253. init_waitqueue_head(&adapter->cmd_wait_q.wait);
  1254. adapter->cmd_wait_q.status = 0;
  1255. adapter->scan_wait_q_woken = false;
  1256. if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB)
  1257. adapter->rx_work_enabled = true;
  1258. adapter->workqueue =
  1259. alloc_workqueue("MWIFIEX_WORK_QUEUE",
  1260. WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
  1261. if (!adapter->workqueue)
  1262. goto err_kmalloc;
  1263. INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
  1264. if (adapter->rx_work_enabled) {
  1265. adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
  1266. WQ_HIGHPRI |
  1267. WQ_MEM_RECLAIM |
  1268. WQ_UNBOUND, 1);
  1269. if (!adapter->rx_workqueue)
  1270. goto err_kmalloc;
  1271. INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
  1272. }
  1273. /* Register the device. Fill up the private data structure with
  1274. * relevant information from the card. Some code extracted from
  1275. * mwifiex_register_dev()
  1276. */
  1277. mwifiex_dbg(adapter, INFO, "%s, mwifiex_init_hw_fw()...\n", __func__);
  1278. if (mwifiex_init_hw_fw(adapter, false)) {
  1279. mwifiex_dbg(adapter, ERROR,
  1280. "%s: firmware init failed\n", __func__);
  1281. goto err_init_fw;
  1282. }
  1283. /* _mwifiex_fw_dpc() does its own cleanup */
  1284. ret = _mwifiex_fw_dpc(adapter->firmware, adapter);
  1285. if (ret) {
  1286. pr_err("Failed to bring up adapter: %d\n", ret);
  1287. return ret;
  1288. }
  1289. mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
  1290. return 0;
  1291. err_init_fw:
  1292. mwifiex_dbg(adapter, ERROR, "info: %s: unregister device\n", __func__);
  1293. if (adapter->if_ops.unregister_dev)
  1294. adapter->if_ops.unregister_dev(adapter);
  1295. err_kmalloc:
  1296. adapter->surprise_removed = true;
  1297. mwifiex_terminate_workqueue(adapter);
  1298. if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
  1299. mwifiex_dbg(adapter, ERROR,
  1300. "info: %s: shutdown mwifiex\n", __func__);
  1301. mwifiex_shutdown_drv(adapter);
  1302. }
  1303. complete_all(adapter->fw_done);
  1304. mwifiex_dbg(adapter, INFO, "%s, error\n", __func__);
  1305. return -1;
  1306. }
  1307. EXPORT_SYMBOL_GPL(mwifiex_reinit_sw);
  1308. static irqreturn_t mwifiex_irq_wakeup_handler(int irq, void *priv)
  1309. {
  1310. struct mwifiex_adapter *adapter = priv;
  1311. dev_dbg(adapter->dev, "%s: wake by wifi", __func__);
  1312. adapter->wake_by_wifi = true;
  1313. disable_irq_nosync(irq);
  1314. /* Notify PM core we are wakeup source */
  1315. pm_wakeup_event(adapter->dev, 0);
  1316. pm_system_wakeup();
  1317. return IRQ_HANDLED;
  1318. }
  1319. static void mwifiex_probe_of(struct mwifiex_adapter *adapter)
  1320. {
  1321. int ret;
  1322. struct device *dev = adapter->dev;
  1323. if (!dev->of_node)
  1324. goto err_exit;
  1325. adapter->dt_node = dev->of_node;
  1326. adapter->irq_wakeup = irq_of_parse_and_map(adapter->dt_node, 0);
  1327. if (!adapter->irq_wakeup) {
  1328. dev_dbg(dev, "fail to parse irq_wakeup from device tree\n");
  1329. goto err_exit;
  1330. }
  1331. ret = devm_request_irq(dev, adapter->irq_wakeup,
  1332. mwifiex_irq_wakeup_handler, IRQF_TRIGGER_LOW,
  1333. "wifi_wake", adapter);
  1334. if (ret) {
  1335. dev_err(dev, "Failed to request irq_wakeup %d (%d)\n",
  1336. adapter->irq_wakeup, ret);
  1337. goto err_exit;
  1338. }
  1339. disable_irq(adapter->irq_wakeup);
  1340. if (device_init_wakeup(dev, true)) {
  1341. dev_err(dev, "fail to init wakeup for mwifiex\n");
  1342. goto err_exit;
  1343. }
  1344. return;
  1345. err_exit:
  1346. adapter->irq_wakeup = -1;
  1347. }
  1348. /*
  1349. * This function adds the card.
  1350. *
  1351. * This function follows the following major steps to set up the device -
  1352. * - Initialize software. This includes probing the card, registering
  1353. * the interface operations table, and allocating/initializing the
  1354. * adapter structure
  1355. * - Set up the netlink socket
  1356. * - Create and start the main work queue
  1357. * - Register the device
  1358. * - Initialize firmware and hardware
  1359. * - Add logical interfaces
  1360. */
  1361. int
  1362. mwifiex_add_card(void *card, struct completion *fw_done,
  1363. struct mwifiex_if_ops *if_ops, u8 iface_type,
  1364. struct device *dev)
  1365. {
  1366. struct mwifiex_adapter *adapter;
  1367. if (mwifiex_register(card, dev, if_ops, (void **)&adapter)) {
  1368. pr_err("%s: software init failed\n", __func__);
  1369. goto err_init_sw;
  1370. }
  1371. mwifiex_probe_of(adapter);
  1372. adapter->iface_type = iface_type;
  1373. adapter->fw_done = fw_done;
  1374. adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
  1375. adapter->surprise_removed = false;
  1376. init_waitqueue_head(&adapter->init_wait_q);
  1377. adapter->is_suspended = false;
  1378. adapter->hs_activated = false;
  1379. init_waitqueue_head(&adapter->hs_activate_wait_q);
  1380. init_waitqueue_head(&adapter->cmd_wait_q.wait);
  1381. adapter->cmd_wait_q.status = 0;
  1382. adapter->scan_wait_q_woken = false;
  1383. if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) {
  1384. adapter->rx_work_enabled = true;
  1385. pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
  1386. }
  1387. adapter->workqueue =
  1388. alloc_workqueue("MWIFIEX_WORK_QUEUE",
  1389. WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
  1390. if (!adapter->workqueue)
  1391. goto err_kmalloc;
  1392. INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
  1393. if (adapter->rx_work_enabled) {
  1394. adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
  1395. WQ_HIGHPRI |
  1396. WQ_MEM_RECLAIM |
  1397. WQ_UNBOUND, 1);
  1398. if (!adapter->rx_workqueue)
  1399. goto err_kmalloc;
  1400. INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
  1401. }
  1402. /* Register the device. Fill up the private data structure with relevant
  1403. information from the card. */
  1404. if (adapter->if_ops.register_dev(adapter)) {
  1405. pr_err("%s: failed to register mwifiex device\n", __func__);
  1406. goto err_registerdev;
  1407. }
  1408. if (mwifiex_init_hw_fw(adapter, true)) {
  1409. pr_err("%s: firmware init failed\n", __func__);
  1410. goto err_init_fw;
  1411. }
  1412. return 0;
  1413. err_init_fw:
  1414. pr_debug("info: %s: unregister device\n", __func__);
  1415. if (adapter->if_ops.unregister_dev)
  1416. adapter->if_ops.unregister_dev(adapter);
  1417. err_registerdev:
  1418. adapter->surprise_removed = true;
  1419. mwifiex_terminate_workqueue(adapter);
  1420. if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
  1421. pr_debug("info: %s: shutdown mwifiex\n", __func__);
  1422. mwifiex_shutdown_drv(adapter);
  1423. }
  1424. err_kmalloc:
  1425. mwifiex_free_adapter(adapter);
  1426. err_init_sw:
  1427. return -1;
  1428. }
  1429. EXPORT_SYMBOL_GPL(mwifiex_add_card);
  1430. /*
  1431. * This function removes the card.
  1432. *
  1433. * This function follows the following major steps to remove the device -
  1434. * - Stop data traffic
  1435. * - Shutdown firmware
  1436. * - Remove the logical interfaces
  1437. * - Terminate the work queue
  1438. * - Unregister the device
  1439. * - Free the adapter structure
  1440. */
  1441. int mwifiex_remove_card(struct mwifiex_adapter *adapter)
  1442. {
  1443. struct mwifiex_private *priv = NULL;
  1444. int i;
  1445. if (!adapter)
  1446. goto exit_remove;
  1447. /* We can no longer handle interrupts once we start doing the teardown
  1448. * below. */
  1449. if (adapter->if_ops.disable_int)
  1450. adapter->if_ops.disable_int(adapter);
  1451. adapter->surprise_removed = true;
  1452. mwifiex_terminate_workqueue(adapter);
  1453. /* Stop data */
  1454. for (i = 0; i < adapter->priv_num; i++) {
  1455. priv = adapter->priv[i];
  1456. if (priv && priv->netdev) {
  1457. mwifiex_stop_net_dev_queue(priv->netdev, adapter);
  1458. if (netif_carrier_ok(priv->netdev))
  1459. netif_carrier_off(priv->netdev);
  1460. }
  1461. }
  1462. mwifiex_dbg(adapter, CMD,
  1463. "cmd: calling mwifiex_shutdown_drv...\n");
  1464. mwifiex_shutdown_drv(adapter);
  1465. mwifiex_dbg(adapter, CMD,
  1466. "cmd: mwifiex_shutdown_drv done\n");
  1467. if (atomic_read(&adapter->rx_pending) ||
  1468. atomic_read(&adapter->tx_pending) ||
  1469. atomic_read(&adapter->cmd_pending)) {
  1470. mwifiex_dbg(adapter, ERROR,
  1471. "rx_pending=%d, tx_pending=%d,\t"
  1472. "cmd_pending=%d\n",
  1473. atomic_read(&adapter->rx_pending),
  1474. atomic_read(&adapter->tx_pending),
  1475. atomic_read(&adapter->cmd_pending));
  1476. }
  1477. for (i = 0; i < adapter->priv_num; i++) {
  1478. priv = adapter->priv[i];
  1479. if (!priv)
  1480. continue;
  1481. rtnl_lock();
  1482. if (priv->netdev &&
  1483. priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
  1484. mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
  1485. rtnl_unlock();
  1486. }
  1487. vfree(adapter->chan_stats);
  1488. wiphy_unregister(adapter->wiphy);
  1489. wiphy_free(adapter->wiphy);
  1490. if (adapter->irq_wakeup >= 0)
  1491. device_init_wakeup(adapter->dev, false);
  1492. /* Unregister device */
  1493. mwifiex_dbg(adapter, INFO,
  1494. "info: unregister device\n");
  1495. if (adapter->if_ops.unregister_dev)
  1496. adapter->if_ops.unregister_dev(adapter);
  1497. /* Free adapter structure */
  1498. mwifiex_dbg(adapter, INFO,
  1499. "info: free adapter\n");
  1500. mwifiex_free_adapter(adapter);
  1501. exit_remove:
  1502. return 0;
  1503. }
  1504. EXPORT_SYMBOL_GPL(mwifiex_remove_card);
  1505. void _mwifiex_dbg(const struct mwifiex_adapter *adapter, int mask,
  1506. const char *fmt, ...)
  1507. {
  1508. struct va_format vaf;
  1509. va_list args;
  1510. if (!(adapter->debug_mask & mask))
  1511. return;
  1512. va_start(args, fmt);
  1513. vaf.fmt = fmt;
  1514. vaf.va = &args;
  1515. if (adapter->dev)
  1516. dev_info(adapter->dev, "%pV", &vaf);
  1517. else
  1518. pr_info("%pV", &vaf);
  1519. va_end(args);
  1520. }
  1521. EXPORT_SYMBOL_GPL(_mwifiex_dbg);
  1522. /*
  1523. * This function initializes the module.
  1524. *
  1525. * The debug FS is also initialized if configured.
  1526. */
  1527. static int
  1528. mwifiex_init_module(void)
  1529. {
  1530. #ifdef CONFIG_DEBUG_FS
  1531. mwifiex_debugfs_init();
  1532. #endif
  1533. return 0;
  1534. }
  1535. /*
  1536. * This function cleans up the module.
  1537. *
  1538. * The debug FS is removed if available.
  1539. */
  1540. static void
  1541. mwifiex_cleanup_module(void)
  1542. {
  1543. #ifdef CONFIG_DEBUG_FS
  1544. mwifiex_debugfs_remove();
  1545. #endif
  1546. }
  1547. module_init(mwifiex_init_module);
  1548. module_exit(mwifiex_cleanup_module);
  1549. MODULE_AUTHOR("Marvell International Ltd.");
  1550. MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
  1551. MODULE_VERSION(VERSION);
  1552. MODULE_LICENSE("GPL v2");