rx.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  1. /*
  2. * Intel Wireless Multicomm 3200 WiFi driver
  3. *
  4. * Copyright (C) 2009 Intel Corporation. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Intel Corporation nor the names of its
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. *
  33. * Intel Corporation <ilw@linux.intel.com>
  34. * Samuel Ortiz <samuel.ortiz@intel.com>
  35. * Zhu Yi <yi.zhu@intel.com>
  36. *
  37. */
  38. #include <linux/kernel.h>
  39. #include <linux/netdevice.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/wireless.h>
  42. #include <linux/ieee80211.h>
  43. #include <linux/if_arp.h>
  44. #include <linux/list.h>
  45. #include <net/iw_handler.h>
  46. #include "iwm.h"
  47. #include "debug.h"
  48. #include "hal.h"
  49. #include "umac.h"
  50. #include "lmac.h"
  51. #include "commands.h"
  52. #include "rx.h"
  53. #include "cfg80211.h"
  54. #include "eeprom.h"
  55. static int iwm_rx_check_udma_hdr(struct iwm_udma_in_hdr *hdr)
  56. {
  57. if ((le32_to_cpu(hdr->cmd) == UMAC_PAD_TERMINAL) ||
  58. (le32_to_cpu(hdr->size) == UMAC_PAD_TERMINAL))
  59. return -EINVAL;
  60. return 0;
  61. }
  62. static inline int iwm_rx_resp_size(struct iwm_udma_in_hdr *hdr)
  63. {
  64. return ALIGN(le32_to_cpu(hdr->size) + sizeof(struct iwm_udma_in_hdr),
  65. 16);
  66. }
  67. /*
  68. * Notification handlers:
  69. *
  70. * For every possible notification we can receive from the
  71. * target, we have a handler.
  72. * When we get a target notification, and there is no one
  73. * waiting for it, it's just processed through the rx code
  74. * path:
  75. *
  76. * iwm_rx_handle()
  77. * -> iwm_rx_handle_umac()
  78. * -> iwm_rx_handle_wifi()
  79. * -> iwm_rx_handle_resp()
  80. * -> iwm_ntf_*()
  81. *
  82. * OR
  83. *
  84. * -> iwm_rx_handle_non_wifi()
  85. *
  86. * If there are processes waiting for this notification, then
  87. * iwm_rx_handle_wifi() just wakes those processes up and they
  88. * grab the pending notification.
  89. */
  90. static int iwm_ntf_error(struct iwm_priv *iwm, u8 *buf,
  91. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  92. {
  93. struct iwm_umac_notif_error *error;
  94. struct iwm_fw_error_hdr *fw_err;
  95. error = (struct iwm_umac_notif_error *)buf;
  96. fw_err = &error->err;
  97. memcpy(iwm->last_fw_err, fw_err, sizeof(struct iwm_fw_error_hdr));
  98. IWM_ERR(iwm, "%cMAC FW ERROR:\n",
  99. (le32_to_cpu(fw_err->category) == UMAC_SYS_ERR_CAT_LMAC) ? 'L' : 'U');
  100. IWM_ERR(iwm, "\tCategory: %d\n", le32_to_cpu(fw_err->category));
  101. IWM_ERR(iwm, "\tStatus: 0x%x\n", le32_to_cpu(fw_err->status));
  102. IWM_ERR(iwm, "\tPC: 0x%x\n", le32_to_cpu(fw_err->pc));
  103. IWM_ERR(iwm, "\tblink1: %d\n", le32_to_cpu(fw_err->blink1));
  104. IWM_ERR(iwm, "\tblink2: %d\n", le32_to_cpu(fw_err->blink2));
  105. IWM_ERR(iwm, "\tilink1: %d\n", le32_to_cpu(fw_err->ilink1));
  106. IWM_ERR(iwm, "\tilink2: %d\n", le32_to_cpu(fw_err->ilink2));
  107. IWM_ERR(iwm, "\tData1: 0x%x\n", le32_to_cpu(fw_err->data1));
  108. IWM_ERR(iwm, "\tData2: 0x%x\n", le32_to_cpu(fw_err->data2));
  109. IWM_ERR(iwm, "\tLine number: %d\n", le32_to_cpu(fw_err->line_num));
  110. IWM_ERR(iwm, "\tUMAC status: 0x%x\n", le32_to_cpu(fw_err->umac_status));
  111. IWM_ERR(iwm, "\tLMAC status: 0x%x\n", le32_to_cpu(fw_err->lmac_status));
  112. IWM_ERR(iwm, "\tSDIO status: 0x%x\n", le32_to_cpu(fw_err->sdio_status));
  113. iwm_resetting(iwm);
  114. return 0;
  115. }
  116. static int iwm_ntf_umac_alive(struct iwm_priv *iwm, u8 *buf,
  117. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  118. {
  119. struct iwm_umac_notif_alive *alive_resp =
  120. (struct iwm_umac_notif_alive *)(buf);
  121. u16 status = le16_to_cpu(alive_resp->status);
  122. if (status == UMAC_NTFY_ALIVE_STATUS_ERR) {
  123. IWM_ERR(iwm, "Receive error UMAC_ALIVE\n");
  124. return -EIO;
  125. }
  126. iwm_tx_credit_init_pools(iwm, alive_resp);
  127. return 0;
  128. }
  129. static int iwm_ntf_init_complete(struct iwm_priv *iwm, u8 *buf,
  130. unsigned long buf_size,
  131. struct iwm_wifi_cmd *cmd)
  132. {
  133. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  134. struct iwm_umac_notif_init_complete *init_complete =
  135. (struct iwm_umac_notif_init_complete *)(buf);
  136. u16 status = le16_to_cpu(init_complete->status);
  137. bool blocked = (status == UMAC_NTFY_INIT_COMPLETE_STATUS_ERR);
  138. if (blocked)
  139. IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is on (radio off)\n");
  140. else
  141. IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is off (radio on)\n");
  142. wiphy_rfkill_set_hw_state(wiphy, blocked);
  143. return 0;
  144. }
  145. static int iwm_ntf_tx_credit_update(struct iwm_priv *iwm, u8 *buf,
  146. unsigned long buf_size,
  147. struct iwm_wifi_cmd *cmd)
  148. {
  149. int pool_nr, total_freed_pages;
  150. unsigned long pool_map;
  151. int i, id;
  152. struct iwm_umac_notif_page_dealloc *dealloc =
  153. (struct iwm_umac_notif_page_dealloc *)buf;
  154. pool_nr = GET_VAL32(dealloc->changes, UMAC_DEALLOC_NTFY_CHANGES_CNT);
  155. pool_map = GET_VAL32(dealloc->changes, UMAC_DEALLOC_NTFY_CHANGES_MSK);
  156. IWM_DBG_TX(iwm, DBG, "UMAC dealloc notification: pool nr %d, "
  157. "update map 0x%lx\n", pool_nr, pool_map);
  158. spin_lock(&iwm->tx_credit.lock);
  159. for (i = 0; i < pool_nr; i++) {
  160. id = GET_VAL32(dealloc->grp_info[i],
  161. UMAC_DEALLOC_NTFY_GROUP_NUM);
  162. if (test_bit(id, &pool_map)) {
  163. total_freed_pages = GET_VAL32(dealloc->grp_info[i],
  164. UMAC_DEALLOC_NTFY_PAGE_CNT);
  165. iwm_tx_credit_inc(iwm, id, total_freed_pages);
  166. }
  167. }
  168. spin_unlock(&iwm->tx_credit.lock);
  169. return 0;
  170. }
  171. static int iwm_ntf_umac_reset(struct iwm_priv *iwm, u8 *buf,
  172. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  173. {
  174. IWM_DBG_NTF(iwm, DBG, "UMAC RESET done\n");
  175. return 0;
  176. }
  177. static int iwm_ntf_lmac_version(struct iwm_priv *iwm, u8 *buf,
  178. unsigned long buf_size,
  179. struct iwm_wifi_cmd *cmd)
  180. {
  181. IWM_DBG_NTF(iwm, INFO, "LMAC Version: %x.%x\n", buf[9], buf[8]);
  182. return 0;
  183. }
  184. static int iwm_ntf_tx(struct iwm_priv *iwm, u8 *buf,
  185. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  186. {
  187. struct iwm_lmac_tx_resp *tx_resp;
  188. struct iwm_umac_wifi_in_hdr *hdr;
  189. tx_resp = (struct iwm_lmac_tx_resp *)
  190. (buf + sizeof(struct iwm_umac_wifi_in_hdr));
  191. hdr = (struct iwm_umac_wifi_in_hdr *)buf;
  192. IWM_DBG_TX(iwm, DBG, "REPLY_TX, buf size: %lu\n", buf_size);
  193. IWM_DBG_TX(iwm, DBG, "Seqnum: %d\n",
  194. le16_to_cpu(hdr->sw_hdr.cmd.seq_num));
  195. IWM_DBG_TX(iwm, DBG, "\tFrame cnt: %d\n", tx_resp->frame_cnt);
  196. IWM_DBG_TX(iwm, DBG, "\tRetry cnt: %d\n",
  197. le16_to_cpu(tx_resp->retry_cnt));
  198. IWM_DBG_TX(iwm, DBG, "\tSeq ctl: %d\n", le16_to_cpu(tx_resp->seq_ctl));
  199. IWM_DBG_TX(iwm, DBG, "\tByte cnt: %d\n",
  200. le16_to_cpu(tx_resp->byte_cnt));
  201. IWM_DBG_TX(iwm, DBG, "\tStatus: 0x%x\n", le32_to_cpu(tx_resp->status));
  202. return 0;
  203. }
  204. static int iwm_ntf_calib_res(struct iwm_priv *iwm, u8 *buf,
  205. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  206. {
  207. u8 opcode;
  208. u8 *calib_buf;
  209. struct iwm_lmac_calib_hdr *hdr = (struct iwm_lmac_calib_hdr *)
  210. (buf + sizeof(struct iwm_umac_wifi_in_hdr));
  211. opcode = hdr->opcode;
  212. BUG_ON(opcode >= CALIBRATION_CMD_NUM ||
  213. opcode < PHY_CALIBRATE_OPCODES_NUM);
  214. IWM_DBG_NTF(iwm, DBG, "Store calibration result for opcode: %d\n",
  215. opcode);
  216. buf_size -= sizeof(struct iwm_umac_wifi_in_hdr);
  217. calib_buf = iwm->calib_res[opcode].buf;
  218. if (!calib_buf || (iwm->calib_res[opcode].size < buf_size)) {
  219. kfree(calib_buf);
  220. calib_buf = kzalloc(buf_size, GFP_KERNEL);
  221. if (!calib_buf) {
  222. IWM_ERR(iwm, "Memory allocation failed: calib_res\n");
  223. return -ENOMEM;
  224. }
  225. iwm->calib_res[opcode].buf = calib_buf;
  226. iwm->calib_res[opcode].size = buf_size;
  227. }
  228. memcpy(calib_buf, hdr, buf_size);
  229. set_bit(opcode - PHY_CALIBRATE_OPCODES_NUM, &iwm->calib_done_map);
  230. return 0;
  231. }
  232. static int iwm_ntf_calib_complete(struct iwm_priv *iwm, u8 *buf,
  233. unsigned long buf_size,
  234. struct iwm_wifi_cmd *cmd)
  235. {
  236. IWM_DBG_NTF(iwm, DBG, "Calibration completed\n");
  237. return 0;
  238. }
  239. static int iwm_ntf_calib_cfg(struct iwm_priv *iwm, u8 *buf,
  240. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  241. {
  242. struct iwm_lmac_cal_cfg_resp *cal_resp;
  243. cal_resp = (struct iwm_lmac_cal_cfg_resp *)
  244. (buf + sizeof(struct iwm_umac_wifi_in_hdr));
  245. IWM_DBG_NTF(iwm, DBG, "Calibration CFG command status: %d\n",
  246. le32_to_cpu(cal_resp->status));
  247. return 0;
  248. }
  249. static int iwm_ntf_wifi_status(struct iwm_priv *iwm, u8 *buf,
  250. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  251. {
  252. struct iwm_umac_notif_wifi_status *status =
  253. (struct iwm_umac_notif_wifi_status *)buf;
  254. iwm->core_enabled |= le16_to_cpu(status->status);
  255. return 0;
  256. }
  257. static struct iwm_rx_ticket_node *
  258. iwm_rx_ticket_node_alloc(struct iwm_priv *iwm, struct iwm_rx_ticket *ticket)
  259. {
  260. struct iwm_rx_ticket_node *ticket_node;
  261. ticket_node = kzalloc(sizeof(struct iwm_rx_ticket_node), GFP_KERNEL);
  262. if (!ticket_node) {
  263. IWM_ERR(iwm, "Couldn't allocate ticket node\n");
  264. return ERR_PTR(-ENOMEM);
  265. }
  266. ticket_node->ticket = kzalloc(sizeof(struct iwm_rx_ticket), GFP_KERNEL);
  267. if (!ticket_node->ticket) {
  268. IWM_ERR(iwm, "Couldn't allocate RX ticket\n");
  269. kfree(ticket_node);
  270. return ERR_PTR(-ENOMEM);
  271. }
  272. memcpy(ticket_node->ticket, ticket, sizeof(struct iwm_rx_ticket));
  273. INIT_LIST_HEAD(&ticket_node->node);
  274. return ticket_node;
  275. }
  276. static void iwm_rx_ticket_node_free(struct iwm_rx_ticket_node *ticket_node)
  277. {
  278. kfree(ticket_node->ticket);
  279. kfree(ticket_node);
  280. }
  281. static struct iwm_rx_packet *iwm_rx_packet_get(struct iwm_priv *iwm, u16 id)
  282. {
  283. u8 id_hash = IWM_RX_ID_GET_HASH(id);
  284. struct list_head *packet_list;
  285. struct iwm_rx_packet *packet, *next;
  286. packet_list = &iwm->rx_packets[id_hash];
  287. list_for_each_entry_safe(packet, next, packet_list, node)
  288. if (packet->id == id)
  289. return packet;
  290. return NULL;
  291. }
  292. static struct iwm_rx_packet *iwm_rx_packet_alloc(struct iwm_priv *iwm, u8 *buf,
  293. u32 size, u16 id)
  294. {
  295. struct iwm_rx_packet *packet;
  296. packet = kzalloc(sizeof(struct iwm_rx_packet), GFP_KERNEL);
  297. if (!packet) {
  298. IWM_ERR(iwm, "Couldn't allocate packet\n");
  299. return ERR_PTR(-ENOMEM);
  300. }
  301. packet->skb = dev_alloc_skb(size);
  302. if (!packet->skb) {
  303. IWM_ERR(iwm, "Couldn't allocate packet SKB\n");
  304. kfree(packet);
  305. return ERR_PTR(-ENOMEM);
  306. }
  307. packet->pkt_size = size;
  308. skb_put(packet->skb, size);
  309. memcpy(packet->skb->data, buf, size);
  310. INIT_LIST_HEAD(&packet->node);
  311. packet->id = id;
  312. return packet;
  313. }
  314. void iwm_rx_free(struct iwm_priv *iwm)
  315. {
  316. struct iwm_rx_ticket_node *ticket, *nt;
  317. struct iwm_rx_packet *packet, *np;
  318. int i;
  319. list_for_each_entry_safe(ticket, nt, &iwm->rx_tickets, node) {
  320. list_del(&ticket->node);
  321. iwm_rx_ticket_node_free(ticket);
  322. }
  323. for (i = 0; i < IWM_RX_ID_HASH; i++) {
  324. list_for_each_entry_safe(packet, np, &iwm->rx_packets[i],
  325. node) {
  326. list_del(&packet->node);
  327. kfree_skb(packet->skb);
  328. kfree(packet);
  329. }
  330. }
  331. }
  332. static int iwm_ntf_rx_ticket(struct iwm_priv *iwm, u8 *buf,
  333. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  334. {
  335. struct iwm_umac_notif_rx_ticket *ntf_rx_ticket =
  336. (struct iwm_umac_notif_rx_ticket *)buf;
  337. struct iwm_rx_ticket *ticket =
  338. (struct iwm_rx_ticket *)ntf_rx_ticket->tickets;
  339. int i, schedule_rx = 0;
  340. for (i = 0; i < ntf_rx_ticket->num_tickets; i++) {
  341. struct iwm_rx_ticket_node *ticket_node;
  342. switch (le16_to_cpu(ticket->action)) {
  343. case IWM_RX_TICKET_RELEASE:
  344. case IWM_RX_TICKET_DROP:
  345. /* We can push the packet to the stack */
  346. ticket_node = iwm_rx_ticket_node_alloc(iwm, ticket);
  347. if (IS_ERR(ticket_node))
  348. return PTR_ERR(ticket_node);
  349. IWM_DBG_RX(iwm, DBG, "TICKET %s(%d)\n",
  350. ticket->action == IWM_RX_TICKET_RELEASE ?
  351. "RELEASE" : "DROP",
  352. ticket->id);
  353. list_add_tail(&ticket_node->node, &iwm->rx_tickets);
  354. /*
  355. * We received an Rx ticket, most likely there's
  356. * a packet pending for it, it's not worth going
  357. * through the packet hash list to double check.
  358. * Let's just fire the rx worker..
  359. */
  360. schedule_rx = 1;
  361. break;
  362. default:
  363. IWM_ERR(iwm, "Invalid RX ticket action: 0x%x\n",
  364. ticket->action);
  365. }
  366. ticket++;
  367. }
  368. if (schedule_rx)
  369. queue_work(iwm->rx_wq, &iwm->rx_worker);
  370. return 0;
  371. }
  372. static int iwm_ntf_rx_packet(struct iwm_priv *iwm, u8 *buf,
  373. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  374. {
  375. struct iwm_umac_wifi_in_hdr *wifi_hdr;
  376. struct iwm_rx_packet *packet;
  377. u16 id, buf_offset;
  378. u32 packet_size;
  379. IWM_DBG_RX(iwm, DBG, "\n");
  380. wifi_hdr = (struct iwm_umac_wifi_in_hdr *)buf;
  381. id = le16_to_cpu(wifi_hdr->sw_hdr.cmd.seq_num);
  382. buf_offset = sizeof(struct iwm_umac_wifi_in_hdr);
  383. packet_size = buf_size - sizeof(struct iwm_umac_wifi_in_hdr);
  384. IWM_DBG_RX(iwm, DBG, "CMD:0x%x, seqnum: %d, packet size: %d\n",
  385. wifi_hdr->sw_hdr.cmd.cmd, id, packet_size);
  386. IWM_DBG_RX(iwm, DBG, "Packet id: %d\n", id);
  387. IWM_HEXDUMP(iwm, DBG, RX, "PACKET: ", buf + buf_offset, packet_size);
  388. packet = iwm_rx_packet_alloc(iwm, buf + buf_offset, packet_size, id);
  389. if (IS_ERR(packet))
  390. return PTR_ERR(packet);
  391. list_add_tail(&packet->node, &iwm->rx_packets[IWM_RX_ID_GET_HASH(id)]);
  392. /* We might (unlikely) have received the packet _after_ the ticket */
  393. queue_work(iwm->rx_wq, &iwm->rx_worker);
  394. return 0;
  395. }
  396. /* MLME handlers */
  397. static int iwm_mlme_assoc_start(struct iwm_priv *iwm, u8 *buf,
  398. unsigned long buf_size,
  399. struct iwm_wifi_cmd *cmd)
  400. {
  401. struct iwm_umac_notif_assoc_start *start;
  402. start = (struct iwm_umac_notif_assoc_start *)buf;
  403. IWM_DBG_MLME(iwm, INFO, "Association with %pM Started, reason: %d\n",
  404. start->bssid, le32_to_cpu(start->roam_reason));
  405. wake_up_interruptible(&iwm->mlme_queue);
  406. return 0;
  407. }
  408. static u8 iwm_is_open_wep_profile(struct iwm_priv *iwm)
  409. {
  410. if ((iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_40 ||
  411. iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_104) &&
  412. (iwm->umac_profile->sec.ucast_cipher ==
  413. iwm->umac_profile->sec.mcast_cipher) &&
  414. (iwm->umac_profile->sec.auth_type == UMAC_AUTH_TYPE_OPEN))
  415. return 1;
  416. return 0;
  417. }
  418. static int iwm_mlme_assoc_complete(struct iwm_priv *iwm, u8 *buf,
  419. unsigned long buf_size,
  420. struct iwm_wifi_cmd *cmd)
  421. {
  422. struct iwm_umac_notif_assoc_complete *complete =
  423. (struct iwm_umac_notif_assoc_complete *)buf;
  424. IWM_DBG_MLME(iwm, INFO, "Association with %pM completed, status: %d\n",
  425. complete->bssid, complete->status);
  426. switch (le32_to_cpu(complete->status)) {
  427. case UMAC_ASSOC_COMPLETE_SUCCESS:
  428. set_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
  429. memcpy(iwm->bssid, complete->bssid, ETH_ALEN);
  430. iwm->channel = complete->channel;
  431. /* Internal roaming state, avoid notifying SME. */
  432. if (!test_and_clear_bit(IWM_STATUS_SME_CONNECTING, &iwm->status)
  433. && iwm->conf.mode == UMAC_MODE_BSS) {
  434. cancel_delayed_work(&iwm->disconnect);
  435. cfg80211_roamed(iwm_to_ndev(iwm),
  436. complete->bssid,
  437. iwm->req_ie, iwm->req_ie_len,
  438. iwm->resp_ie, iwm->resp_ie_len,
  439. GFP_KERNEL);
  440. break;
  441. }
  442. iwm_link_on(iwm);
  443. if (iwm->conf.mode == UMAC_MODE_IBSS)
  444. goto ibss;
  445. if (!test_bit(IWM_STATUS_RESETTING, &iwm->status))
  446. cfg80211_connect_result(iwm_to_ndev(iwm),
  447. complete->bssid,
  448. iwm->req_ie, iwm->req_ie_len,
  449. iwm->resp_ie, iwm->resp_ie_len,
  450. WLAN_STATUS_SUCCESS,
  451. GFP_KERNEL);
  452. else
  453. cfg80211_roamed(iwm_to_ndev(iwm),
  454. complete->bssid,
  455. iwm->req_ie, iwm->req_ie_len,
  456. iwm->resp_ie, iwm->resp_ie_len,
  457. GFP_KERNEL);
  458. break;
  459. case UMAC_ASSOC_COMPLETE_FAILURE:
  460. clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
  461. memset(iwm->bssid, 0, ETH_ALEN);
  462. iwm->channel = 0;
  463. /* Internal roaming state, avoid notifying SME. */
  464. if (!test_and_clear_bit(IWM_STATUS_SME_CONNECTING, &iwm->status)
  465. && iwm->conf.mode == UMAC_MODE_BSS) {
  466. cancel_delayed_work(&iwm->disconnect);
  467. break;
  468. }
  469. iwm_link_off(iwm);
  470. if (iwm->conf.mode == UMAC_MODE_IBSS)
  471. goto ibss;
  472. if (!test_bit(IWM_STATUS_RESETTING, &iwm->status))
  473. if (!iwm_is_open_wep_profile(iwm)) {
  474. cfg80211_connect_result(iwm_to_ndev(iwm),
  475. complete->bssid,
  476. NULL, 0, NULL, 0,
  477. WLAN_STATUS_UNSPECIFIED_FAILURE,
  478. GFP_KERNEL);
  479. } else {
  480. /* Let's try shared WEP auth */
  481. IWM_ERR(iwm, "Trying WEP shared auth\n");
  482. schedule_work(&iwm->auth_retry_worker);
  483. }
  484. else
  485. cfg80211_disconnected(iwm_to_ndev(iwm), 0, NULL, 0,
  486. GFP_KERNEL);
  487. break;
  488. default:
  489. break;
  490. }
  491. clear_bit(IWM_STATUS_RESETTING, &iwm->status);
  492. return 0;
  493. ibss:
  494. cfg80211_ibss_joined(iwm_to_ndev(iwm), iwm->bssid, GFP_KERNEL);
  495. clear_bit(IWM_STATUS_RESETTING, &iwm->status);
  496. return 0;
  497. }
  498. static int iwm_mlme_profile_invalidate(struct iwm_priv *iwm, u8 *buf,
  499. unsigned long buf_size,
  500. struct iwm_wifi_cmd *cmd)
  501. {
  502. struct iwm_umac_notif_profile_invalidate *invalid;
  503. u32 reason;
  504. invalid = (struct iwm_umac_notif_profile_invalidate *)buf;
  505. reason = le32_to_cpu(invalid->reason);
  506. IWM_DBG_MLME(iwm, INFO, "Profile Invalidated. Reason: %d\n", reason);
  507. if (reason != UMAC_PROFILE_INVALID_REQUEST &&
  508. test_bit(IWM_STATUS_SME_CONNECTING, &iwm->status))
  509. cfg80211_connect_result(iwm_to_ndev(iwm), NULL, NULL, 0, NULL,
  510. 0, WLAN_STATUS_UNSPECIFIED_FAILURE,
  511. GFP_KERNEL);
  512. clear_bit(IWM_STATUS_SME_CONNECTING, &iwm->status);
  513. clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
  514. iwm->umac_profile_active = 0;
  515. memset(iwm->bssid, 0, ETH_ALEN);
  516. iwm->channel = 0;
  517. iwm_link_off(iwm);
  518. wake_up_interruptible(&iwm->mlme_queue);
  519. return 0;
  520. }
  521. #define IWM_DISCONNECT_INTERVAL (5 * HZ)
  522. static int iwm_mlme_connection_terminated(struct iwm_priv *iwm, u8 *buf,
  523. unsigned long buf_size,
  524. struct iwm_wifi_cmd *cmd)
  525. {
  526. IWM_DBG_MLME(iwm, DBG, "Connection terminated\n");
  527. schedule_delayed_work(&iwm->disconnect, IWM_DISCONNECT_INTERVAL);
  528. return 0;
  529. }
  530. static int iwm_mlme_scan_complete(struct iwm_priv *iwm, u8 *buf,
  531. unsigned long buf_size,
  532. struct iwm_wifi_cmd *cmd)
  533. {
  534. int ret;
  535. struct iwm_umac_notif_scan_complete *scan_complete =
  536. (struct iwm_umac_notif_scan_complete *)buf;
  537. u32 result = le32_to_cpu(scan_complete->result);
  538. IWM_DBG_MLME(iwm, INFO, "type:0x%x result:0x%x seq:%d\n",
  539. le32_to_cpu(scan_complete->type),
  540. le32_to_cpu(scan_complete->result),
  541. scan_complete->seq_num);
  542. if (!test_and_clear_bit(IWM_STATUS_SCANNING, &iwm->status)) {
  543. IWM_ERR(iwm, "Scan complete while device not scanning\n");
  544. return -EIO;
  545. }
  546. if (!iwm->scan_request)
  547. return 0;
  548. ret = iwm_cfg80211_inform_bss(iwm);
  549. cfg80211_scan_done(iwm->scan_request,
  550. (result & UMAC_SCAN_RESULT_ABORTED) ? 1 : !!ret);
  551. iwm->scan_request = NULL;
  552. return ret;
  553. }
  554. static int iwm_mlme_update_sta_table(struct iwm_priv *iwm, u8 *buf,
  555. unsigned long buf_size,
  556. struct iwm_wifi_cmd *cmd)
  557. {
  558. struct iwm_umac_notif_sta_info *umac_sta =
  559. (struct iwm_umac_notif_sta_info *)buf;
  560. struct iwm_sta_info *sta;
  561. int i;
  562. switch (le32_to_cpu(umac_sta->opcode)) {
  563. case UMAC_OPCODE_ADD_MODIFY:
  564. sta = &iwm->sta_table[GET_VAL8(umac_sta->sta_id, LMAC_STA_ID)];
  565. IWM_DBG_MLME(iwm, INFO, "%s STA: ID = %d, Color = %d, "
  566. "addr = %pM, qos = %d\n",
  567. sta->valid ? "Modify" : "Add",
  568. GET_VAL8(umac_sta->sta_id, LMAC_STA_ID),
  569. GET_VAL8(umac_sta->sta_id, LMAC_STA_COLOR),
  570. umac_sta->mac_addr,
  571. umac_sta->flags & UMAC_STA_FLAG_QOS);
  572. sta->valid = 1;
  573. sta->qos = umac_sta->flags & UMAC_STA_FLAG_QOS;
  574. sta->color = GET_VAL8(umac_sta->sta_id, LMAC_STA_COLOR);
  575. memcpy(sta->addr, umac_sta->mac_addr, ETH_ALEN);
  576. break;
  577. case UMAC_OPCODE_REMOVE:
  578. IWM_DBG_MLME(iwm, INFO, "Remove STA: ID = %d, Color = %d, "
  579. "addr = %pM\n",
  580. GET_VAL8(umac_sta->sta_id, LMAC_STA_ID),
  581. GET_VAL8(umac_sta->sta_id, LMAC_STA_COLOR),
  582. umac_sta->mac_addr);
  583. sta = &iwm->sta_table[GET_VAL8(umac_sta->sta_id, LMAC_STA_ID)];
  584. if (!memcmp(sta->addr, umac_sta->mac_addr, ETH_ALEN))
  585. sta->valid = 0;
  586. break;
  587. case UMAC_OPCODE_CLEAR_ALL:
  588. for (i = 0; i < IWM_STA_TABLE_NUM; i++)
  589. iwm->sta_table[i].valid = 0;
  590. break;
  591. default:
  592. break;
  593. }
  594. return 0;
  595. }
  596. static int iwm_mlme_medium_lost(struct iwm_priv *iwm, u8 *buf,
  597. unsigned long buf_size,
  598. struct iwm_wifi_cmd *cmd)
  599. {
  600. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  601. IWM_DBG_NTF(iwm, DBG, "WiFi/WiMax coexistence radio is OFF\n");
  602. wiphy_rfkill_set_hw_state(wiphy, true);
  603. return 0;
  604. }
  605. static int iwm_mlme_update_bss_table(struct iwm_priv *iwm, u8 *buf,
  606. unsigned long buf_size,
  607. struct iwm_wifi_cmd *cmd)
  608. {
  609. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  610. struct ieee80211_mgmt *mgmt;
  611. struct iwm_umac_notif_bss_info *umac_bss =
  612. (struct iwm_umac_notif_bss_info *)buf;
  613. struct ieee80211_channel *channel;
  614. struct ieee80211_supported_band *band;
  615. struct iwm_bss_info *bss, *next;
  616. s32 signal;
  617. int freq;
  618. u16 frame_len = le16_to_cpu(umac_bss->frame_len);
  619. size_t bss_len = sizeof(struct iwm_umac_notif_bss_info) + frame_len;
  620. mgmt = (struct ieee80211_mgmt *)(umac_bss->frame_buf);
  621. IWM_DBG_MLME(iwm, DBG, "New BSS info entry: %pM\n", mgmt->bssid);
  622. IWM_DBG_MLME(iwm, DBG, "\tType: 0x%x\n", le32_to_cpu(umac_bss->type));
  623. IWM_DBG_MLME(iwm, DBG, "\tTimestamp: %d\n",
  624. le32_to_cpu(umac_bss->timestamp));
  625. IWM_DBG_MLME(iwm, DBG, "\tTable Index: %d\n",
  626. le16_to_cpu(umac_bss->table_idx));
  627. IWM_DBG_MLME(iwm, DBG, "\tBand: %d\n", umac_bss->band);
  628. IWM_DBG_MLME(iwm, DBG, "\tChannel: %d\n", umac_bss->channel);
  629. IWM_DBG_MLME(iwm, DBG, "\tRSSI: %d\n", umac_bss->rssi);
  630. IWM_DBG_MLME(iwm, DBG, "\tFrame Length: %d\n", frame_len);
  631. list_for_each_entry_safe(bss, next, &iwm->bss_list, node)
  632. if (bss->bss->table_idx == umac_bss->table_idx)
  633. break;
  634. if (&bss->node != &iwm->bss_list) {
  635. /* Remove the old BSS entry, we will add it back later. */
  636. list_del(&bss->node);
  637. kfree(bss->bss);
  638. } else {
  639. /* New BSS entry */
  640. bss = kzalloc(sizeof(struct iwm_bss_info), GFP_KERNEL);
  641. if (!bss) {
  642. IWM_ERR(iwm, "Couldn't allocate bss_info\n");
  643. return -ENOMEM;
  644. }
  645. }
  646. bss->bss = kzalloc(bss_len, GFP_KERNEL);
  647. if (!bss) {
  648. kfree(bss);
  649. IWM_ERR(iwm, "Couldn't allocate bss\n");
  650. return -ENOMEM;
  651. }
  652. INIT_LIST_HEAD(&bss->node);
  653. memcpy(bss->bss, umac_bss, bss_len);
  654. if (umac_bss->band == UMAC_BAND_2GHZ)
  655. band = wiphy->bands[IEEE80211_BAND_2GHZ];
  656. else if (umac_bss->band == UMAC_BAND_5GHZ)
  657. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  658. else {
  659. IWM_ERR(iwm, "Invalid band: %d\n", umac_bss->band);
  660. goto err;
  661. }
  662. freq = ieee80211_channel_to_frequency(umac_bss->channel);
  663. channel = ieee80211_get_channel(wiphy, freq);
  664. signal = umac_bss->rssi * 100;
  665. bss->cfg_bss = cfg80211_inform_bss_frame(wiphy, channel,
  666. mgmt, frame_len,
  667. signal, GFP_KERNEL);
  668. if (!bss->cfg_bss)
  669. goto err;
  670. list_add_tail(&bss->node, &iwm->bss_list);
  671. return 0;
  672. err:
  673. kfree(bss->bss);
  674. kfree(bss);
  675. return -EINVAL;
  676. }
  677. static int iwm_mlme_remove_bss(struct iwm_priv *iwm, u8 *buf,
  678. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  679. {
  680. struct iwm_umac_notif_bss_removed *bss_rm =
  681. (struct iwm_umac_notif_bss_removed *)buf;
  682. struct iwm_bss_info *bss, *next;
  683. u16 table_idx;
  684. int i;
  685. for (i = 0; i < le32_to_cpu(bss_rm->count); i++) {
  686. table_idx = (le16_to_cpu(bss_rm->entries[i])
  687. & IWM_BSS_REMOVE_INDEX_MSK);
  688. list_for_each_entry_safe(bss, next, &iwm->bss_list, node)
  689. if (bss->bss->table_idx == cpu_to_le16(table_idx)) {
  690. struct ieee80211_mgmt *mgmt;
  691. mgmt = (struct ieee80211_mgmt *)
  692. (bss->bss->frame_buf);
  693. IWM_DBG_MLME(iwm, ERR,
  694. "BSS removed: %pM\n",
  695. mgmt->bssid);
  696. list_del(&bss->node);
  697. kfree(bss->bss);
  698. kfree(bss);
  699. }
  700. }
  701. return 0;
  702. }
  703. static int iwm_mlme_mgt_frame(struct iwm_priv *iwm, u8 *buf,
  704. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  705. {
  706. struct iwm_umac_notif_mgt_frame *mgt_frame =
  707. (struct iwm_umac_notif_mgt_frame *)buf;
  708. struct ieee80211_mgmt *mgt = (struct ieee80211_mgmt *)mgt_frame->frame;
  709. u8 *ie;
  710. IWM_HEXDUMP(iwm, DBG, MLME, "MGT: ", mgt_frame->frame,
  711. le16_to_cpu(mgt_frame->len));
  712. if (ieee80211_is_assoc_req(mgt->frame_control)) {
  713. ie = mgt->u.assoc_req.variable;;
  714. iwm->req_ie_len =
  715. le16_to_cpu(mgt_frame->len) - (ie - (u8 *)mgt);
  716. kfree(iwm->req_ie);
  717. iwm->req_ie = kmemdup(mgt->u.assoc_req.variable,
  718. iwm->req_ie_len, GFP_KERNEL);
  719. } else if (ieee80211_is_reassoc_req(mgt->frame_control)) {
  720. ie = mgt->u.reassoc_req.variable;;
  721. iwm->req_ie_len =
  722. le16_to_cpu(mgt_frame->len) - (ie - (u8 *)mgt);
  723. kfree(iwm->req_ie);
  724. iwm->req_ie = kmemdup(mgt->u.reassoc_req.variable,
  725. iwm->req_ie_len, GFP_KERNEL);
  726. } else if (ieee80211_is_assoc_resp(mgt->frame_control)) {
  727. ie = mgt->u.assoc_resp.variable;;
  728. iwm->resp_ie_len =
  729. le16_to_cpu(mgt_frame->len) - (ie - (u8 *)mgt);
  730. kfree(iwm->resp_ie);
  731. iwm->resp_ie = kmemdup(mgt->u.assoc_resp.variable,
  732. iwm->resp_ie_len, GFP_KERNEL);
  733. } else if (ieee80211_is_reassoc_resp(mgt->frame_control)) {
  734. ie = mgt->u.reassoc_resp.variable;;
  735. iwm->resp_ie_len =
  736. le16_to_cpu(mgt_frame->len) - (ie - (u8 *)mgt);
  737. kfree(iwm->resp_ie);
  738. iwm->resp_ie = kmemdup(mgt->u.reassoc_resp.variable,
  739. iwm->resp_ie_len, GFP_KERNEL);
  740. } else {
  741. IWM_ERR(iwm, "Unsupported management frame: 0x%x",
  742. le16_to_cpu(mgt->frame_control));
  743. return 0;
  744. }
  745. return 0;
  746. }
  747. static int iwm_ntf_mlme(struct iwm_priv *iwm, u8 *buf,
  748. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  749. {
  750. struct iwm_umac_notif_wifi_if *notif =
  751. (struct iwm_umac_notif_wifi_if *)buf;
  752. switch (notif->status) {
  753. case WIFI_IF_NTFY_ASSOC_START:
  754. return iwm_mlme_assoc_start(iwm, buf, buf_size, cmd);
  755. case WIFI_IF_NTFY_ASSOC_COMPLETE:
  756. return iwm_mlme_assoc_complete(iwm, buf, buf_size, cmd);
  757. case WIFI_IF_NTFY_PROFILE_INVALIDATE_COMPLETE:
  758. return iwm_mlme_profile_invalidate(iwm, buf, buf_size, cmd);
  759. case WIFI_IF_NTFY_CONNECTION_TERMINATED:
  760. return iwm_mlme_connection_terminated(iwm, buf, buf_size, cmd);
  761. case WIFI_IF_NTFY_SCAN_COMPLETE:
  762. return iwm_mlme_scan_complete(iwm, buf, buf_size, cmd);
  763. case WIFI_IF_NTFY_STA_TABLE_CHANGE:
  764. return iwm_mlme_update_sta_table(iwm, buf, buf_size, cmd);
  765. case WIFI_IF_NTFY_EXTENDED_IE_REQUIRED:
  766. IWM_DBG_MLME(iwm, DBG, "Extended IE required\n");
  767. break;
  768. case WIFI_IF_NTFY_RADIO_PREEMPTION:
  769. return iwm_mlme_medium_lost(iwm, buf, buf_size, cmd);
  770. case WIFI_IF_NTFY_BSS_TRK_TABLE_CHANGED:
  771. return iwm_mlme_update_bss_table(iwm, buf, buf_size, cmd);
  772. case WIFI_IF_NTFY_BSS_TRK_ENTRIES_REMOVED:
  773. return iwm_mlme_remove_bss(iwm, buf, buf_size, cmd);
  774. break;
  775. case WIFI_IF_NTFY_MGMT_FRAME:
  776. return iwm_mlme_mgt_frame(iwm, buf, buf_size, cmd);
  777. case WIFI_DBG_IF_NTFY_SCAN_SUPER_JOB_START:
  778. case WIFI_DBG_IF_NTFY_SCAN_SUPER_JOB_COMPLETE:
  779. case WIFI_DBG_IF_NTFY_SCAN_CHANNEL_START:
  780. case WIFI_DBG_IF_NTFY_SCAN_CHANNEL_RESULT:
  781. case WIFI_DBG_IF_NTFY_SCAN_MINI_JOB_START:
  782. case WIFI_DBG_IF_NTFY_SCAN_MINI_JOB_COMPLETE:
  783. case WIFI_DBG_IF_NTFY_CNCT_ATC_START:
  784. case WIFI_DBG_IF_NTFY_COEX_NOTIFICATION:
  785. case WIFI_DBG_IF_NTFY_COEX_HANDLE_ENVELOP:
  786. case WIFI_DBG_IF_NTFY_COEX_HANDLE_RELEASE_ENVELOP:
  787. IWM_DBG_MLME(iwm, DBG, "MLME debug notification: 0x%x\n",
  788. notif->status);
  789. break;
  790. default:
  791. IWM_ERR(iwm, "Unhandled notification: 0x%x\n", notif->status);
  792. break;
  793. }
  794. return 0;
  795. }
  796. #define IWM_STATS_UPDATE_INTERVAL (2 * HZ)
  797. static int iwm_ntf_statistics(struct iwm_priv *iwm, u8 *buf,
  798. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  799. {
  800. struct iwm_umac_notif_stats *stats = (struct iwm_umac_notif_stats *)buf;
  801. struct iw_statistics *wstats = &iwm->wstats;
  802. u16 max_rate = 0;
  803. int i;
  804. IWM_DBG_MLME(iwm, DBG, "Statistics notification received\n");
  805. if (test_bit(IWM_STATUS_ASSOCIATED, &iwm->status)) {
  806. for (i = 0; i < UMAC_NTF_RATE_SAMPLE_NR; i++) {
  807. max_rate = max_t(u16, max_rate,
  808. max(le16_to_cpu(stats->tx_rate[i]),
  809. le16_to_cpu(stats->rx_rate[i])));
  810. }
  811. /* UMAC passes rate info multiplies by 2 */
  812. iwm->rate = max_rate >> 1;
  813. }
  814. iwm->txpower = le32_to_cpu(stats->tx_power);
  815. wstats->status = 0;
  816. wstats->discard.nwid = le32_to_cpu(stats->rx_drop_other_bssid);
  817. wstats->discard.code = le32_to_cpu(stats->rx_drop_decode);
  818. wstats->discard.fragment = le32_to_cpu(stats->rx_drop_reassembly);
  819. wstats->discard.retries = le32_to_cpu(stats->tx_drop_max_retry);
  820. wstats->miss.beacon = le32_to_cpu(stats->missed_beacons);
  821. /* according to cfg80211 */
  822. if (stats->rssi_dbm < -110)
  823. wstats->qual.qual = 0;
  824. else if (stats->rssi_dbm > -40)
  825. wstats->qual.qual = 70;
  826. else
  827. wstats->qual.qual = stats->rssi_dbm + 110;
  828. wstats->qual.level = stats->rssi_dbm;
  829. wstats->qual.noise = stats->noise_dbm;
  830. wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  831. schedule_delayed_work(&iwm->stats_request, IWM_STATS_UPDATE_INTERVAL);
  832. mod_timer(&iwm->watchdog, round_jiffies(jiffies + IWM_WATCHDOG_PERIOD));
  833. return 0;
  834. }
  835. static int iwm_ntf_eeprom_proxy(struct iwm_priv *iwm, u8 *buf,
  836. unsigned long buf_size,
  837. struct iwm_wifi_cmd *cmd)
  838. {
  839. struct iwm_umac_cmd_eeprom_proxy *eeprom_proxy =
  840. (struct iwm_umac_cmd_eeprom_proxy *)
  841. (buf + sizeof(struct iwm_umac_wifi_in_hdr));
  842. struct iwm_umac_cmd_eeprom_proxy_hdr *hdr = &eeprom_proxy->hdr;
  843. u32 hdr_offset = le32_to_cpu(hdr->offset);
  844. u32 hdr_len = le32_to_cpu(hdr->len);
  845. u32 hdr_type = le32_to_cpu(hdr->type);
  846. IWM_DBG_NTF(iwm, DBG, "type: 0x%x, len: %d, offset: 0x%x\n",
  847. hdr_type, hdr_len, hdr_offset);
  848. if ((hdr_offset + hdr_len) > IWM_EEPROM_LEN)
  849. return -EINVAL;
  850. switch (hdr_type) {
  851. case IWM_UMAC_CMD_EEPROM_TYPE_READ:
  852. memcpy(iwm->eeprom + hdr_offset, eeprom_proxy->buf, hdr_len);
  853. break;
  854. case IWM_UMAC_CMD_EEPROM_TYPE_WRITE:
  855. default:
  856. return -ENOTSUPP;
  857. }
  858. return 0;
  859. }
  860. static int iwm_ntf_channel_info_list(struct iwm_priv *iwm, u8 *buf,
  861. unsigned long buf_size,
  862. struct iwm_wifi_cmd *cmd)
  863. {
  864. struct iwm_umac_cmd_get_channel_list *ch_list =
  865. (struct iwm_umac_cmd_get_channel_list *)
  866. (buf + sizeof(struct iwm_umac_wifi_in_hdr));
  867. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  868. struct ieee80211_supported_band *band;
  869. int i;
  870. band = wiphy->bands[IEEE80211_BAND_2GHZ];
  871. for (i = 0; i < band->n_channels; i++) {
  872. unsigned long ch_mask_0 =
  873. le32_to_cpu(ch_list->ch[0].channels_mask);
  874. unsigned long ch_mask_2 =
  875. le32_to_cpu(ch_list->ch[2].channels_mask);
  876. if (!test_bit(i, &ch_mask_0))
  877. band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
  878. if (!test_bit(i, &ch_mask_2))
  879. band->channels[i].flags |= IEEE80211_CHAN_NO_IBSS;
  880. }
  881. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  882. for (i = 0; i < min(band->n_channels, 32); i++) {
  883. unsigned long ch_mask_1 =
  884. le32_to_cpu(ch_list->ch[1].channels_mask);
  885. unsigned long ch_mask_3 =
  886. le32_to_cpu(ch_list->ch[3].channels_mask);
  887. if (!test_bit(i, &ch_mask_1))
  888. band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
  889. if (!test_bit(i, &ch_mask_3))
  890. band->channels[i].flags |= IEEE80211_CHAN_NO_IBSS;
  891. }
  892. return 0;
  893. }
  894. static int iwm_ntf_wifi_if_wrapper(struct iwm_priv *iwm, u8 *buf,
  895. unsigned long buf_size,
  896. struct iwm_wifi_cmd *cmd)
  897. {
  898. struct iwm_umac_wifi_if *hdr;
  899. if (cmd == NULL) {
  900. IWM_ERR(iwm, "Couldn't find expected wifi command\n");
  901. return -EINVAL;
  902. }
  903. hdr = (struct iwm_umac_wifi_if *)cmd->buf.payload;
  904. IWM_DBG_NTF(iwm, DBG, "WIFI_IF_WRAPPER cmd is delivered to UMAC: "
  905. "oid is 0x%x\n", hdr->oid);
  906. if (hdr->oid <= WIFI_IF_NTFY_MAX) {
  907. set_bit(hdr->oid, &iwm->wifi_ntfy[0]);
  908. wake_up_interruptible(&iwm->wifi_ntfy_queue);
  909. } else
  910. return -EINVAL;
  911. switch (hdr->oid) {
  912. case UMAC_WIFI_IF_CMD_SET_PROFILE:
  913. iwm->umac_profile_active = 1;
  914. break;
  915. default:
  916. break;
  917. }
  918. return 0;
  919. }
  920. #define CT_KILL_DELAY (30 * HZ)
  921. static int iwm_ntf_card_state(struct iwm_priv *iwm, u8 *buf,
  922. unsigned long buf_size, struct iwm_wifi_cmd *cmd)
  923. {
  924. struct wiphy *wiphy = iwm_to_wiphy(iwm);
  925. struct iwm_lmac_card_state *state = (struct iwm_lmac_card_state *)
  926. (buf + sizeof(struct iwm_umac_wifi_in_hdr));
  927. u32 flags = le32_to_cpu(state->flags);
  928. IWM_INFO(iwm, "HW RF Kill %s, CT Kill %s\n",
  929. flags & IWM_CARD_STATE_HW_DISABLED ? "ON" : "OFF",
  930. flags & IWM_CARD_STATE_CTKILL_DISABLED ? "ON" : "OFF");
  931. if (flags & IWM_CARD_STATE_CTKILL_DISABLED) {
  932. /*
  933. * We got a CTKILL event: We bring the interface down in
  934. * oder to cool the device down, and try to bring it up
  935. * 30 seconds later. If it's still too hot, we'll go through
  936. * this code path again.
  937. */
  938. cancel_delayed_work_sync(&iwm->ct_kill_delay);
  939. schedule_delayed_work(&iwm->ct_kill_delay, CT_KILL_DELAY);
  940. }
  941. wiphy_rfkill_set_hw_state(wiphy, flags &
  942. (IWM_CARD_STATE_HW_DISABLED |
  943. IWM_CARD_STATE_CTKILL_DISABLED));
  944. return 0;
  945. }
  946. static int iwm_rx_handle_wifi(struct iwm_priv *iwm, u8 *buf,
  947. unsigned long buf_size)
  948. {
  949. struct iwm_umac_wifi_in_hdr *wifi_hdr;
  950. struct iwm_wifi_cmd *cmd;
  951. u8 source, cmd_id;
  952. u16 seq_num;
  953. u32 count;
  954. u8 resp;
  955. wifi_hdr = (struct iwm_umac_wifi_in_hdr *)buf;
  956. cmd_id = wifi_hdr->sw_hdr.cmd.cmd;
  957. source = GET_VAL32(wifi_hdr->hw_hdr.cmd, UMAC_HDI_IN_CMD_SOURCE);
  958. if (source >= IWM_SRC_NUM) {
  959. IWM_CRIT(iwm, "invalid source %d\n", source);
  960. return -EINVAL;
  961. }
  962. count = (GET_VAL32(wifi_hdr->sw_hdr.meta_data, UMAC_FW_CMD_BYTE_COUNT));
  963. count += sizeof(struct iwm_umac_wifi_in_hdr) -
  964. sizeof(struct iwm_dev_cmd_hdr);
  965. if (count > buf_size) {
  966. IWM_CRIT(iwm, "count %d, buf size:%ld\n", count, buf_size);
  967. return -EINVAL;
  968. }
  969. resp = GET_VAL32(wifi_hdr->sw_hdr.meta_data, UMAC_FW_CMD_STATUS);
  970. seq_num = le16_to_cpu(wifi_hdr->sw_hdr.cmd.seq_num);
  971. IWM_DBG_RX(iwm, DBG, "CMD:0x%x, source: 0x%x, seqnum: %d\n",
  972. cmd_id, source, seq_num);
  973. /*
  974. * If this is a response to a previously sent command, there must
  975. * be a pending command for this sequence number.
  976. */
  977. cmd = iwm_get_pending_wifi_cmd(iwm, seq_num);
  978. /* Notify the caller only for sync commands. */
  979. switch (source) {
  980. case UMAC_HDI_IN_SOURCE_FHRX:
  981. if (iwm->lmac_handlers[cmd_id] &&
  982. test_bit(cmd_id, &iwm->lmac_handler_map[0]))
  983. return iwm_notif_send(iwm, cmd, cmd_id, source,
  984. buf, count);
  985. break;
  986. case UMAC_HDI_IN_SOURCE_FW:
  987. if (iwm->umac_handlers[cmd_id] &&
  988. test_bit(cmd_id, &iwm->umac_handler_map[0]))
  989. return iwm_notif_send(iwm, cmd, cmd_id, source,
  990. buf, count);
  991. break;
  992. case UMAC_HDI_IN_SOURCE_UDMA:
  993. break;
  994. }
  995. return iwm_rx_handle_resp(iwm, buf, count, cmd);
  996. }
  997. int iwm_rx_handle_resp(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size,
  998. struct iwm_wifi_cmd *cmd)
  999. {
  1000. u8 source, cmd_id;
  1001. struct iwm_umac_wifi_in_hdr *wifi_hdr;
  1002. int ret = 0;
  1003. wifi_hdr = (struct iwm_umac_wifi_in_hdr *)buf;
  1004. cmd_id = wifi_hdr->sw_hdr.cmd.cmd;
  1005. source = GET_VAL32(wifi_hdr->hw_hdr.cmd, UMAC_HDI_IN_CMD_SOURCE);
  1006. IWM_DBG_RX(iwm, DBG, "CMD:0x%x, source: 0x%x\n", cmd_id, source);
  1007. switch (source) {
  1008. case UMAC_HDI_IN_SOURCE_FHRX:
  1009. if (iwm->lmac_handlers[cmd_id])
  1010. ret = iwm->lmac_handlers[cmd_id]
  1011. (iwm, buf, buf_size, cmd);
  1012. break;
  1013. case UMAC_HDI_IN_SOURCE_FW:
  1014. if (iwm->umac_handlers[cmd_id])
  1015. ret = iwm->umac_handlers[cmd_id]
  1016. (iwm, buf, buf_size, cmd);
  1017. break;
  1018. case UMAC_HDI_IN_SOURCE_UDMA:
  1019. ret = -EINVAL;
  1020. break;
  1021. }
  1022. kfree(cmd);
  1023. return ret;
  1024. }
  1025. static int iwm_rx_handle_nonwifi(struct iwm_priv *iwm, u8 *buf,
  1026. unsigned long buf_size)
  1027. {
  1028. u8 seq_num;
  1029. struct iwm_udma_in_hdr *hdr = (struct iwm_udma_in_hdr *)buf;
  1030. struct iwm_nonwifi_cmd *cmd, *next;
  1031. seq_num = GET_VAL32(hdr->cmd, UDMA_HDI_IN_CMD_NON_WIFI_HW_SEQ_NUM);
  1032. /*
  1033. * We received a non wifi answer.
  1034. * Let's check if there's a pending command for it, and if so
  1035. * replace the command payload with the buffer, and then wake the
  1036. * callers up.
  1037. * That means we only support synchronised non wifi command response
  1038. * schemes.
  1039. */
  1040. list_for_each_entry_safe(cmd, next, &iwm->nonwifi_pending_cmd, pending)
  1041. if (cmd->seq_num == seq_num) {
  1042. cmd->resp_received = 1;
  1043. cmd->buf.len = buf_size;
  1044. memcpy(cmd->buf.hdr, buf, buf_size);
  1045. wake_up_interruptible(&iwm->nonwifi_queue);
  1046. }
  1047. return 0;
  1048. }
  1049. static int iwm_rx_handle_umac(struct iwm_priv *iwm, u8 *buf,
  1050. unsigned long buf_size)
  1051. {
  1052. int ret = 0;
  1053. u8 op_code;
  1054. unsigned long buf_offset = 0;
  1055. struct iwm_udma_in_hdr *hdr;
  1056. /*
  1057. * To allow for a more efficient bus usage, UMAC
  1058. * messages are encapsulated into UDMA ones. This
  1059. * way we can have several UMAC messages in one bus
  1060. * transfer.
  1061. * A UDMA frame size is always aligned on 16 bytes,
  1062. * and a UDMA frame must not start with a UMAC_PAD_TERMINAL
  1063. * word. This is how we parse a bus frame into several
  1064. * UDMA ones.
  1065. */
  1066. while (buf_offset < buf_size) {
  1067. hdr = (struct iwm_udma_in_hdr *)(buf + buf_offset);
  1068. if (iwm_rx_check_udma_hdr(hdr) < 0) {
  1069. IWM_DBG_RX(iwm, DBG, "End of frame\n");
  1070. break;
  1071. }
  1072. op_code = GET_VAL32(hdr->cmd, UMAC_HDI_IN_CMD_OPCODE);
  1073. IWM_DBG_RX(iwm, DBG, "Op code: 0x%x\n", op_code);
  1074. if (op_code == UMAC_HDI_IN_OPCODE_WIFI) {
  1075. ret |= iwm_rx_handle_wifi(iwm, buf + buf_offset,
  1076. buf_size - buf_offset);
  1077. } else if (op_code < UMAC_HDI_IN_OPCODE_NONWIFI_MAX) {
  1078. if (GET_VAL32(hdr->cmd,
  1079. UDMA_HDI_IN_CMD_NON_WIFI_HW_SIG) !=
  1080. UDMA_HDI_IN_CMD_NON_WIFI_HW_SIG) {
  1081. IWM_ERR(iwm, "Incorrect hw signature\n");
  1082. return -EINVAL;
  1083. }
  1084. ret |= iwm_rx_handle_nonwifi(iwm, buf + buf_offset,
  1085. buf_size - buf_offset);
  1086. } else {
  1087. IWM_ERR(iwm, "Invalid RX opcode: 0x%x\n", op_code);
  1088. ret |= -EINVAL;
  1089. }
  1090. buf_offset += iwm_rx_resp_size(hdr);
  1091. }
  1092. return ret;
  1093. }
  1094. int iwm_rx_handle(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size)
  1095. {
  1096. struct iwm_udma_in_hdr *hdr;
  1097. hdr = (struct iwm_udma_in_hdr *)buf;
  1098. switch (le32_to_cpu(hdr->cmd)) {
  1099. case UMAC_REBOOT_BARKER:
  1100. if (test_bit(IWM_STATUS_READY, &iwm->status)) {
  1101. IWM_ERR(iwm, "Unexpected BARKER\n");
  1102. schedule_work(&iwm->reset_worker);
  1103. return 0;
  1104. }
  1105. return iwm_notif_send(iwm, NULL, IWM_BARKER_REBOOT_NOTIFICATION,
  1106. IWM_SRC_UDMA, buf, buf_size);
  1107. case UMAC_ACK_BARKER:
  1108. return iwm_notif_send(iwm, NULL, IWM_ACK_BARKER_NOTIFICATION,
  1109. IWM_SRC_UDMA, NULL, 0);
  1110. default:
  1111. IWM_DBG_RX(iwm, DBG, "Received cmd: 0x%x\n", hdr->cmd);
  1112. return iwm_rx_handle_umac(iwm, buf, buf_size);
  1113. }
  1114. return 0;
  1115. }
  1116. static const iwm_handler iwm_umac_handlers[] =
  1117. {
  1118. [UMAC_NOTIFY_OPCODE_ERROR] = iwm_ntf_error,
  1119. [UMAC_NOTIFY_OPCODE_ALIVE] = iwm_ntf_umac_alive,
  1120. [UMAC_NOTIFY_OPCODE_INIT_COMPLETE] = iwm_ntf_init_complete,
  1121. [UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS] = iwm_ntf_wifi_status,
  1122. [UMAC_NOTIFY_OPCODE_WIFI_IF_WRAPPER] = iwm_ntf_mlme,
  1123. [UMAC_NOTIFY_OPCODE_PAGE_DEALLOC] = iwm_ntf_tx_credit_update,
  1124. [UMAC_NOTIFY_OPCODE_RX_TICKET] = iwm_ntf_rx_ticket,
  1125. [UMAC_CMD_OPCODE_RESET] = iwm_ntf_umac_reset,
  1126. [UMAC_NOTIFY_OPCODE_STATS] = iwm_ntf_statistics,
  1127. [UMAC_CMD_OPCODE_EEPROM_PROXY] = iwm_ntf_eeprom_proxy,
  1128. [UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST] = iwm_ntf_channel_info_list,
  1129. [REPLY_RX_MPDU_CMD] = iwm_ntf_rx_packet,
  1130. [UMAC_CMD_OPCODE_WIFI_IF_WRAPPER] = iwm_ntf_wifi_if_wrapper,
  1131. };
  1132. static const iwm_handler iwm_lmac_handlers[] =
  1133. {
  1134. [REPLY_TX] = iwm_ntf_tx,
  1135. [REPLY_ALIVE] = iwm_ntf_lmac_version,
  1136. [CALIBRATION_RES_NOTIFICATION] = iwm_ntf_calib_res,
  1137. [CALIBRATION_COMPLETE_NOTIFICATION] = iwm_ntf_calib_complete,
  1138. [CALIBRATION_CFG_CMD] = iwm_ntf_calib_cfg,
  1139. [REPLY_RX_MPDU_CMD] = iwm_ntf_rx_packet,
  1140. [CARD_STATE_NOTIFICATION] = iwm_ntf_card_state,
  1141. };
  1142. void iwm_rx_setup_handlers(struct iwm_priv *iwm)
  1143. {
  1144. iwm->umac_handlers = (iwm_handler *) iwm_umac_handlers;
  1145. iwm->lmac_handlers = (iwm_handler *) iwm_lmac_handlers;
  1146. }
  1147. static void iwm_remove_iv(struct sk_buff *skb, u32 hdr_total_len)
  1148. {
  1149. struct ieee80211_hdr *hdr;
  1150. unsigned int hdr_len;
  1151. hdr = (struct ieee80211_hdr *)skb->data;
  1152. if (!ieee80211_has_protected(hdr->frame_control))
  1153. return;
  1154. hdr_len = ieee80211_hdrlen(hdr->frame_control);
  1155. if (hdr_total_len <= hdr_len)
  1156. return;
  1157. memmove(skb->data + (hdr_total_len - hdr_len), skb->data, hdr_len);
  1158. skb_pull(skb, (hdr_total_len - hdr_len));
  1159. }
  1160. static void iwm_rx_adjust_packet(struct iwm_priv *iwm,
  1161. struct iwm_rx_packet *packet,
  1162. struct iwm_rx_ticket_node *ticket_node)
  1163. {
  1164. u32 payload_offset = 0, payload_len;
  1165. struct iwm_rx_ticket *ticket = ticket_node->ticket;
  1166. struct iwm_rx_mpdu_hdr *mpdu_hdr;
  1167. struct ieee80211_hdr *hdr;
  1168. mpdu_hdr = (struct iwm_rx_mpdu_hdr *)packet->skb->data;
  1169. payload_offset += sizeof(struct iwm_rx_mpdu_hdr);
  1170. /* Padding is 0 or 2 bytes */
  1171. payload_len = le16_to_cpu(mpdu_hdr->len) +
  1172. (le16_to_cpu(ticket->flags) & IWM_RX_TICKET_PAD_SIZE_MSK);
  1173. payload_len -= ticket->tail_len;
  1174. IWM_DBG_RX(iwm, DBG, "Packet adjusted, len:%d, offset:%d, "
  1175. "ticket offset:%d ticket tail len:%d\n",
  1176. payload_len, payload_offset, ticket->payload_offset,
  1177. ticket->tail_len);
  1178. IWM_HEXDUMP(iwm, DBG, RX, "RAW: ", packet->skb->data, packet->skb->len);
  1179. skb_pull(packet->skb, payload_offset);
  1180. skb_trim(packet->skb, payload_len);
  1181. iwm_remove_iv(packet->skb, ticket->payload_offset);
  1182. hdr = (struct ieee80211_hdr *) packet->skb->data;
  1183. if (ieee80211_is_data_qos(hdr->frame_control)) {
  1184. /* UMAC handed QOS_DATA frame with 2 padding bytes appended
  1185. * to the qos_ctl field in IEEE 802.11 headers. */
  1186. memmove(packet->skb->data + IEEE80211_QOS_CTL_LEN + 2,
  1187. packet->skb->data,
  1188. ieee80211_hdrlen(hdr->frame_control) -
  1189. IEEE80211_QOS_CTL_LEN);
  1190. hdr = (struct ieee80211_hdr *) skb_pull(packet->skb,
  1191. IEEE80211_QOS_CTL_LEN + 2);
  1192. hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  1193. }
  1194. IWM_HEXDUMP(iwm, DBG, RX, "ADJUSTED: ",
  1195. packet->skb->data, packet->skb->len);
  1196. }
  1197. static void classify8023(struct sk_buff *skb)
  1198. {
  1199. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1200. if (ieee80211_is_data_qos(hdr->frame_control)) {
  1201. u8 *qc = ieee80211_get_qos_ctl(hdr);
  1202. /* frame has qos control */
  1203. skb->priority = *qc & IEEE80211_QOS_CTL_TID_MASK;
  1204. } else {
  1205. skb->priority = 0;
  1206. }
  1207. }
  1208. static void iwm_rx_process_packet(struct iwm_priv *iwm,
  1209. struct iwm_rx_packet *packet,
  1210. struct iwm_rx_ticket_node *ticket_node)
  1211. {
  1212. int ret;
  1213. struct sk_buff *skb = packet->skb;
  1214. struct wireless_dev *wdev = iwm_to_wdev(iwm);
  1215. struct net_device *ndev = iwm_to_ndev(iwm);
  1216. IWM_DBG_RX(iwm, DBG, "Processing packet ID %d\n", packet->id);
  1217. switch (le16_to_cpu(ticket_node->ticket->action)) {
  1218. case IWM_RX_TICKET_RELEASE:
  1219. IWM_DBG_RX(iwm, DBG, "RELEASE packet\n");
  1220. classify8023(skb);
  1221. iwm_rx_adjust_packet(iwm, packet, ticket_node);
  1222. ret = ieee80211_data_to_8023(skb, ndev->dev_addr, wdev->iftype);
  1223. if (ret < 0) {
  1224. IWM_DBG_RX(iwm, DBG, "Couldn't convert 802.11 header - "
  1225. "%d\n", ret);
  1226. break;
  1227. }
  1228. IWM_HEXDUMP(iwm, DBG, RX, "802.3: ", skb->data, skb->len);
  1229. skb->dev = iwm_to_ndev(iwm);
  1230. skb->protocol = eth_type_trans(skb, ndev);
  1231. skb->ip_summed = CHECKSUM_NONE;
  1232. memset(skb->cb, 0, sizeof(skb->cb));
  1233. ndev->stats.rx_packets++;
  1234. ndev->stats.rx_bytes += skb->len;
  1235. if (netif_rx_ni(skb) == NET_RX_DROP) {
  1236. IWM_ERR(iwm, "Packet dropped\n");
  1237. ndev->stats.rx_dropped++;
  1238. }
  1239. break;
  1240. case IWM_RX_TICKET_DROP:
  1241. IWM_DBG_RX(iwm, DBG, "DROP packet: 0x%x\n",
  1242. le16_to_cpu(ticket_node->ticket->flags));
  1243. kfree_skb(packet->skb);
  1244. break;
  1245. default:
  1246. IWM_ERR(iwm, "Unknow ticket action: %d\n",
  1247. le16_to_cpu(ticket_node->ticket->action));
  1248. kfree_skb(packet->skb);
  1249. }
  1250. kfree(packet);
  1251. iwm_rx_ticket_node_free(ticket_node);
  1252. }
  1253. /*
  1254. * Rx data processing:
  1255. *
  1256. * We're receiving Rx packet from the LMAC, and Rx ticket from
  1257. * the UMAC.
  1258. * To forward a target data packet upstream (i.e. to the
  1259. * kernel network stack), we must have received an Rx ticket
  1260. * that tells us we're allowed to release this packet (ticket
  1261. * action is IWM_RX_TICKET_RELEASE). The Rx ticket also indicates,
  1262. * among other things, where valid data actually starts in the Rx
  1263. * packet.
  1264. */
  1265. void iwm_rx_worker(struct work_struct *work)
  1266. {
  1267. struct iwm_priv *iwm;
  1268. struct iwm_rx_ticket_node *ticket, *next;
  1269. iwm = container_of(work, struct iwm_priv, rx_worker);
  1270. /*
  1271. * We go through the tickets list and if there is a pending
  1272. * packet for it, we push it upstream.
  1273. * We stop whenever a ticket is missing its packet, as we're
  1274. * supposed to send the packets in order.
  1275. */
  1276. list_for_each_entry_safe(ticket, next, &iwm->rx_tickets, node) {
  1277. struct iwm_rx_packet *packet =
  1278. iwm_rx_packet_get(iwm, le16_to_cpu(ticket->ticket->id));
  1279. if (!packet) {
  1280. IWM_DBG_RX(iwm, DBG, "Skip rx_work: Wait for ticket %d "
  1281. "to be handled first\n",
  1282. le16_to_cpu(ticket->ticket->id));
  1283. return;
  1284. }
  1285. list_del(&ticket->node);
  1286. list_del(&packet->node);
  1287. iwm_rx_process_packet(iwm, packet, ticket);
  1288. }
  1289. }