rx.c 48 KB

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