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