rx.c 40 KB

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