rx.c 48 KB

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