rx.c 48 KB

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