rx.c 46 KB

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