main.c 49 KB

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