2 * Intel Wireless Multicomm 3200 WiFi driver
4 * Copyright (C) 2009 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
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.
33 * Intel Corporation <ilw@linux.intel.com>
34 * Samuel Ortiz <samuel.ortiz@intel.com>
35 * Zhu Yi <yi.zhu@intel.com>
39 #include <linux/kernel.h>
40 #include <linux/netdevice.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>
58 static int iwm_rx_check_udma_hdr(struct iwm_udma_in_hdr *hdr)
60 if ((le32_to_cpu(hdr->cmd) == UMAC_PAD_TERMINAL) ||
61 (le32_to_cpu(hdr->size) == UMAC_PAD_TERMINAL))
67 static inline int iwm_rx_resp_size(struct iwm_udma_in_hdr *hdr)
69 return ALIGN(le32_to_cpu(hdr->size) + sizeof(struct iwm_udma_in_hdr),
74 * Notification handlers:
76 * For every possible notification we can receive from the
77 * target, we have a handler.
78 * When we get a target notification, and there is no one
79 * waiting for it, it's just processed through the rx code
83 * -> iwm_rx_handle_umac()
84 * -> iwm_rx_handle_wifi()
85 * -> iwm_rx_handle_resp()
90 * -> iwm_rx_handle_non_wifi()
92 * If there are processes waiting for this notification, then
93 * iwm_rx_handle_wifi() just wakes those processes up and they
94 * grab the pending notification.
96 static int iwm_ntf_error(struct iwm_priv *iwm, u8 *buf,
97 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
99 struct iwm_umac_notif_error *error;
100 struct iwm_fw_error_hdr *fw_err;
102 error = (struct iwm_umac_notif_error *)buf;
103 fw_err = &error->err;
105 memcpy(iwm->last_fw_err, fw_err, sizeof(struct iwm_fw_error_hdr));
107 IWM_ERR(iwm, "%cMAC FW ERROR:\n",
108 (le32_to_cpu(fw_err->category) == UMAC_SYS_ERR_CAT_LMAC) ? 'L' : 'U');
109 IWM_ERR(iwm, "\tCategory: %d\n", le32_to_cpu(fw_err->category));
110 IWM_ERR(iwm, "\tStatus: 0x%x\n", le32_to_cpu(fw_err->status));
111 IWM_ERR(iwm, "\tPC: 0x%x\n", le32_to_cpu(fw_err->pc));
112 IWM_ERR(iwm, "\tblink1: %d\n", le32_to_cpu(fw_err->blink1));
113 IWM_ERR(iwm, "\tblink2: %d\n", le32_to_cpu(fw_err->blink2));
114 IWM_ERR(iwm, "\tilink1: %d\n", le32_to_cpu(fw_err->ilink1));
115 IWM_ERR(iwm, "\tilink2: %d\n", le32_to_cpu(fw_err->ilink2));
116 IWM_ERR(iwm, "\tData1: 0x%x\n", le32_to_cpu(fw_err->data1));
117 IWM_ERR(iwm, "\tData2: 0x%x\n", le32_to_cpu(fw_err->data2));
118 IWM_ERR(iwm, "\tLine number: %d\n", le32_to_cpu(fw_err->line_num));
119 IWM_ERR(iwm, "\tUMAC status: 0x%x\n", le32_to_cpu(fw_err->umac_status));
120 IWM_ERR(iwm, "\tLMAC status: 0x%x\n", le32_to_cpu(fw_err->lmac_status));
121 IWM_ERR(iwm, "\tSDIO status: 0x%x\n", le32_to_cpu(fw_err->sdio_status));
128 static int iwm_ntf_umac_alive(struct iwm_priv *iwm, u8 *buf,
129 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
131 struct iwm_umac_notif_alive *alive_resp =
132 (struct iwm_umac_notif_alive *)(buf);
133 u16 status = le16_to_cpu(alive_resp->status);
135 if (status == UMAC_NTFY_ALIVE_STATUS_ERR) {
136 IWM_ERR(iwm, "Receive error UMAC_ALIVE\n");
140 iwm_tx_credit_init_pools(iwm, alive_resp);
145 static int iwm_ntf_init_complete(struct iwm_priv *iwm, u8 *buf,
146 unsigned long buf_size,
147 struct iwm_wifi_cmd *cmd)
149 struct wiphy *wiphy = iwm_to_wiphy(iwm);
150 struct iwm_umac_notif_init_complete *init_complete =
151 (struct iwm_umac_notif_init_complete *)(buf);
152 u16 status = le16_to_cpu(init_complete->status);
153 bool blocked = (status == UMAC_NTFY_INIT_COMPLETE_STATUS_ERR);
156 IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is on (radio off)\n");
158 IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is off (radio on)\n");
160 wiphy_rfkill_set_hw_state(wiphy, blocked);
165 static int iwm_ntf_tx_credit_update(struct iwm_priv *iwm, u8 *buf,
166 unsigned long buf_size,
167 struct iwm_wifi_cmd *cmd)
169 int pool_nr, total_freed_pages;
170 unsigned long pool_map;
172 struct iwm_umac_notif_page_dealloc *dealloc =
173 (struct iwm_umac_notif_page_dealloc *)buf;
175 pool_nr = GET_VAL32(dealloc->changes, UMAC_DEALLOC_NTFY_CHANGES_CNT);
176 pool_map = GET_VAL32(dealloc->changes, UMAC_DEALLOC_NTFY_CHANGES_MSK);
178 IWM_DBG_TX(iwm, DBG, "UMAC dealloc notification: pool nr %d, "
179 "update map 0x%lx\n", pool_nr, pool_map);
181 spin_lock(&iwm->tx_credit.lock);
183 for (i = 0; i < pool_nr; i++) {
184 id = GET_VAL32(dealloc->grp_info[i],
185 UMAC_DEALLOC_NTFY_GROUP_NUM);
186 if (test_bit(id, &pool_map)) {
187 total_freed_pages = GET_VAL32(dealloc->grp_info[i],
188 UMAC_DEALLOC_NTFY_PAGE_CNT);
189 iwm_tx_credit_inc(iwm, id, total_freed_pages);
193 spin_unlock(&iwm->tx_credit.lock);
198 static int iwm_ntf_umac_reset(struct iwm_priv *iwm, u8 *buf,
199 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
201 IWM_DBG_NTF(iwm, DBG, "UMAC RESET done\n");
206 static int iwm_ntf_lmac_version(struct iwm_priv *iwm, u8 *buf,
207 unsigned long buf_size,
208 struct iwm_wifi_cmd *cmd)
210 IWM_DBG_NTF(iwm, INFO, "LMAC Version: %x.%x\n", buf[9], buf[8]);
215 static int iwm_ntf_tx(struct iwm_priv *iwm, u8 *buf,
216 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
218 struct iwm_lmac_tx_resp *tx_resp;
219 struct iwm_umac_wifi_in_hdr *hdr;
221 tx_resp = (struct iwm_lmac_tx_resp *)
222 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
223 hdr = (struct iwm_umac_wifi_in_hdr *)buf;
225 IWM_DBG_TX(iwm, DBG, "REPLY_TX, buf size: %lu\n", buf_size);
227 IWM_DBG_TX(iwm, DBG, "Seqnum: %d\n",
228 le16_to_cpu(hdr->sw_hdr.cmd.seq_num));
229 IWM_DBG_TX(iwm, DBG, "\tFrame cnt: %d\n", tx_resp->frame_cnt);
230 IWM_DBG_TX(iwm, DBG, "\tRetry cnt: %d\n",
231 le16_to_cpu(tx_resp->retry_cnt));
232 IWM_DBG_TX(iwm, DBG, "\tSeq ctl: %d\n", le16_to_cpu(tx_resp->seq_ctl));
233 IWM_DBG_TX(iwm, DBG, "\tByte cnt: %d\n",
234 le16_to_cpu(tx_resp->byte_cnt));
235 IWM_DBG_TX(iwm, DBG, "\tStatus: 0x%x\n", le32_to_cpu(tx_resp->status));
241 static int iwm_ntf_calib_res(struct iwm_priv *iwm, u8 *buf,
242 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
246 struct iwm_lmac_calib_hdr *hdr = (struct iwm_lmac_calib_hdr *)
247 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
249 opcode = hdr->opcode;
251 BUG_ON(opcode >= CALIBRATION_CMD_NUM ||
252 opcode < PHY_CALIBRATE_OPCODES_NUM);
254 IWM_DBG_NTF(iwm, DBG, "Store calibration result for opcode: %d\n",
257 buf_size -= sizeof(struct iwm_umac_wifi_in_hdr);
258 calib_buf = iwm->calib_res[opcode].buf;
260 if (!calib_buf || (iwm->calib_res[opcode].size < buf_size)) {
262 calib_buf = kzalloc(buf_size, GFP_KERNEL);
264 IWM_ERR(iwm, "Memory allocation failed: calib_res\n");
267 iwm->calib_res[opcode].buf = calib_buf;
268 iwm->calib_res[opcode].size = buf_size;
271 memcpy(calib_buf, hdr, buf_size);
272 set_bit(opcode - PHY_CALIBRATE_OPCODES_NUM, &iwm->calib_done_map);
277 static int iwm_ntf_calib_complete(struct iwm_priv *iwm, u8 *buf,
278 unsigned long buf_size,
279 struct iwm_wifi_cmd *cmd)
281 IWM_DBG_NTF(iwm, DBG, "Calibration completed\n");
286 static int iwm_ntf_calib_cfg(struct iwm_priv *iwm, u8 *buf,
287 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
289 struct iwm_lmac_cal_cfg_resp *cal_resp;
291 cal_resp = (struct iwm_lmac_cal_cfg_resp *)
292 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
294 IWM_DBG_NTF(iwm, DBG, "Calibration CFG command status: %d\n",
295 le32_to_cpu(cal_resp->status));
300 static int iwm_ntf_wifi_status(struct iwm_priv *iwm, u8 *buf,
301 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
303 struct iwm_umac_notif_wifi_status *status =
304 (struct iwm_umac_notif_wifi_status *)buf;
306 iwm->core_enabled |= le16_to_cpu(status->status);
311 static struct iwm_rx_ticket_node *
312 iwm_rx_ticket_node_alloc(struct iwm_priv *iwm, struct iwm_rx_ticket *ticket)
314 struct iwm_rx_ticket_node *ticket_node;
316 ticket_node = kzalloc(sizeof(struct iwm_rx_ticket_node), GFP_KERNEL);
318 IWM_ERR(iwm, "Couldn't allocate ticket node\n");
319 return ERR_PTR(-ENOMEM);
322 ticket_node->ticket = kzalloc(sizeof(struct iwm_rx_ticket), GFP_KERNEL);
323 if (!ticket_node->ticket) {
324 IWM_ERR(iwm, "Couldn't allocate RX ticket\n");
326 return ERR_PTR(-ENOMEM);
329 memcpy(ticket_node->ticket, ticket, sizeof(struct iwm_rx_ticket));
330 INIT_LIST_HEAD(&ticket_node->node);
335 static void iwm_rx_ticket_node_free(struct iwm_rx_ticket_node *ticket_node)
337 kfree(ticket_node->ticket);
341 static struct iwm_rx_packet *iwm_rx_packet_get(struct iwm_priv *iwm, u16 id)
343 u8 id_hash = IWM_RX_ID_GET_HASH(id);
344 struct list_head *packet_list;
345 struct iwm_rx_packet *packet, *next;
347 packet_list = &iwm->rx_packets[id_hash];
349 list_for_each_entry_safe(packet, next, packet_list, node)
350 if (packet->id == id)
356 static struct iwm_rx_packet *iwm_rx_packet_alloc(struct iwm_priv *iwm, u8 *buf,
359 struct iwm_rx_packet *packet;
361 packet = kzalloc(sizeof(struct iwm_rx_packet), GFP_KERNEL);
363 IWM_ERR(iwm, "Couldn't allocate packet\n");
364 return ERR_PTR(-ENOMEM);
367 packet->skb = dev_alloc_skb(size);
369 IWM_ERR(iwm, "Couldn't allocate packet SKB\n");
371 return ERR_PTR(-ENOMEM);
374 packet->pkt_size = size;
376 skb_put(packet->skb, size);
377 memcpy(packet->skb->data, buf, size);
378 INIT_LIST_HEAD(&packet->node);
384 void iwm_rx_free(struct iwm_priv *iwm)
386 struct iwm_rx_ticket_node *ticket, *nt;
387 struct iwm_rx_packet *packet, *np;
390 list_for_each_entry_safe(ticket, nt, &iwm->rx_tickets, node) {
391 list_del(&ticket->node);
392 iwm_rx_ticket_node_free(ticket);
395 for (i = 0; i < IWM_RX_ID_HASH; i++) {
396 list_for_each_entry_safe(packet, np, &iwm->rx_packets[i],
398 list_del(&packet->node);
399 kfree_skb(packet->skb);
405 static int iwm_ntf_rx_ticket(struct iwm_priv *iwm, u8 *buf,
406 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
408 struct iwm_umac_notif_rx_ticket *ntf_rx_ticket =
409 (struct iwm_umac_notif_rx_ticket *)buf;
410 struct iwm_rx_ticket *ticket =
411 (struct iwm_rx_ticket *)ntf_rx_ticket->tickets;
412 int i, schedule_rx = 0;
414 for (i = 0; i < ntf_rx_ticket->num_tickets; i++) {
415 struct iwm_rx_ticket_node *ticket_node;
417 switch (le16_to_cpu(ticket->action)) {
418 case IWM_RX_TICKET_RELEASE:
419 case IWM_RX_TICKET_DROP:
420 /* We can push the packet to the stack */
421 ticket_node = iwm_rx_ticket_node_alloc(iwm, ticket);
422 if (IS_ERR(ticket_node))
423 return PTR_ERR(ticket_node);
425 IWM_DBG_RX(iwm, DBG, "TICKET RELEASE(%d)\n",
427 list_add_tail(&ticket_node->node, &iwm->rx_tickets);
430 * We received an Rx ticket, most likely there's
431 * a packet pending for it, it's not worth going
432 * through the packet hash list to double check.
433 * Let's just fire the rx worker..
440 IWM_ERR(iwm, "Invalid RX ticket action: 0x%x\n",
448 queue_work(iwm->rx_wq, &iwm->rx_worker);
453 static int iwm_ntf_rx_packet(struct iwm_priv *iwm, u8 *buf,
454 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
456 struct iwm_umac_wifi_in_hdr *wifi_hdr;
457 struct iwm_rx_packet *packet;
461 IWM_DBG_RX(iwm, DBG, "\n");
463 wifi_hdr = (struct iwm_umac_wifi_in_hdr *)buf;
464 id = le16_to_cpu(wifi_hdr->sw_hdr.cmd.seq_num);
465 buf_offset = sizeof(struct iwm_umac_wifi_in_hdr);
466 packet_size = buf_size - sizeof(struct iwm_umac_wifi_in_hdr);
468 IWM_DBG_RX(iwm, DBG, "CMD:0x%x, seqnum: %d, packet size: %d\n",
469 wifi_hdr->sw_hdr.cmd.cmd, id, packet_size);
470 IWM_DBG_RX(iwm, DBG, "Packet id: %d\n", id);
471 IWM_HEXDUMP(iwm, DBG, RX, "PACKET: ", buf + buf_offset, packet_size);
473 packet = iwm_rx_packet_alloc(iwm, buf + buf_offset, packet_size, id);
475 return PTR_ERR(packet);
477 list_add_tail(&packet->node, &iwm->rx_packets[IWM_RX_ID_GET_HASH(id)]);
479 /* We might (unlikely) have received the packet _after_ the ticket */
480 queue_work(iwm->rx_wq, &iwm->rx_worker);
486 static int iwm_mlme_assoc_start(struct iwm_priv *iwm, u8 *buf,
487 unsigned long buf_size,
488 struct iwm_wifi_cmd *cmd)
490 struct iwm_umac_notif_assoc_start *start;
492 start = (struct iwm_umac_notif_assoc_start *)buf;
494 IWM_DBG_MLME(iwm, INFO, "Association with %pM Started, reason: %d\n",
495 start->bssid, le32_to_cpu(start->roam_reason));
497 wake_up_interruptible(&iwm->mlme_queue);
502 static int iwm_mlme_assoc_complete(struct iwm_priv *iwm, u8 *buf,
503 unsigned long buf_size,
504 struct iwm_wifi_cmd *cmd)
506 struct iwm_umac_notif_assoc_complete *complete =
507 (struct iwm_umac_notif_assoc_complete *)buf;
509 IWM_DBG_MLME(iwm, INFO, "Association with %pM completed, status: %d\n",
510 complete->bssid, complete->status);
512 switch (le32_to_cpu(complete->status)) {
513 case UMAC_ASSOC_COMPLETE_SUCCESS:
514 set_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
515 memcpy(iwm->bssid, complete->bssid, ETH_ALEN);
516 iwm->channel = complete->channel;
518 /* Internal roaming state, avoid notifying SME. */
519 if (!test_and_clear_bit(IWM_STATUS_SME_CONNECTING, &iwm->status)
520 && iwm->conf.mode == UMAC_MODE_BSS) {
521 cancel_delayed_work(&iwm->disconnect);
522 cfg80211_roamed(iwm_to_ndev(iwm),
524 iwm->req_ie, iwm->req_ie_len,
525 iwm->resp_ie, iwm->resp_ie_len,
532 if (iwm->conf.mode == UMAC_MODE_IBSS)
535 if (!test_bit(IWM_STATUS_RESETTING, &iwm->status))
536 cfg80211_connect_result(iwm_to_ndev(iwm),
538 iwm->req_ie, iwm->req_ie_len,
539 iwm->resp_ie, iwm->resp_ie_len,
543 cfg80211_roamed(iwm_to_ndev(iwm),
545 iwm->req_ie, iwm->req_ie_len,
546 iwm->resp_ie, iwm->resp_ie_len,
549 case UMAC_ASSOC_COMPLETE_FAILURE:
550 clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
551 memset(iwm->bssid, 0, ETH_ALEN);
554 /* Internal roaming state, avoid notifying SME. */
555 if (!test_and_clear_bit(IWM_STATUS_SME_CONNECTING, &iwm->status)
556 && iwm->conf.mode == UMAC_MODE_BSS) {
557 cancel_delayed_work(&iwm->disconnect);
563 if (iwm->conf.mode == UMAC_MODE_IBSS)
566 if (!test_bit(IWM_STATUS_RESETTING, &iwm->status))
567 cfg80211_connect_result(iwm_to_ndev(iwm),
570 WLAN_STATUS_UNSPECIFIED_FAILURE,
573 cfg80211_disconnected(iwm_to_ndev(iwm), 0, NULL, 0,
580 clear_bit(IWM_STATUS_RESETTING, &iwm->status);
584 cfg80211_ibss_joined(iwm_to_ndev(iwm), iwm->bssid, GFP_KERNEL);
585 clear_bit(IWM_STATUS_RESETTING, &iwm->status);
589 static int iwm_mlme_profile_invalidate(struct iwm_priv *iwm, u8 *buf,
590 unsigned long buf_size,
591 struct iwm_wifi_cmd *cmd)
593 struct iwm_umac_notif_profile_invalidate *invalid;
596 invalid = (struct iwm_umac_notif_profile_invalidate *)buf;
597 reason = le32_to_cpu(invalid->reason);
599 IWM_DBG_MLME(iwm, INFO, "Profile Invalidated. Reason: %d\n", reason);
601 if (reason != UMAC_PROFILE_INVALID_REQUEST &&
602 test_bit(IWM_STATUS_SME_CONNECTING, &iwm->status))
603 cfg80211_connect_result(iwm_to_ndev(iwm), NULL, NULL, 0, NULL,
604 0, WLAN_STATUS_UNSPECIFIED_FAILURE,
607 clear_bit(IWM_STATUS_SME_CONNECTING, &iwm->status);
608 clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
610 iwm->umac_profile_active = 0;
611 memset(iwm->bssid, 0, ETH_ALEN);
616 wake_up_interruptible(&iwm->mlme_queue);
621 #define IWM_DISCONNECT_INTERVAL (5 * HZ)
623 static int iwm_mlme_connection_terminated(struct iwm_priv *iwm, u8 *buf,
624 unsigned long buf_size,
625 struct iwm_wifi_cmd *cmd)
627 IWM_DBG_MLME(iwm, DBG, "Connection terminated\n");
629 schedule_delayed_work(&iwm->disconnect, IWM_DISCONNECT_INTERVAL);
634 static int iwm_mlme_scan_complete(struct iwm_priv *iwm, u8 *buf,
635 unsigned long buf_size,
636 struct iwm_wifi_cmd *cmd)
639 struct iwm_umac_notif_scan_complete *scan_complete =
640 (struct iwm_umac_notif_scan_complete *)buf;
641 u32 result = le32_to_cpu(scan_complete->result);
643 IWM_DBG_MLME(iwm, INFO, "type:0x%x result:0x%x seq:%d\n",
644 le32_to_cpu(scan_complete->type),
645 le32_to_cpu(scan_complete->result),
646 scan_complete->seq_num);
648 if (!test_and_clear_bit(IWM_STATUS_SCANNING, &iwm->status)) {
649 IWM_ERR(iwm, "Scan complete while device not scanning\n");
652 if (!iwm->scan_request)
655 ret = iwm_cfg80211_inform_bss(iwm);
657 cfg80211_scan_done(iwm->scan_request,
658 (result & UMAC_SCAN_RESULT_ABORTED) ? 1 : !!ret);
659 iwm->scan_request = NULL;
664 static int iwm_mlme_update_sta_table(struct iwm_priv *iwm, u8 *buf,
665 unsigned long buf_size,
666 struct iwm_wifi_cmd *cmd)
668 struct iwm_umac_notif_sta_info *umac_sta =
669 (struct iwm_umac_notif_sta_info *)buf;
670 struct iwm_sta_info *sta;
673 switch (le32_to_cpu(umac_sta->opcode)) {
674 case UMAC_OPCODE_ADD_MODIFY:
675 sta = &iwm->sta_table[GET_VAL8(umac_sta->sta_id, LMAC_STA_ID)];
677 IWM_DBG_MLME(iwm, INFO, "%s STA: ID = %d, Color = %d, "
678 "addr = %pM, qos = %d\n",
679 sta->valid ? "Modify" : "Add",
680 GET_VAL8(umac_sta->sta_id, LMAC_STA_ID),
681 GET_VAL8(umac_sta->sta_id, LMAC_STA_COLOR),
683 umac_sta->flags & UMAC_STA_FLAG_QOS);
686 sta->qos = umac_sta->flags & UMAC_STA_FLAG_QOS;
687 sta->color = GET_VAL8(umac_sta->sta_id, LMAC_STA_COLOR);
688 memcpy(sta->addr, umac_sta->mac_addr, ETH_ALEN);
690 case UMAC_OPCODE_REMOVE:
691 IWM_DBG_MLME(iwm, INFO, "Remove STA: ID = %d, Color = %d, "
693 GET_VAL8(umac_sta->sta_id, LMAC_STA_ID),
694 GET_VAL8(umac_sta->sta_id, LMAC_STA_COLOR),
697 sta = &iwm->sta_table[GET_VAL8(umac_sta->sta_id, LMAC_STA_ID)];
699 if (!memcmp(sta->addr, umac_sta->mac_addr, ETH_ALEN))
703 case UMAC_OPCODE_CLEAR_ALL:
704 for (i = 0; i < IWM_STA_TABLE_NUM; i++)
705 iwm->sta_table[i].valid = 0;
715 static int iwm_mlme_update_bss_table(struct iwm_priv *iwm, u8 *buf,
716 unsigned long buf_size,
717 struct iwm_wifi_cmd *cmd)
719 struct wiphy *wiphy = iwm_to_wiphy(iwm);
720 struct ieee80211_mgmt *mgmt;
721 struct iwm_umac_notif_bss_info *umac_bss =
722 (struct iwm_umac_notif_bss_info *)buf;
723 struct ieee80211_channel *channel;
724 struct ieee80211_supported_band *band;
725 struct iwm_bss_info *bss, *next;
728 u16 frame_len = le16_to_cpu(umac_bss->frame_len);
729 size_t bss_len = sizeof(struct iwm_umac_notif_bss_info) + frame_len;
731 mgmt = (struct ieee80211_mgmt *)(umac_bss->frame_buf);
733 IWM_DBG_MLME(iwm, DBG, "New BSS info entry: %pM\n", mgmt->bssid);
734 IWM_DBG_MLME(iwm, DBG, "\tType: 0x%x\n", le32_to_cpu(umac_bss->type));
735 IWM_DBG_MLME(iwm, DBG, "\tTimestamp: %d\n",
736 le32_to_cpu(umac_bss->timestamp));
737 IWM_DBG_MLME(iwm, DBG, "\tTable Index: %d\n",
738 le16_to_cpu(umac_bss->table_idx));
739 IWM_DBG_MLME(iwm, DBG, "\tBand: %d\n", umac_bss->band);
740 IWM_DBG_MLME(iwm, DBG, "\tChannel: %d\n", umac_bss->channel);
741 IWM_DBG_MLME(iwm, DBG, "\tRSSI: %d\n", umac_bss->rssi);
742 IWM_DBG_MLME(iwm, DBG, "\tFrame Length: %d\n", frame_len);
744 list_for_each_entry_safe(bss, next, &iwm->bss_list, node)
745 if (bss->bss->table_idx == umac_bss->table_idx)
748 if (&bss->node != &iwm->bss_list) {
749 /* Remove the old BSS entry, we will add it back later. */
750 list_del(&bss->node);
755 bss = kzalloc(sizeof(struct iwm_bss_info), GFP_KERNEL);
757 IWM_ERR(iwm, "Couldn't allocate bss_info\n");
762 bss->bss = kzalloc(bss_len, GFP_KERNEL);
765 IWM_ERR(iwm, "Couldn't allocate bss\n");
769 INIT_LIST_HEAD(&bss->node);
770 memcpy(bss->bss, umac_bss, bss_len);
772 if (umac_bss->band == UMAC_BAND_2GHZ)
773 band = wiphy->bands[IEEE80211_BAND_2GHZ];
774 else if (umac_bss->band == UMAC_BAND_5GHZ)
775 band = wiphy->bands[IEEE80211_BAND_5GHZ];
777 IWM_ERR(iwm, "Invalid band: %d\n", umac_bss->band);
781 freq = ieee80211_channel_to_frequency(umac_bss->channel);
782 channel = ieee80211_get_channel(wiphy, freq);
783 signal = umac_bss->rssi * 100;
785 bss->cfg_bss = cfg80211_inform_bss_frame(wiphy, channel,
791 list_add_tail(&bss->node, &iwm->bss_list);
801 static int iwm_mlme_remove_bss(struct iwm_priv *iwm, u8 *buf,
802 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
804 struct iwm_umac_notif_bss_removed *bss_rm =
805 (struct iwm_umac_notif_bss_removed *)buf;
806 struct iwm_bss_info *bss, *next;
810 for (i = 0; i < le32_to_cpu(bss_rm->count); i++) {
811 table_idx = (le16_to_cpu(bss_rm->entries[i])
812 & IWM_BSS_REMOVE_INDEX_MSK);
813 list_for_each_entry_safe(bss, next, &iwm->bss_list, node)
814 if (bss->bss->table_idx == cpu_to_le16(table_idx)) {
815 struct ieee80211_mgmt *mgmt;
817 mgmt = (struct ieee80211_mgmt *)
818 (bss->bss->frame_buf);
819 IWM_DBG_MLME(iwm, ERR,
820 "BSS removed: %pM\n",
822 list_del(&bss->node);
831 static int iwm_mlme_mgt_frame(struct iwm_priv *iwm, u8 *buf,
832 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
834 struct iwm_umac_notif_mgt_frame *mgt_frame =
835 (struct iwm_umac_notif_mgt_frame *)buf;
836 struct ieee80211_mgmt *mgt = (struct ieee80211_mgmt *)mgt_frame->frame;
839 IWM_HEXDUMP(iwm, DBG, MLME, "MGT: ", mgt_frame->frame,
840 le16_to_cpu(mgt_frame->len));
842 if (ieee80211_is_assoc_req(mgt->frame_control)) {
843 ie = mgt->u.assoc_req.variable;;
845 le16_to_cpu(mgt_frame->len) - (ie - (u8 *)mgt);
847 iwm->req_ie = kmemdup(mgt->u.assoc_req.variable,
848 iwm->req_ie_len, GFP_KERNEL);
849 } else if (ieee80211_is_reassoc_req(mgt->frame_control)) {
850 ie = mgt->u.reassoc_req.variable;;
852 le16_to_cpu(mgt_frame->len) - (ie - (u8 *)mgt);
854 iwm->req_ie = kmemdup(mgt->u.reassoc_req.variable,
855 iwm->req_ie_len, GFP_KERNEL);
856 } else if (ieee80211_is_assoc_resp(mgt->frame_control)) {
857 ie = mgt->u.assoc_resp.variable;;
859 le16_to_cpu(mgt_frame->len) - (ie - (u8 *)mgt);
861 iwm->resp_ie = kmemdup(mgt->u.assoc_resp.variable,
862 iwm->resp_ie_len, GFP_KERNEL);
863 } else if (ieee80211_is_reassoc_resp(mgt->frame_control)) {
864 ie = mgt->u.reassoc_resp.variable;;
866 le16_to_cpu(mgt_frame->len) - (ie - (u8 *)mgt);
868 iwm->resp_ie = kmemdup(mgt->u.reassoc_resp.variable,
869 iwm->resp_ie_len, GFP_KERNEL);
871 IWM_ERR(iwm, "Unsupported management frame: 0x%x",
872 le16_to_cpu(mgt->frame_control));
879 static int iwm_ntf_mlme(struct iwm_priv *iwm, u8 *buf,
880 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
882 struct iwm_umac_notif_wifi_if *notif =
883 (struct iwm_umac_notif_wifi_if *)buf;
885 switch (notif->status) {
886 case WIFI_IF_NTFY_ASSOC_START:
887 return iwm_mlme_assoc_start(iwm, buf, buf_size, cmd);
888 case WIFI_IF_NTFY_ASSOC_COMPLETE:
889 return iwm_mlme_assoc_complete(iwm, buf, buf_size, cmd);
890 case WIFI_IF_NTFY_PROFILE_INVALIDATE_COMPLETE:
891 return iwm_mlme_profile_invalidate(iwm, buf, buf_size, cmd);
892 case WIFI_IF_NTFY_CONNECTION_TERMINATED:
893 return iwm_mlme_connection_terminated(iwm, buf, buf_size, cmd);
894 case WIFI_IF_NTFY_SCAN_COMPLETE:
895 return iwm_mlme_scan_complete(iwm, buf, buf_size, cmd);
896 case WIFI_IF_NTFY_STA_TABLE_CHANGE:
897 return iwm_mlme_update_sta_table(iwm, buf, buf_size, cmd);
898 case WIFI_IF_NTFY_EXTENDED_IE_REQUIRED:
899 IWM_DBG_MLME(iwm, DBG, "Extended IE required\n");
901 case WIFI_IF_NTFY_BSS_TRK_TABLE_CHANGED:
902 return iwm_mlme_update_bss_table(iwm, buf, buf_size, cmd);
903 case WIFI_IF_NTFY_BSS_TRK_ENTRIES_REMOVED:
904 return iwm_mlme_remove_bss(iwm, buf, buf_size, cmd);
906 case WIFI_IF_NTFY_MGMT_FRAME:
907 return iwm_mlme_mgt_frame(iwm, buf, buf_size, cmd);
908 case WIFI_DBG_IF_NTFY_SCAN_SUPER_JOB_START:
909 case WIFI_DBG_IF_NTFY_SCAN_SUPER_JOB_COMPLETE:
910 case WIFI_DBG_IF_NTFY_SCAN_CHANNEL_START:
911 case WIFI_DBG_IF_NTFY_SCAN_CHANNEL_RESULT:
912 case WIFI_DBG_IF_NTFY_SCAN_MINI_JOB_START:
913 case WIFI_DBG_IF_NTFY_SCAN_MINI_JOB_COMPLETE:
914 case WIFI_DBG_IF_NTFY_CNCT_ATC_START:
915 case WIFI_DBG_IF_NTFY_COEX_NOTIFICATION:
916 case WIFI_DBG_IF_NTFY_COEX_HANDLE_ENVELOP:
917 case WIFI_DBG_IF_NTFY_COEX_HANDLE_RELEASE_ENVELOP:
918 IWM_DBG_MLME(iwm, DBG, "MLME debug notification: 0x%x\n",
922 IWM_ERR(iwm, "Unhandled notification: 0x%x\n", notif->status);
929 #define IWM_STATS_UPDATE_INTERVAL (2 * HZ)
931 static int iwm_ntf_statistics(struct iwm_priv *iwm, u8 *buf,
932 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
934 struct iwm_umac_notif_stats *stats = (struct iwm_umac_notif_stats *)buf;
935 struct iw_statistics *wstats = &iwm->wstats;
939 IWM_DBG_MLME(iwm, DBG, "Statistics notification received\n");
941 if (test_bit(IWM_STATUS_ASSOCIATED, &iwm->status)) {
942 for (i = 0; i < UMAC_NTF_RATE_SAMPLE_NR; i++) {
943 max_rate = max_t(u16, max_rate,
944 max(le16_to_cpu(stats->tx_rate[i]),
945 le16_to_cpu(stats->rx_rate[i])));
947 /* UMAC passes rate info multiplies by 2 */
948 iwm->rate = max_rate >> 1;
950 iwm->txpower = le32_to_cpu(stats->tx_power);
954 wstats->discard.nwid = le32_to_cpu(stats->rx_drop_other_bssid);
955 wstats->discard.code = le32_to_cpu(stats->rx_drop_decode);
956 wstats->discard.fragment = le32_to_cpu(stats->rx_drop_reassembly);
957 wstats->discard.retries = le32_to_cpu(stats->tx_drop_max_retry);
959 wstats->miss.beacon = le32_to_cpu(stats->missed_beacons);
961 /* according to cfg80211 */
962 if (stats->rssi_dbm < -110)
963 wstats->qual.qual = 0;
964 else if (stats->rssi_dbm > -40)
965 wstats->qual.qual = 70;
967 wstats->qual.qual = stats->rssi_dbm + 110;
969 wstats->qual.level = stats->rssi_dbm;
970 wstats->qual.noise = stats->noise_dbm;
971 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
973 schedule_delayed_work(&iwm->stats_request, IWM_STATS_UPDATE_INTERVAL);
975 mod_timer(&iwm->watchdog, round_jiffies(jiffies + IWM_WATCHDOG_PERIOD));
980 static int iwm_ntf_eeprom_proxy(struct iwm_priv *iwm, u8 *buf,
981 unsigned long buf_size,
982 struct iwm_wifi_cmd *cmd)
984 struct iwm_umac_cmd_eeprom_proxy *eeprom_proxy =
985 (struct iwm_umac_cmd_eeprom_proxy *)
986 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
987 struct iwm_umac_cmd_eeprom_proxy_hdr *hdr = &eeprom_proxy->hdr;
988 u32 hdr_offset = le32_to_cpu(hdr->offset);
989 u32 hdr_len = le32_to_cpu(hdr->len);
990 u32 hdr_type = le32_to_cpu(hdr->type);
992 IWM_DBG_NTF(iwm, DBG, "type: 0x%x, len: %d, offset: 0x%x\n",
993 hdr_type, hdr_len, hdr_offset);
995 if ((hdr_offset + hdr_len) > IWM_EEPROM_LEN)
999 case IWM_UMAC_CMD_EEPROM_TYPE_READ:
1000 memcpy(iwm->eeprom + hdr_offset, eeprom_proxy->buf, hdr_len);
1002 case IWM_UMAC_CMD_EEPROM_TYPE_WRITE:
1010 static int iwm_ntf_channel_info_list(struct iwm_priv *iwm, u8 *buf,
1011 unsigned long buf_size,
1012 struct iwm_wifi_cmd *cmd)
1014 struct iwm_umac_cmd_get_channel_list *ch_list =
1015 (struct iwm_umac_cmd_get_channel_list *)
1016 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
1017 struct wiphy *wiphy = iwm_to_wiphy(iwm);
1018 struct ieee80211_supported_band *band;
1021 band = wiphy->bands[IEEE80211_BAND_2GHZ];
1023 for (i = 0; i < band->n_channels; i++) {
1024 unsigned long ch_mask_0 =
1025 le32_to_cpu(ch_list->ch[0].channels_mask);
1026 unsigned long ch_mask_2 =
1027 le32_to_cpu(ch_list->ch[2].channels_mask);
1029 if (!test_bit(i, &ch_mask_0))
1030 band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
1032 if (!test_bit(i, &ch_mask_2))
1033 band->channels[i].flags |= IEEE80211_CHAN_NO_IBSS;
1036 band = wiphy->bands[IEEE80211_BAND_5GHZ];
1038 for (i = 0; i < min(band->n_channels, 32); i++) {
1039 unsigned long ch_mask_1 =
1040 le32_to_cpu(ch_list->ch[1].channels_mask);
1041 unsigned long ch_mask_3 =
1042 le32_to_cpu(ch_list->ch[3].channels_mask);
1044 if (!test_bit(i, &ch_mask_1))
1045 band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
1047 if (!test_bit(i, &ch_mask_3))
1048 band->channels[i].flags |= IEEE80211_CHAN_NO_IBSS;
1054 static int iwm_ntf_wifi_if_wrapper(struct iwm_priv *iwm, u8 *buf,
1055 unsigned long buf_size,
1056 struct iwm_wifi_cmd *cmd)
1058 struct iwm_umac_wifi_if *hdr =
1059 (struct iwm_umac_wifi_if *)cmd->buf.payload;
1061 IWM_DBG_NTF(iwm, DBG, "WIFI_IF_WRAPPER cmd is delivered to UMAC: "
1062 "oid is 0x%x\n", hdr->oid);
1064 if (hdr->oid <= WIFI_IF_NTFY_MAX) {
1065 set_bit(hdr->oid, &iwm->wifi_ntfy[0]);
1066 wake_up_interruptible(&iwm->wifi_ntfy_queue);
1071 case UMAC_WIFI_IF_CMD_SET_PROFILE:
1072 iwm->umac_profile_active = 1;
1081 #define CT_KILL_DELAY (30 * HZ)
1082 static int iwm_ntf_card_state(struct iwm_priv *iwm, u8 *buf,
1083 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
1085 struct wiphy *wiphy = iwm_to_wiphy(iwm);
1086 struct iwm_lmac_card_state *state = (struct iwm_lmac_card_state *)
1087 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
1088 u32 flags = le32_to_cpu(state->flags);
1090 IWM_INFO(iwm, "HW RF Kill %s, CT Kill %s\n",
1091 flags & IWM_CARD_STATE_HW_DISABLED ? "ON" : "OFF",
1092 flags & IWM_CARD_STATE_CTKILL_DISABLED ? "ON" : "OFF");
1094 if (flags & IWM_CARD_STATE_CTKILL_DISABLED) {
1096 * We got a CTKILL event: We bring the interface down in
1097 * oder to cool the device down, and try to bring it up
1098 * 30 seconds later. If it's still too hot, we'll go through
1099 * this code path again.
1101 cancel_delayed_work_sync(&iwm->ct_kill_delay);
1102 schedule_delayed_work(&iwm->ct_kill_delay, CT_KILL_DELAY);
1105 wiphy_rfkill_set_hw_state(wiphy, flags &
1106 (IWM_CARD_STATE_HW_DISABLED |
1107 IWM_CARD_STATE_CTKILL_DISABLED));
1112 static int iwm_rx_handle_wifi(struct iwm_priv *iwm, u8 *buf,
1113 unsigned long buf_size)
1115 struct iwm_umac_wifi_in_hdr *wifi_hdr;
1116 struct iwm_wifi_cmd *cmd;
1122 wifi_hdr = (struct iwm_umac_wifi_in_hdr *)buf;
1123 cmd_id = wifi_hdr->sw_hdr.cmd.cmd;
1125 source = GET_VAL32(wifi_hdr->hw_hdr.cmd, UMAC_HDI_IN_CMD_SOURCE);
1126 if (source >= IWM_SRC_NUM) {
1127 IWM_CRIT(iwm, "invalid source %d\n", source);
1131 count = (GET_VAL32(wifi_hdr->sw_hdr.meta_data, UMAC_FW_CMD_BYTE_COUNT));
1132 count += sizeof(struct iwm_umac_wifi_in_hdr) -
1133 sizeof(struct iwm_dev_cmd_hdr);
1134 if (count > buf_size) {
1135 IWM_CRIT(iwm, "count %d, buf size:%ld\n", count, buf_size);
1139 resp = GET_VAL32(wifi_hdr->sw_hdr.meta_data, UMAC_FW_CMD_STATUS);
1141 seq_num = le16_to_cpu(wifi_hdr->sw_hdr.cmd.seq_num);
1143 IWM_DBG_RX(iwm, DBG, "CMD:0x%x, source: 0x%x, seqnum: %d\n",
1144 cmd_id, source, seq_num);
1147 * If this is a response to a previously sent command, there must
1148 * be a pending command for this sequence number.
1150 cmd = iwm_get_pending_wifi_cmd(iwm, seq_num);
1152 /* Notify the caller only for sync commands. */
1154 case UMAC_HDI_IN_SOURCE_FHRX:
1155 if (iwm->lmac_handlers[cmd_id] &&
1156 test_bit(cmd_id, &iwm->lmac_handler_map[0]))
1157 return iwm_notif_send(iwm, cmd, cmd_id, source,
1160 case UMAC_HDI_IN_SOURCE_FW:
1161 if (iwm->umac_handlers[cmd_id] &&
1162 test_bit(cmd_id, &iwm->umac_handler_map[0]))
1163 return iwm_notif_send(iwm, cmd, cmd_id, source,
1166 case UMAC_HDI_IN_SOURCE_UDMA:
1170 return iwm_rx_handle_resp(iwm, buf, count, cmd);
1173 int iwm_rx_handle_resp(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size,
1174 struct iwm_wifi_cmd *cmd)
1177 struct iwm_umac_wifi_in_hdr *wifi_hdr;
1180 wifi_hdr = (struct iwm_umac_wifi_in_hdr *)buf;
1181 cmd_id = wifi_hdr->sw_hdr.cmd.cmd;
1183 source = GET_VAL32(wifi_hdr->hw_hdr.cmd, UMAC_HDI_IN_CMD_SOURCE);
1185 IWM_DBG_RX(iwm, DBG, "CMD:0x%x, source: 0x%x\n", cmd_id, source);
1188 case UMAC_HDI_IN_SOURCE_FHRX:
1189 if (iwm->lmac_handlers[cmd_id])
1190 ret = iwm->lmac_handlers[cmd_id]
1191 (iwm, buf, buf_size, cmd);
1193 case UMAC_HDI_IN_SOURCE_FW:
1194 if (iwm->umac_handlers[cmd_id])
1195 ret = iwm->umac_handlers[cmd_id]
1196 (iwm, buf, buf_size, cmd);
1198 case UMAC_HDI_IN_SOURCE_UDMA:
1208 static int iwm_rx_handle_nonwifi(struct iwm_priv *iwm, u8 *buf,
1209 unsigned long buf_size)
1212 struct iwm_udma_in_hdr *hdr = (struct iwm_udma_in_hdr *)buf;
1213 struct iwm_nonwifi_cmd *cmd, *next;
1215 seq_num = GET_VAL32(hdr->cmd, UDMA_HDI_IN_CMD_NON_WIFI_HW_SEQ_NUM);
1218 * We received a non wifi answer.
1219 * Let's check if there's a pending command for it, and if so
1220 * replace the command payload with the buffer, and then wake the
1222 * That means we only support synchronised non wifi command response
1225 list_for_each_entry_safe(cmd, next, &iwm->nonwifi_pending_cmd, pending)
1226 if (cmd->seq_num == seq_num) {
1227 cmd->resp_received = 1;
1228 cmd->buf.len = buf_size;
1229 memcpy(cmd->buf.hdr, buf, buf_size);
1230 wake_up_interruptible(&iwm->nonwifi_queue);
1236 static int iwm_rx_handle_umac(struct iwm_priv *iwm, u8 *buf,
1237 unsigned long buf_size)
1241 unsigned long buf_offset = 0;
1242 struct iwm_udma_in_hdr *hdr;
1245 * To allow for a more efficient bus usage, UMAC
1246 * messages are encapsulated into UDMA ones. This
1247 * way we can have several UMAC messages in one bus
1249 * A UDMA frame size is always aligned on 16 bytes,
1250 * and a UDMA frame must not start with a UMAC_PAD_TERMINAL
1251 * word. This is how we parse a bus frame into several
1254 while (buf_offset < buf_size) {
1256 hdr = (struct iwm_udma_in_hdr *)(buf + buf_offset);
1258 if (iwm_rx_check_udma_hdr(hdr) < 0) {
1259 IWM_DBG_RX(iwm, DBG, "End of frame\n");
1263 op_code = GET_VAL32(hdr->cmd, UMAC_HDI_IN_CMD_OPCODE);
1265 IWM_DBG_RX(iwm, DBG, "Op code: 0x%x\n", op_code);
1267 if (op_code == UMAC_HDI_IN_OPCODE_WIFI) {
1268 ret |= iwm_rx_handle_wifi(iwm, buf + buf_offset,
1269 buf_size - buf_offset);
1270 } else if (op_code < UMAC_HDI_IN_OPCODE_NONWIFI_MAX) {
1271 if (GET_VAL32(hdr->cmd,
1272 UDMA_HDI_IN_CMD_NON_WIFI_HW_SIG) !=
1273 UDMA_HDI_IN_CMD_NON_WIFI_HW_SIG) {
1274 IWM_ERR(iwm, "Incorrect hw signature\n");
1277 ret |= iwm_rx_handle_nonwifi(iwm, buf + buf_offset,
1278 buf_size - buf_offset);
1280 IWM_ERR(iwm, "Invalid RX opcode: 0x%x\n", op_code);
1284 buf_offset += iwm_rx_resp_size(hdr);
1290 int iwm_rx_handle(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size)
1292 struct iwm_udma_in_hdr *hdr;
1294 hdr = (struct iwm_udma_in_hdr *)buf;
1296 switch (le32_to_cpu(hdr->cmd)) {
1297 case UMAC_REBOOT_BARKER:
1298 return iwm_notif_send(iwm, NULL, IWM_BARKER_REBOOT_NOTIFICATION,
1299 IWM_SRC_UDMA, buf, buf_size);
1300 case UMAC_ACK_BARKER:
1301 return iwm_notif_send(iwm, NULL, IWM_ACK_BARKER_NOTIFICATION,
1302 IWM_SRC_UDMA, NULL, 0);
1304 IWM_DBG_RX(iwm, DBG, "Received cmd: 0x%x\n", hdr->cmd);
1305 return iwm_rx_handle_umac(iwm, buf, buf_size);
1311 static const iwm_handler iwm_umac_handlers[] =
1313 [UMAC_NOTIFY_OPCODE_ERROR] = iwm_ntf_error,
1314 [UMAC_NOTIFY_OPCODE_ALIVE] = iwm_ntf_umac_alive,
1315 [UMAC_NOTIFY_OPCODE_INIT_COMPLETE] = iwm_ntf_init_complete,
1316 [UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS] = iwm_ntf_wifi_status,
1317 [UMAC_NOTIFY_OPCODE_WIFI_IF_WRAPPER] = iwm_ntf_mlme,
1318 [UMAC_NOTIFY_OPCODE_PAGE_DEALLOC] = iwm_ntf_tx_credit_update,
1319 [UMAC_NOTIFY_OPCODE_RX_TICKET] = iwm_ntf_rx_ticket,
1320 [UMAC_CMD_OPCODE_RESET] = iwm_ntf_umac_reset,
1321 [UMAC_NOTIFY_OPCODE_STATS] = iwm_ntf_statistics,
1322 [UMAC_CMD_OPCODE_EEPROM_PROXY] = iwm_ntf_eeprom_proxy,
1323 [UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST] = iwm_ntf_channel_info_list,
1324 [REPLY_RX_MPDU_CMD] = iwm_ntf_rx_packet,
1325 [UMAC_CMD_OPCODE_WIFI_IF_WRAPPER] = iwm_ntf_wifi_if_wrapper,
1328 static const iwm_handler iwm_lmac_handlers[] =
1330 [REPLY_TX] = iwm_ntf_tx,
1331 [REPLY_ALIVE] = iwm_ntf_lmac_version,
1332 [CALIBRATION_RES_NOTIFICATION] = iwm_ntf_calib_res,
1333 [CALIBRATION_COMPLETE_NOTIFICATION] = iwm_ntf_calib_complete,
1334 [CALIBRATION_CFG_CMD] = iwm_ntf_calib_cfg,
1335 [REPLY_RX_MPDU_CMD] = iwm_ntf_rx_packet,
1336 [CARD_STATE_NOTIFICATION] = iwm_ntf_card_state,
1339 void iwm_rx_setup_handlers(struct iwm_priv *iwm)
1341 iwm->umac_handlers = (iwm_handler *) iwm_umac_handlers;
1342 iwm->lmac_handlers = (iwm_handler *) iwm_lmac_handlers;
1345 static void iwm_remove_iv(struct sk_buff *skb, u32 hdr_total_len)
1347 struct ieee80211_hdr *hdr;
1348 unsigned int hdr_len;
1350 hdr = (struct ieee80211_hdr *)skb->data;
1352 if (!ieee80211_has_protected(hdr->frame_control))
1355 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1356 if (hdr_total_len <= hdr_len)
1359 memmove(skb->data + (hdr_total_len - hdr_len), skb->data, hdr_len);
1360 skb_pull(skb, (hdr_total_len - hdr_len));
1363 static void iwm_rx_adjust_packet(struct iwm_priv *iwm,
1364 struct iwm_rx_packet *packet,
1365 struct iwm_rx_ticket_node *ticket_node)
1367 u32 payload_offset = 0, payload_len;
1368 struct iwm_rx_ticket *ticket = ticket_node->ticket;
1369 struct iwm_rx_mpdu_hdr *mpdu_hdr;
1370 struct ieee80211_hdr *hdr;
1372 mpdu_hdr = (struct iwm_rx_mpdu_hdr *)packet->skb->data;
1373 payload_offset += sizeof(struct iwm_rx_mpdu_hdr);
1374 /* Padding is 0 or 2 bytes */
1375 payload_len = le16_to_cpu(mpdu_hdr->len) +
1376 (le16_to_cpu(ticket->flags) & IWM_RX_TICKET_PAD_SIZE_MSK);
1377 payload_len -= ticket->tail_len;
1379 IWM_DBG_RX(iwm, DBG, "Packet adjusted, len:%d, offset:%d, "
1380 "ticket offset:%d ticket tail len:%d\n",
1381 payload_len, payload_offset, ticket->payload_offset,
1384 IWM_HEXDUMP(iwm, DBG, RX, "RAW: ", packet->skb->data, packet->skb->len);
1386 skb_pull(packet->skb, payload_offset);
1387 skb_trim(packet->skb, payload_len);
1389 iwm_remove_iv(packet->skb, ticket->payload_offset);
1391 hdr = (struct ieee80211_hdr *) packet->skb->data;
1392 if (ieee80211_is_data_qos(hdr->frame_control)) {
1393 /* UMAC handed QOS_DATA frame with 2 padding bytes appended
1394 * to the qos_ctl field in IEEE 802.11 headers. */
1395 memmove(packet->skb->data + IEEE80211_QOS_CTL_LEN + 2,
1397 ieee80211_hdrlen(hdr->frame_control) -
1398 IEEE80211_QOS_CTL_LEN);
1399 hdr = (struct ieee80211_hdr *) skb_pull(packet->skb,
1400 IEEE80211_QOS_CTL_LEN + 2);
1401 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1404 IWM_HEXDUMP(iwm, DBG, RX, "ADJUSTED: ",
1405 packet->skb->data, packet->skb->len);
1408 static void classify8023(struct sk_buff *skb)
1410 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1412 if (ieee80211_is_data_qos(hdr->frame_control)) {
1413 u8 *qc = ieee80211_get_qos_ctl(hdr);
1414 /* frame has qos control */
1415 skb->priority = *qc & IEEE80211_QOS_CTL_TID_MASK;
1421 static void iwm_rx_process_packet(struct iwm_priv *iwm,
1422 struct iwm_rx_packet *packet,
1423 struct iwm_rx_ticket_node *ticket_node)
1426 struct sk_buff *skb = packet->skb;
1427 struct wireless_dev *wdev = iwm_to_wdev(iwm);
1428 struct net_device *ndev = iwm_to_ndev(iwm);
1430 IWM_DBG_RX(iwm, DBG, "Processing packet ID %d\n", packet->id);
1432 switch (le16_to_cpu(ticket_node->ticket->action)) {
1433 case IWM_RX_TICKET_RELEASE:
1434 IWM_DBG_RX(iwm, DBG, "RELEASE packet\n");
1436 iwm_rx_adjust_packet(iwm, packet, ticket_node);
1437 ret = ieee80211_data_to_8023(skb, ndev->dev_addr, wdev->iftype);
1439 IWM_DBG_RX(iwm, DBG, "Couldn't convert 802.11 header - "
1444 IWM_HEXDUMP(iwm, DBG, RX, "802.3: ", skb->data, skb->len);
1446 skb->dev = iwm_to_ndev(iwm);
1447 skb->protocol = eth_type_trans(skb, ndev);
1448 skb->ip_summed = CHECKSUM_NONE;
1449 memset(skb->cb, 0, sizeof(skb->cb));
1451 ndev->stats.rx_packets++;
1452 ndev->stats.rx_bytes += skb->len;
1454 if (netif_rx_ni(skb) == NET_RX_DROP) {
1455 IWM_ERR(iwm, "Packet dropped\n");
1456 ndev->stats.rx_dropped++;
1459 case IWM_RX_TICKET_DROP:
1460 IWM_DBG_RX(iwm, DBG, "DROP packet\n");
1461 kfree_skb(packet->skb);
1464 IWM_ERR(iwm, "Unknow ticket action: %d\n",
1465 le16_to_cpu(ticket_node->ticket->action));
1466 kfree_skb(packet->skb);
1470 iwm_rx_ticket_node_free(ticket_node);
1474 * Rx data processing:
1476 * We're receiving Rx packet from the LMAC, and Rx ticket from
1478 * To forward a target data packet upstream (i.e. to the
1479 * kernel network stack), we must have received an Rx ticket
1480 * that tells us we're allowed to release this packet (ticket
1481 * action is IWM_RX_TICKET_RELEASE). The Rx ticket also indicates,
1482 * among other things, where valid data actually starts in the Rx
1485 void iwm_rx_worker(struct work_struct *work)
1487 struct iwm_priv *iwm;
1488 struct iwm_rx_ticket_node *ticket, *next;
1490 iwm = container_of(work, struct iwm_priv, rx_worker);
1493 * We go through the tickets list and if there is a pending
1494 * packet for it, we push it upstream.
1495 * We stop whenever a ticket is missing its packet, as we're
1496 * supposed to send the packets in order.
1498 list_for_each_entry_safe(ticket, next, &iwm->rx_tickets, node) {
1499 struct iwm_rx_packet *packet =
1500 iwm_rx_packet_get(iwm, le16_to_cpu(ticket->ticket->id));
1503 IWM_DBG_RX(iwm, DBG, "Skip rx_work: Wait for ticket %d "
1504 "to be handled first\n",
1505 le16_to_cpu(ticket->ticket->id));
1509 list_del(&ticket->node);
1510 list_del(&packet->node);
1511 iwm_rx_process_packet(iwm, packet, ticket);