blob: 36b1580329cc32b7dff67f4cb8656d6ae6087720 [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>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040041#include <linux/sched.h>
Zhu Yibb9f8692009-05-21 21:20:45 +080042#include <linux/etherdevice.h>
43#include <linux/wireless.h>
44#include <linux/ieee80211.h>
45#include <linux/if_arp.h>
46#include <linux/list.h>
47#include <net/iw_handler.h>
48
49#include "iwm.h"
50#include "debug.h"
51#include "hal.h"
52#include "umac.h"
53#include "lmac.h"
54#include "commands.h"
55#include "rx.h"
56#include "cfg80211.h"
57#include "eeprom.h"
58
59static int iwm_rx_check_udma_hdr(struct iwm_udma_in_hdr *hdr)
60{
61 if ((le32_to_cpu(hdr->cmd) == UMAC_PAD_TERMINAL) ||
62 (le32_to_cpu(hdr->size) == UMAC_PAD_TERMINAL))
63 return -EINVAL;
64
65 return 0;
66}
67
68static inline int iwm_rx_resp_size(struct iwm_udma_in_hdr *hdr)
69{
70 return ALIGN(le32_to_cpu(hdr->size) + sizeof(struct iwm_udma_in_hdr),
71 16);
72}
73
74/*
75 * Notification handlers:
76 *
77 * For every possible notification we can receive from the
78 * target, we have a handler.
79 * When we get a target notification, and there is no one
80 * waiting for it, it's just processed through the rx code
81 * path:
82 *
83 * iwm_rx_handle()
84 * -> iwm_rx_handle_umac()
85 * -> iwm_rx_handle_wifi()
86 * -> iwm_rx_handle_resp()
87 * -> iwm_ntf_*()
88 *
89 * OR
90 *
91 * -> iwm_rx_handle_non_wifi()
92 *
93 * If there are processes waiting for this notification, then
94 * iwm_rx_handle_wifi() just wakes those processes up and they
95 * grab the pending notification.
96 */
97static int iwm_ntf_error(struct iwm_priv *iwm, u8 *buf,
98 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
99{
100 struct iwm_umac_notif_error *error;
101 struct iwm_fw_error_hdr *fw_err;
102
103 error = (struct iwm_umac_notif_error *)buf;
104 fw_err = &error->err;
105
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200106 memcpy(iwm->last_fw_err, fw_err, sizeof(struct iwm_fw_error_hdr));
107
Zhu Yibb9f8692009-05-21 21:20:45 +0800108 IWM_ERR(iwm, "%cMAC FW ERROR:\n",
109 (le32_to_cpu(fw_err->category) == UMAC_SYS_ERR_CAT_LMAC) ? 'L' : 'U');
110 IWM_ERR(iwm, "\tCategory: %d\n", le32_to_cpu(fw_err->category));
111 IWM_ERR(iwm, "\tStatus: 0x%x\n", le32_to_cpu(fw_err->status));
112 IWM_ERR(iwm, "\tPC: 0x%x\n", le32_to_cpu(fw_err->pc));
113 IWM_ERR(iwm, "\tblink1: %d\n", le32_to_cpu(fw_err->blink1));
114 IWM_ERR(iwm, "\tblink2: %d\n", le32_to_cpu(fw_err->blink2));
115 IWM_ERR(iwm, "\tilink1: %d\n", le32_to_cpu(fw_err->ilink1));
116 IWM_ERR(iwm, "\tilink2: %d\n", le32_to_cpu(fw_err->ilink2));
117 IWM_ERR(iwm, "\tData1: 0x%x\n", le32_to_cpu(fw_err->data1));
118 IWM_ERR(iwm, "\tData2: 0x%x\n", le32_to_cpu(fw_err->data2));
119 IWM_ERR(iwm, "\tLine number: %d\n", le32_to_cpu(fw_err->line_num));
120 IWM_ERR(iwm, "\tUMAC status: 0x%x\n", le32_to_cpu(fw_err->umac_status));
121 IWM_ERR(iwm, "\tLMAC status: 0x%x\n", le32_to_cpu(fw_err->lmac_status));
122 IWM_ERR(iwm, "\tSDIO status: 0x%x\n", le32_to_cpu(fw_err->sdio_status));
123
Samuel Ortizd2101762009-09-01 15:14:05 +0200124 iwm_resetting(iwm);
125
Zhu Yibb9f8692009-05-21 21:20:45 +0800126 return 0;
127}
128
129static int iwm_ntf_umac_alive(struct iwm_priv *iwm, u8 *buf,
130 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
131{
132 struct iwm_umac_notif_alive *alive_resp =
133 (struct iwm_umac_notif_alive *)(buf);
134 u16 status = le16_to_cpu(alive_resp->status);
135
136 if (status == UMAC_NTFY_ALIVE_STATUS_ERR) {
137 IWM_ERR(iwm, "Receive error UMAC_ALIVE\n");
138 return -EIO;
139 }
140
141 iwm_tx_credit_init_pools(iwm, alive_resp);
142
143 return 0;
144}
145
146static int iwm_ntf_init_complete(struct iwm_priv *iwm, u8 *buf,
147 unsigned long buf_size,
148 struct iwm_wifi_cmd *cmd)
149{
Zhu Yi257862f2009-06-15 21:59:56 +0200150 struct wiphy *wiphy = iwm_to_wiphy(iwm);
Zhu Yibb9f8692009-05-21 21:20:45 +0800151 struct iwm_umac_notif_init_complete *init_complete =
152 (struct iwm_umac_notif_init_complete *)(buf);
153 u16 status = le16_to_cpu(init_complete->status);
Zhu Yi257862f2009-06-15 21:59:56 +0200154 bool blocked = (status == UMAC_NTFY_INIT_COMPLETE_STATUS_ERR);
Zhu Yibb9f8692009-05-21 21:20:45 +0800155
Zhu Yi257862f2009-06-15 21:59:56 +0200156 if (blocked)
Zhu Yibb9f8692009-05-21 21:20:45 +0800157 IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is on (radio off)\n");
Zhu Yi257862f2009-06-15 21:59:56 +0200158 else
Zhu Yibb9f8692009-05-21 21:20:45 +0800159 IWM_DBG_NTF(iwm, DBG, "Hardware rf kill is off (radio on)\n");
Zhu Yi257862f2009-06-15 21:59:56 +0200160
161 wiphy_rfkill_set_hw_state(wiphy, blocked);
Zhu Yibb9f8692009-05-21 21:20:45 +0800162
163 return 0;
164}
165
166static int iwm_ntf_tx_credit_update(struct iwm_priv *iwm, u8 *buf,
167 unsigned long buf_size,
168 struct iwm_wifi_cmd *cmd)
169{
170 int pool_nr, total_freed_pages;
171 unsigned long pool_map;
172 int i, id;
173 struct iwm_umac_notif_page_dealloc *dealloc =
174 (struct iwm_umac_notif_page_dealloc *)buf;
175
176 pool_nr = GET_VAL32(dealloc->changes, UMAC_DEALLOC_NTFY_CHANGES_CNT);
177 pool_map = GET_VAL32(dealloc->changes, UMAC_DEALLOC_NTFY_CHANGES_MSK);
178
179 IWM_DBG_TX(iwm, DBG, "UMAC dealloc notification: pool nr %d, "
180 "update map 0x%lx\n", pool_nr, pool_map);
181
182 spin_lock(&iwm->tx_credit.lock);
183
184 for (i = 0; i < pool_nr; i++) {
185 id = GET_VAL32(dealloc->grp_info[i],
186 UMAC_DEALLOC_NTFY_GROUP_NUM);
187 if (test_bit(id, &pool_map)) {
188 total_freed_pages = GET_VAL32(dealloc->grp_info[i],
189 UMAC_DEALLOC_NTFY_PAGE_CNT);
190 iwm_tx_credit_inc(iwm, id, total_freed_pages);
191 }
192 }
193
194 spin_unlock(&iwm->tx_credit.lock);
195
196 return 0;
197}
198
199static int iwm_ntf_umac_reset(struct iwm_priv *iwm, u8 *buf,
200 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
201{
202 IWM_DBG_NTF(iwm, DBG, "UMAC RESET done\n");
203
204 return 0;
205}
206
207static int iwm_ntf_lmac_version(struct iwm_priv *iwm, u8 *buf,
208 unsigned long buf_size,
209 struct iwm_wifi_cmd *cmd)
210{
211 IWM_DBG_NTF(iwm, INFO, "LMAC Version: %x.%x\n", buf[9], buf[8]);
212
213 return 0;
214}
215
216static int iwm_ntf_tx(struct iwm_priv *iwm, u8 *buf,
217 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
218{
219 struct iwm_lmac_tx_resp *tx_resp;
220 struct iwm_umac_wifi_in_hdr *hdr;
221
222 tx_resp = (struct iwm_lmac_tx_resp *)
223 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
224 hdr = (struct iwm_umac_wifi_in_hdr *)buf;
225
Zhu Yi4fdd81f2009-07-16 17:34:09 +0800226 IWM_DBG_TX(iwm, DBG, "REPLY_TX, buf size: %lu\n", buf_size);
Zhu Yibb9f8692009-05-21 21:20:45 +0800227
Zhu Yi4fdd81f2009-07-16 17:34:09 +0800228 IWM_DBG_TX(iwm, DBG, "Seqnum: %d\n",
229 le16_to_cpu(hdr->sw_hdr.cmd.seq_num));
230 IWM_DBG_TX(iwm, DBG, "\tFrame cnt: %d\n", tx_resp->frame_cnt);
231 IWM_DBG_TX(iwm, DBG, "\tRetry cnt: %d\n",
232 le16_to_cpu(tx_resp->retry_cnt));
233 IWM_DBG_TX(iwm, DBG, "\tSeq ctl: %d\n", le16_to_cpu(tx_resp->seq_ctl));
234 IWM_DBG_TX(iwm, DBG, "\tByte cnt: %d\n",
235 le16_to_cpu(tx_resp->byte_cnt));
236 IWM_DBG_TX(iwm, DBG, "\tStatus: 0x%x\n", le32_to_cpu(tx_resp->status));
Zhu Yibb9f8692009-05-21 21:20:45 +0800237
238 return 0;
239}
240
241
242static int iwm_ntf_calib_res(struct iwm_priv *iwm, u8 *buf,
243 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
244{
245 u8 opcode;
246 u8 *calib_buf;
247 struct iwm_lmac_calib_hdr *hdr = (struct iwm_lmac_calib_hdr *)
248 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
249
250 opcode = hdr->opcode;
251
252 BUG_ON(opcode >= CALIBRATION_CMD_NUM ||
253 opcode < PHY_CALIBRATE_OPCODES_NUM);
254
255 IWM_DBG_NTF(iwm, DBG, "Store calibration result for opcode: %d\n",
256 opcode);
257
258 buf_size -= sizeof(struct iwm_umac_wifi_in_hdr);
259 calib_buf = iwm->calib_res[opcode].buf;
260
261 if (!calib_buf || (iwm->calib_res[opcode].size < buf_size)) {
262 kfree(calib_buf);
263 calib_buf = kzalloc(buf_size, GFP_KERNEL);
264 if (!calib_buf) {
265 IWM_ERR(iwm, "Memory allocation failed: calib_res\n");
266 return -ENOMEM;
267 }
268 iwm->calib_res[opcode].buf = calib_buf;
269 iwm->calib_res[opcode].size = buf_size;
270 }
271
272 memcpy(calib_buf, hdr, buf_size);
273 set_bit(opcode - PHY_CALIBRATE_OPCODES_NUM, &iwm->calib_done_map);
274
275 return 0;
276}
277
278static int iwm_ntf_calib_complete(struct iwm_priv *iwm, u8 *buf,
279 unsigned long buf_size,
280 struct iwm_wifi_cmd *cmd)
281{
282 IWM_DBG_NTF(iwm, DBG, "Calibration completed\n");
283
284 return 0;
285}
286
287static int iwm_ntf_calib_cfg(struct iwm_priv *iwm, u8 *buf,
288 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
289{
290 struct iwm_lmac_cal_cfg_resp *cal_resp;
291
292 cal_resp = (struct iwm_lmac_cal_cfg_resp *)
293 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
294
295 IWM_DBG_NTF(iwm, DBG, "Calibration CFG command status: %d\n",
296 le32_to_cpu(cal_resp->status));
297
298 return 0;
299}
300
301static int iwm_ntf_wifi_status(struct iwm_priv *iwm, u8 *buf,
302 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
303{
304 struct iwm_umac_notif_wifi_status *status =
305 (struct iwm_umac_notif_wifi_status *)buf;
306
307 iwm->core_enabled |= le16_to_cpu(status->status);
308
309 return 0;
310}
311
312static struct iwm_rx_ticket_node *
313iwm_rx_ticket_node_alloc(struct iwm_priv *iwm, struct iwm_rx_ticket *ticket)
314{
315 struct iwm_rx_ticket_node *ticket_node;
316
317 ticket_node = kzalloc(sizeof(struct iwm_rx_ticket_node), GFP_KERNEL);
318 if (!ticket_node) {
319 IWM_ERR(iwm, "Couldn't allocate ticket node\n");
320 return ERR_PTR(-ENOMEM);
321 }
322
323 ticket_node->ticket = kzalloc(sizeof(struct iwm_rx_ticket), GFP_KERNEL);
324 if (!ticket_node->ticket) {
325 IWM_ERR(iwm, "Couldn't allocate RX ticket\n");
326 kfree(ticket_node);
327 return ERR_PTR(-ENOMEM);
328 }
329
330 memcpy(ticket_node->ticket, ticket, sizeof(struct iwm_rx_ticket));
331 INIT_LIST_HEAD(&ticket_node->node);
332
333 return ticket_node;
334}
335
336static void iwm_rx_ticket_node_free(struct iwm_rx_ticket_node *ticket_node)
337{
338 kfree(ticket_node->ticket);
339 kfree(ticket_node);
340}
341
342static struct iwm_rx_packet *iwm_rx_packet_get(struct iwm_priv *iwm, u16 id)
343{
344 u8 id_hash = IWM_RX_ID_GET_HASH(id);
345 struct list_head *packet_list;
346 struct iwm_rx_packet *packet, *next;
347
348 packet_list = &iwm->rx_packets[id_hash];
349
350 list_for_each_entry_safe(packet, next, packet_list, node)
351 if (packet->id == id)
352 return packet;
353
354 return NULL;
355}
356
357static struct iwm_rx_packet *iwm_rx_packet_alloc(struct iwm_priv *iwm, u8 *buf,
358 u32 size, u16 id)
359{
360 struct iwm_rx_packet *packet;
361
362 packet = kzalloc(sizeof(struct iwm_rx_packet), GFP_KERNEL);
363 if (!packet) {
364 IWM_ERR(iwm, "Couldn't allocate packet\n");
365 return ERR_PTR(-ENOMEM);
366 }
367
368 packet->skb = dev_alloc_skb(size);
369 if (!packet->skb) {
370 IWM_ERR(iwm, "Couldn't allocate packet SKB\n");
371 kfree(packet);
372 return ERR_PTR(-ENOMEM);
373 }
374
375 packet->pkt_size = size;
376
377 skb_put(packet->skb, size);
378 memcpy(packet->skb->data, buf, size);
379 INIT_LIST_HEAD(&packet->node);
380 packet->id = id;
381
382 return packet;
383}
384
385void iwm_rx_free(struct iwm_priv *iwm)
386{
387 struct iwm_rx_ticket_node *ticket, *nt;
388 struct iwm_rx_packet *packet, *np;
389 int i;
390
391 list_for_each_entry_safe(ticket, nt, &iwm->rx_tickets, node) {
392 list_del(&ticket->node);
393 iwm_rx_ticket_node_free(ticket);
394 }
395
396 for (i = 0; i < IWM_RX_ID_HASH; i++) {
397 list_for_each_entry_safe(packet, np, &iwm->rx_packets[i],
398 node) {
399 list_del(&packet->node);
400 kfree_skb(packet->skb);
401 kfree(packet);
402 }
403 }
404}
405
406static int iwm_ntf_rx_ticket(struct iwm_priv *iwm, u8 *buf,
407 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
408{
409 struct iwm_umac_notif_rx_ticket *ntf_rx_ticket =
410 (struct iwm_umac_notif_rx_ticket *)buf;
411 struct iwm_rx_ticket *ticket =
412 (struct iwm_rx_ticket *)ntf_rx_ticket->tickets;
413 int i, schedule_rx = 0;
414
415 for (i = 0; i < ntf_rx_ticket->num_tickets; i++) {
416 struct iwm_rx_ticket_node *ticket_node;
417
418 switch (le16_to_cpu(ticket->action)) {
419 case IWM_RX_TICKET_RELEASE:
420 case IWM_RX_TICKET_DROP:
421 /* We can push the packet to the stack */
422 ticket_node = iwm_rx_ticket_node_alloc(iwm, ticket);
423 if (IS_ERR(ticket_node))
424 return PTR_ERR(ticket_node);
425
Samuel Ortiz69cf6e22009-10-16 13:18:50 +0800426 IWM_DBG_RX(iwm, DBG, "TICKET %s(%d)\n",
427 ticket->action == IWM_RX_TICKET_RELEASE ?
428 "RELEASE" : "DROP",
Zhu Yi4fdd81f2009-07-16 17:34:09 +0800429 ticket->id);
Zhu Yibb9f8692009-05-21 21:20:45 +0800430 list_add_tail(&ticket_node->node, &iwm->rx_tickets);
431
432 /*
433 * We received an Rx ticket, most likely there's
434 * a packet pending for it, it's not worth going
435 * through the packet hash list to double check.
436 * Let's just fire the rx worker..
437 */
438 schedule_rx = 1;
439
440 break;
441
442 default:
443 IWM_ERR(iwm, "Invalid RX ticket action: 0x%x\n",
444 ticket->action);
445 }
446
447 ticket++;
448 }
449
450 if (schedule_rx)
451 queue_work(iwm->rx_wq, &iwm->rx_worker);
452
453 return 0;
454}
455
456static int iwm_ntf_rx_packet(struct iwm_priv *iwm, u8 *buf,
457 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
458{
459 struct iwm_umac_wifi_in_hdr *wifi_hdr;
460 struct iwm_rx_packet *packet;
461 u16 id, buf_offset;
462 u32 packet_size;
463
Zhu Yi4fdd81f2009-07-16 17:34:09 +0800464 IWM_DBG_RX(iwm, DBG, "\n");
Zhu Yibb9f8692009-05-21 21:20:45 +0800465
466 wifi_hdr = (struct iwm_umac_wifi_in_hdr *)buf;
467 id = le16_to_cpu(wifi_hdr->sw_hdr.cmd.seq_num);
468 buf_offset = sizeof(struct iwm_umac_wifi_in_hdr);
469 packet_size = buf_size - sizeof(struct iwm_umac_wifi_in_hdr);
470
Zhu Yi4fdd81f2009-07-16 17:34:09 +0800471 IWM_DBG_RX(iwm, DBG, "CMD:0x%x, seqnum: %d, packet size: %d\n",
472 wifi_hdr->sw_hdr.cmd.cmd, id, packet_size);
Zhu Yibb9f8692009-05-21 21:20:45 +0800473 IWM_DBG_RX(iwm, DBG, "Packet id: %d\n", id);
474 IWM_HEXDUMP(iwm, DBG, RX, "PACKET: ", buf + buf_offset, packet_size);
475
476 packet = iwm_rx_packet_alloc(iwm, buf + buf_offset, packet_size, id);
477 if (IS_ERR(packet))
478 return PTR_ERR(packet);
479
480 list_add_tail(&packet->node, &iwm->rx_packets[IWM_RX_ID_GET_HASH(id)]);
481
482 /* We might (unlikely) have received the packet _after_ the ticket */
483 queue_work(iwm->rx_wq, &iwm->rx_worker);
484
485 return 0;
486}
487
488/* MLME handlers */
489static int iwm_mlme_assoc_start(struct iwm_priv *iwm, u8 *buf,
490 unsigned long buf_size,
491 struct iwm_wifi_cmd *cmd)
492{
493 struct iwm_umac_notif_assoc_start *start;
494
495 start = (struct iwm_umac_notif_assoc_start *)buf;
496
Zhu Yibb9f8692009-05-21 21:20:45 +0800497 IWM_DBG_MLME(iwm, INFO, "Association with %pM Started, reason: %d\n",
498 start->bssid, le32_to_cpu(start->roam_reason));
499
500 wake_up_interruptible(&iwm->mlme_queue);
501
502 return 0;
503}
504
Samuel Ortiz9829e1b2009-10-16 13:18:57 +0800505static u8 iwm_is_open_wep_profile(struct iwm_priv *iwm)
506{
507 if ((iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_40 ||
508 iwm->umac_profile->sec.ucast_cipher == UMAC_CIPHER_TYPE_WEP_104) &&
509 (iwm->umac_profile->sec.ucast_cipher ==
510 iwm->umac_profile->sec.mcast_cipher) &&
511 (iwm->umac_profile->sec.auth_type == UMAC_AUTH_TYPE_OPEN))
512 return 1;
513
514 return 0;
515}
516
Zhu Yibb9f8692009-05-21 21:20:45 +0800517static int iwm_mlme_assoc_complete(struct iwm_priv *iwm, u8 *buf,
518 unsigned long buf_size,
519 struct iwm_wifi_cmd *cmd)
520{
Zhu Yi7d49c612010-02-25 14:15:25 +0800521 struct wiphy *wiphy = iwm_to_wiphy(iwm);
522 struct ieee80211_channel *chan;
Zhu Yibb9f8692009-05-21 21:20:45 +0800523 struct iwm_umac_notif_assoc_complete *complete =
524 (struct iwm_umac_notif_assoc_complete *)buf;
Zhu Yibb9f8692009-05-21 21:20:45 +0800525
526 IWM_DBG_MLME(iwm, INFO, "Association with %pM completed, status: %d\n",
527 complete->bssid, complete->status);
528
Zhu Yibb9f8692009-05-21 21:20:45 +0800529 switch (le32_to_cpu(complete->status)) {
530 case UMAC_ASSOC_COMPLETE_SUCCESS:
Zhu Yi7d49c612010-02-25 14:15:25 +0800531 chan = ieee80211_get_channel(wiphy,
532 ieee80211_channel_to_frequency(complete->channel));
533 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
534 /* Associated to a unallowed channel, disassociate. */
535 __iwm_invalidate_mlme_profile(iwm);
536 IWM_WARN(iwm, "Couldn't associate with %pM due to "
537 "channel %d is disabled. Check your local "
538 "regulatory setting.\n",
539 complete->bssid, complete->channel);
540 goto failure;
541 }
542
Zhu Yibb9f8692009-05-21 21:20:45 +0800543 set_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
544 memcpy(iwm->bssid, complete->bssid, ETH_ALEN);
545 iwm->channel = complete->channel;
546
Zhu Yide15fd32009-09-01 15:14:01 +0200547 /* Internal roaming state, avoid notifying SME. */
548 if (!test_and_clear_bit(IWM_STATUS_SME_CONNECTING, &iwm->status)
549 && iwm->conf.mode == UMAC_MODE_BSS) {
Zhu Yic7436272009-09-01 15:14:02 +0200550 cancel_delayed_work(&iwm->disconnect);
Zhu Yide15fd32009-09-01 15:14:01 +0200551 cfg80211_roamed(iwm_to_ndev(iwm),
552 complete->bssid,
553 iwm->req_ie, iwm->req_ie_len,
554 iwm->resp_ie, iwm->resp_ie_len,
555 GFP_KERNEL);
556 break;
557 }
558
Zhu Yibb9f8692009-05-21 21:20:45 +0800559 iwm_link_on(iwm);
560
Zhu Yi9c7c0cd2009-07-20 11:47:46 +0800561 if (iwm->conf.mode == UMAC_MODE_IBSS)
562 goto ibss;
563
Samuel Ortizd2101762009-09-01 15:14:05 +0200564 if (!test_bit(IWM_STATUS_RESETTING, &iwm->status))
565 cfg80211_connect_result(iwm_to_ndev(iwm),
566 complete->bssid,
567 iwm->req_ie, iwm->req_ie_len,
568 iwm->resp_ie, iwm->resp_ie_len,
569 WLAN_STATUS_SUCCESS,
570 GFP_KERNEL);
571 else
572 cfg80211_roamed(iwm_to_ndev(iwm),
Samuel Ortiz9967d462009-07-16 17:34:10 +0800573 complete->bssid,
Zhu Yib68518f2009-07-20 11:47:45 +0800574 iwm->req_ie, iwm->req_ie_len,
575 iwm->resp_ie, iwm->resp_ie_len,
Samuel Ortizd2101762009-09-01 15:14:05 +0200576 GFP_KERNEL);
Zhu Yibb9f8692009-05-21 21:20:45 +0800577 break;
578 case UMAC_ASSOC_COMPLETE_FAILURE:
Zhu Yi7d49c612010-02-25 14:15:25 +0800579 failure:
Zhu Yibb9f8692009-05-21 21:20:45 +0800580 clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
581 memset(iwm->bssid, 0, ETH_ALEN);
582 iwm->channel = 0;
583
Zhu Yide15fd32009-09-01 15:14:01 +0200584 /* Internal roaming state, avoid notifying SME. */
585 if (!test_and_clear_bit(IWM_STATUS_SME_CONNECTING, &iwm->status)
Zhu Yic7436272009-09-01 15:14:02 +0200586 && iwm->conf.mode == UMAC_MODE_BSS) {
587 cancel_delayed_work(&iwm->disconnect);
Zhu Yide15fd32009-09-01 15:14:01 +0200588 break;
Zhu Yic7436272009-09-01 15:14:02 +0200589 }
Zhu Yide15fd32009-09-01 15:14:01 +0200590
Zhu Yibb9f8692009-05-21 21:20:45 +0800591 iwm_link_off(iwm);
Samuel Ortiz9967d462009-07-16 17:34:10 +0800592
Zhu Yi9c7c0cd2009-07-20 11:47:46 +0800593 if (iwm->conf.mode == UMAC_MODE_IBSS)
594 goto ibss;
595
Samuel Ortizd2101762009-09-01 15:14:05 +0200596 if (!test_bit(IWM_STATUS_RESETTING, &iwm->status))
Samuel Ortiz9829e1b2009-10-16 13:18:57 +0800597 if (!iwm_is_open_wep_profile(iwm)) {
598 cfg80211_connect_result(iwm_to_ndev(iwm),
599 complete->bssid,
600 NULL, 0, NULL, 0,
601 WLAN_STATUS_UNSPECIFIED_FAILURE,
602 GFP_KERNEL);
603 } else {
604 /* Let's try shared WEP auth */
605 IWM_ERR(iwm, "Trying WEP shared auth\n");
606 schedule_work(&iwm->auth_retry_worker);
607 }
Samuel Ortizd2101762009-09-01 15:14:05 +0200608 else
609 cfg80211_disconnected(iwm_to_ndev(iwm), 0, NULL, 0,
610 GFP_KERNEL);
Zhu Yide15fd32009-09-01 15:14:01 +0200611 break;
Zhu Yibb9f8692009-05-21 21:20:45 +0800612 default:
613 break;
614 }
615
Samuel Ortizd2101762009-09-01 15:14:05 +0200616 clear_bit(IWM_STATUS_RESETTING, &iwm->status);
Zhu Yi9c7c0cd2009-07-20 11:47:46 +0800617 return 0;
Zhu Yibb9f8692009-05-21 21:20:45 +0800618
Zhu Yi9c7c0cd2009-07-20 11:47:46 +0800619 ibss:
620 cfg80211_ibss_joined(iwm_to_ndev(iwm), iwm->bssid, GFP_KERNEL);
Samuel Ortizd2101762009-09-01 15:14:05 +0200621 clear_bit(IWM_STATUS_RESETTING, &iwm->status);
Zhu Yibb9f8692009-05-21 21:20:45 +0800622 return 0;
623}
624
625static int iwm_mlme_profile_invalidate(struct iwm_priv *iwm, u8 *buf,
626 unsigned long buf_size,
627 struct iwm_wifi_cmd *cmd)
628{
629 struct iwm_umac_notif_profile_invalidate *invalid;
Zhu Yic7436272009-09-01 15:14:02 +0200630 u32 reason;
Zhu Yibb9f8692009-05-21 21:20:45 +0800631
632 invalid = (struct iwm_umac_notif_profile_invalidate *)buf;
Zhu Yic7436272009-09-01 15:14:02 +0200633 reason = le32_to_cpu(invalid->reason);
Zhu Yibb9f8692009-05-21 21:20:45 +0800634
Zhu Yic7436272009-09-01 15:14:02 +0200635 IWM_DBG_MLME(iwm, INFO, "Profile Invalidated. Reason: %d\n", reason);
636
637 if (reason != UMAC_PROFILE_INVALID_REQUEST &&
638 test_bit(IWM_STATUS_SME_CONNECTING, &iwm->status))
639 cfg80211_connect_result(iwm_to_ndev(iwm), NULL, NULL, 0, NULL,
640 0, WLAN_STATUS_UNSPECIFIED_FAILURE,
641 GFP_KERNEL);
Zhu Yibb9f8692009-05-21 21:20:45 +0800642
Zhu Yide15fd32009-09-01 15:14:01 +0200643 clear_bit(IWM_STATUS_SME_CONNECTING, &iwm->status);
Zhu Yibb9f8692009-05-21 21:20:45 +0800644 clear_bit(IWM_STATUS_ASSOCIATED, &iwm->status);
645
646 iwm->umac_profile_active = 0;
647 memset(iwm->bssid, 0, ETH_ALEN);
648 iwm->channel = 0;
649
650 iwm_link_off(iwm);
651
652 wake_up_interruptible(&iwm->mlme_queue);
653
654 return 0;
655}
656
Zhu Yic7436272009-09-01 15:14:02 +0200657#define IWM_DISCONNECT_INTERVAL (5 * HZ)
658
659static int iwm_mlme_connection_terminated(struct iwm_priv *iwm, u8 *buf,
660 unsigned long buf_size,
661 struct iwm_wifi_cmd *cmd)
662{
663 IWM_DBG_MLME(iwm, DBG, "Connection terminated\n");
664
665 schedule_delayed_work(&iwm->disconnect, IWM_DISCONNECT_INTERVAL);
666
667 return 0;
668}
669
Zhu Yibb9f8692009-05-21 21:20:45 +0800670static int iwm_mlme_scan_complete(struct iwm_priv *iwm, u8 *buf,
671 unsigned long buf_size,
672 struct iwm_wifi_cmd *cmd)
673{
674 int ret;
675 struct iwm_umac_notif_scan_complete *scan_complete =
676 (struct iwm_umac_notif_scan_complete *)buf;
677 u32 result = le32_to_cpu(scan_complete->result);
678
679 IWM_DBG_MLME(iwm, INFO, "type:0x%x result:0x%x seq:%d\n",
680 le32_to_cpu(scan_complete->type),
681 le32_to_cpu(scan_complete->result),
682 scan_complete->seq_num);
683
684 if (!test_and_clear_bit(IWM_STATUS_SCANNING, &iwm->status)) {
685 IWM_ERR(iwm, "Scan complete while device not scanning\n");
686 return -EIO;
687 }
688 if (!iwm->scan_request)
689 return 0;
690
691 ret = iwm_cfg80211_inform_bss(iwm);
692
693 cfg80211_scan_done(iwm->scan_request,
694 (result & UMAC_SCAN_RESULT_ABORTED) ? 1 : !!ret);
695 iwm->scan_request = NULL;
696
697 return ret;
698}
699
700static int iwm_mlme_update_sta_table(struct iwm_priv *iwm, u8 *buf,
701 unsigned long buf_size,
702 struct iwm_wifi_cmd *cmd)
703{
704 struct iwm_umac_notif_sta_info *umac_sta =
705 (struct iwm_umac_notif_sta_info *)buf;
706 struct iwm_sta_info *sta;
707 int i;
708
709 switch (le32_to_cpu(umac_sta->opcode)) {
710 case UMAC_OPCODE_ADD_MODIFY:
711 sta = &iwm->sta_table[GET_VAL8(umac_sta->sta_id, LMAC_STA_ID)];
712
713 IWM_DBG_MLME(iwm, INFO, "%s STA: ID = %d, Color = %d, "
714 "addr = %pM, qos = %d\n",
715 sta->valid ? "Modify" : "Add",
716 GET_VAL8(umac_sta->sta_id, LMAC_STA_ID),
717 GET_VAL8(umac_sta->sta_id, LMAC_STA_COLOR),
718 umac_sta->mac_addr,
719 umac_sta->flags & UMAC_STA_FLAG_QOS);
720
721 sta->valid = 1;
722 sta->qos = umac_sta->flags & UMAC_STA_FLAG_QOS;
723 sta->color = GET_VAL8(umac_sta->sta_id, LMAC_STA_COLOR);
724 memcpy(sta->addr, umac_sta->mac_addr, ETH_ALEN);
725 break;
726 case UMAC_OPCODE_REMOVE:
727 IWM_DBG_MLME(iwm, INFO, "Remove STA: ID = %d, Color = %d, "
728 "addr = %pM\n",
729 GET_VAL8(umac_sta->sta_id, LMAC_STA_ID),
730 GET_VAL8(umac_sta->sta_id, LMAC_STA_COLOR),
731 umac_sta->mac_addr);
732
733 sta = &iwm->sta_table[GET_VAL8(umac_sta->sta_id, LMAC_STA_ID)];
734
735 if (!memcmp(sta->addr, umac_sta->mac_addr, ETH_ALEN))
736 sta->valid = 0;
737
738 break;
739 case UMAC_OPCODE_CLEAR_ALL:
740 for (i = 0; i < IWM_STA_TABLE_NUM; i++)
741 iwm->sta_table[i].valid = 0;
742
743 break;
744 default:
745 break;
746 }
747
748 return 0;
749}
750
Zhu Yib8fcf592009-10-16 13:19:00 +0800751static int iwm_mlme_medium_lost(struct iwm_priv *iwm, u8 *buf,
752 unsigned long buf_size,
753 struct iwm_wifi_cmd *cmd)
754{
755 struct wiphy *wiphy = iwm_to_wiphy(iwm);
756
757 IWM_DBG_NTF(iwm, DBG, "WiFi/WiMax coexistence radio is OFF\n");
758
759 wiphy_rfkill_set_hw_state(wiphy, true);
760
761 return 0;
762}
763
Zhu Yibb9f8692009-05-21 21:20:45 +0800764static int iwm_mlme_update_bss_table(struct iwm_priv *iwm, u8 *buf,
765 unsigned long buf_size,
766 struct iwm_wifi_cmd *cmd)
767{
768 struct wiphy *wiphy = iwm_to_wiphy(iwm);
769 struct ieee80211_mgmt *mgmt;
770 struct iwm_umac_notif_bss_info *umac_bss =
771 (struct iwm_umac_notif_bss_info *)buf;
772 struct ieee80211_channel *channel;
773 struct ieee80211_supported_band *band;
774 struct iwm_bss_info *bss, *next;
775 s32 signal;
776 int freq;
777 u16 frame_len = le16_to_cpu(umac_bss->frame_len);
778 size_t bss_len = sizeof(struct iwm_umac_notif_bss_info) + frame_len;
779
780 mgmt = (struct ieee80211_mgmt *)(umac_bss->frame_buf);
781
782 IWM_DBG_MLME(iwm, DBG, "New BSS info entry: %pM\n", mgmt->bssid);
783 IWM_DBG_MLME(iwm, DBG, "\tType: 0x%x\n", le32_to_cpu(umac_bss->type));
784 IWM_DBG_MLME(iwm, DBG, "\tTimestamp: %d\n",
785 le32_to_cpu(umac_bss->timestamp));
786 IWM_DBG_MLME(iwm, DBG, "\tTable Index: %d\n",
787 le16_to_cpu(umac_bss->table_idx));
788 IWM_DBG_MLME(iwm, DBG, "\tBand: %d\n", umac_bss->band);
789 IWM_DBG_MLME(iwm, DBG, "\tChannel: %d\n", umac_bss->channel);
790 IWM_DBG_MLME(iwm, DBG, "\tRSSI: %d\n", umac_bss->rssi);
791 IWM_DBG_MLME(iwm, DBG, "\tFrame Length: %d\n", frame_len);
792
793 list_for_each_entry_safe(bss, next, &iwm->bss_list, node)
794 if (bss->bss->table_idx == umac_bss->table_idx)
795 break;
796
797 if (&bss->node != &iwm->bss_list) {
798 /* Remove the old BSS entry, we will add it back later. */
799 list_del(&bss->node);
800 kfree(bss->bss);
801 } else {
802 /* New BSS entry */
803
804 bss = kzalloc(sizeof(struct iwm_bss_info), GFP_KERNEL);
805 if (!bss) {
806 IWM_ERR(iwm, "Couldn't allocate bss_info\n");
807 return -ENOMEM;
808 }
809 }
810
811 bss->bss = kzalloc(bss_len, GFP_KERNEL);
Roel Kluin33a5d082010-02-09 12:07:41 +0100812 if (!bss->bss) {
Zhu Yibb9f8692009-05-21 21:20:45 +0800813 kfree(bss);
814 IWM_ERR(iwm, "Couldn't allocate bss\n");
815 return -ENOMEM;
816 }
817
818 INIT_LIST_HEAD(&bss->node);
819 memcpy(bss->bss, umac_bss, bss_len);
820
821 if (umac_bss->band == UMAC_BAND_2GHZ)
822 band = wiphy->bands[IEEE80211_BAND_2GHZ];
823 else if (umac_bss->band == UMAC_BAND_5GHZ)
824 band = wiphy->bands[IEEE80211_BAND_5GHZ];
825 else {
826 IWM_ERR(iwm, "Invalid band: %d\n", umac_bss->band);
827 goto err;
828 }
829
830 freq = ieee80211_channel_to_frequency(umac_bss->channel);
831 channel = ieee80211_get_channel(wiphy, freq);
832 signal = umac_bss->rssi * 100;
833
834 bss->cfg_bss = cfg80211_inform_bss_frame(wiphy, channel,
835 mgmt, frame_len,
836 signal, GFP_KERNEL);
837 if (!bss->cfg_bss)
838 goto err;
839
840 list_add_tail(&bss->node, &iwm->bss_list);
841
842 return 0;
843 err:
844 kfree(bss->bss);
845 kfree(bss);
846
847 return -EINVAL;
848}
849
850static int iwm_mlme_remove_bss(struct iwm_priv *iwm, u8 *buf,
851 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
852{
853 struct iwm_umac_notif_bss_removed *bss_rm =
854 (struct iwm_umac_notif_bss_removed *)buf;
855 struct iwm_bss_info *bss, *next;
856 u16 table_idx;
857 int i;
858
859 for (i = 0; i < le32_to_cpu(bss_rm->count); i++) {
860 table_idx = (le16_to_cpu(bss_rm->entries[i])
861 & IWM_BSS_REMOVE_INDEX_MSK);
862 list_for_each_entry_safe(bss, next, &iwm->bss_list, node)
863 if (bss->bss->table_idx == cpu_to_le16(table_idx)) {
864 struct ieee80211_mgmt *mgmt;
865
866 mgmt = (struct ieee80211_mgmt *)
867 (bss->bss->frame_buf);
868 IWM_DBG_MLME(iwm, ERR,
869 "BSS removed: %pM\n",
870 mgmt->bssid);
871 list_del(&bss->node);
872 kfree(bss->bss);
873 kfree(bss);
874 }
875 }
876
877 return 0;
878}
879
880static int iwm_mlme_mgt_frame(struct iwm_priv *iwm, u8 *buf,
881 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
882{
883 struct iwm_umac_notif_mgt_frame *mgt_frame =
Zhu Yib68518f2009-07-20 11:47:45 +0800884 (struct iwm_umac_notif_mgt_frame *)buf;
Zhu Yibb9f8692009-05-21 21:20:45 +0800885 struct ieee80211_mgmt *mgt = (struct ieee80211_mgmt *)mgt_frame->frame;
Zhu Yibb9f8692009-05-21 21:20:45 +0800886
887 IWM_HEXDUMP(iwm, DBG, MLME, "MGT: ", mgt_frame->frame,
888 le16_to_cpu(mgt_frame->len));
889
890 if (ieee80211_is_assoc_req(mgt->frame_control)) {
Joe Perchesd80050c2009-12-02 20:56:11 -0800891 iwm->req_ie_len = le16_to_cpu(mgt_frame->len)
892 - offsetof(struct ieee80211_mgmt,
893 u.assoc_req.variable);
Zhu Yib68518f2009-07-20 11:47:45 +0800894 kfree(iwm->req_ie);
895 iwm->req_ie = kmemdup(mgt->u.assoc_req.variable,
896 iwm->req_ie_len, GFP_KERNEL);
Zhu Yibb9f8692009-05-21 21:20:45 +0800897 } else if (ieee80211_is_reassoc_req(mgt->frame_control)) {
Joe Perchesd80050c2009-12-02 20:56:11 -0800898 iwm->req_ie_len = le16_to_cpu(mgt_frame->len)
899 - offsetof(struct ieee80211_mgmt,
900 u.reassoc_req.variable);
Zhu Yib68518f2009-07-20 11:47:45 +0800901 kfree(iwm->req_ie);
902 iwm->req_ie = kmemdup(mgt->u.reassoc_req.variable,
903 iwm->req_ie_len, GFP_KERNEL);
Zhu Yibb9f8692009-05-21 21:20:45 +0800904 } else if (ieee80211_is_assoc_resp(mgt->frame_control)) {
Joe Perchesd80050c2009-12-02 20:56:11 -0800905 iwm->resp_ie_len = le16_to_cpu(mgt_frame->len)
906 - offsetof(struct ieee80211_mgmt,
907 u.assoc_resp.variable);
Zhu Yib68518f2009-07-20 11:47:45 +0800908 kfree(iwm->resp_ie);
909 iwm->resp_ie = kmemdup(mgt->u.assoc_resp.variable,
910 iwm->resp_ie_len, GFP_KERNEL);
Zhu Yibb9f8692009-05-21 21:20:45 +0800911 } else if (ieee80211_is_reassoc_resp(mgt->frame_control)) {
Joe Perchesd80050c2009-12-02 20:56:11 -0800912 iwm->resp_ie_len = le16_to_cpu(mgt_frame->len)
913 - offsetof(struct ieee80211_mgmt,
914 u.reassoc_resp.variable);
Zhu Yib68518f2009-07-20 11:47:45 +0800915 kfree(iwm->resp_ie);
916 iwm->resp_ie = kmemdup(mgt->u.reassoc_resp.variable,
917 iwm->resp_ie_len, GFP_KERNEL);
Zhu Yibb9f8692009-05-21 21:20:45 +0800918 } else {
Zhu Yide15fd32009-09-01 15:14:01 +0200919 IWM_ERR(iwm, "Unsupported management frame: 0x%x",
Zhu Yi314524202009-09-01 15:14:03 +0200920 le16_to_cpu(mgt->frame_control));
Zhu Yibb9f8692009-05-21 21:20:45 +0800921 return 0;
922 }
923
Zhu Yibb9f8692009-05-21 21:20:45 +0800924 return 0;
925}
926
927static int iwm_ntf_mlme(struct iwm_priv *iwm, u8 *buf,
928 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
929{
930 struct iwm_umac_notif_wifi_if *notif =
931 (struct iwm_umac_notif_wifi_if *)buf;
932
933 switch (notif->status) {
934 case WIFI_IF_NTFY_ASSOC_START:
935 return iwm_mlme_assoc_start(iwm, buf, buf_size, cmd);
936 case WIFI_IF_NTFY_ASSOC_COMPLETE:
937 return iwm_mlme_assoc_complete(iwm, buf, buf_size, cmd);
938 case WIFI_IF_NTFY_PROFILE_INVALIDATE_COMPLETE:
939 return iwm_mlme_profile_invalidate(iwm, buf, buf_size, cmd);
940 case WIFI_IF_NTFY_CONNECTION_TERMINATED:
Zhu Yic7436272009-09-01 15:14:02 +0200941 return iwm_mlme_connection_terminated(iwm, buf, buf_size, cmd);
Zhu Yibb9f8692009-05-21 21:20:45 +0800942 case WIFI_IF_NTFY_SCAN_COMPLETE:
943 return iwm_mlme_scan_complete(iwm, buf, buf_size, cmd);
944 case WIFI_IF_NTFY_STA_TABLE_CHANGE:
945 return iwm_mlme_update_sta_table(iwm, buf, buf_size, cmd);
946 case WIFI_IF_NTFY_EXTENDED_IE_REQUIRED:
947 IWM_DBG_MLME(iwm, DBG, "Extended IE required\n");
948 break;
Zhu Yib8fcf592009-10-16 13:19:00 +0800949 case WIFI_IF_NTFY_RADIO_PREEMPTION:
950 return iwm_mlme_medium_lost(iwm, buf, buf_size, cmd);
Zhu Yibb9f8692009-05-21 21:20:45 +0800951 case WIFI_IF_NTFY_BSS_TRK_TABLE_CHANGED:
952 return iwm_mlme_update_bss_table(iwm, buf, buf_size, cmd);
953 case WIFI_IF_NTFY_BSS_TRK_ENTRIES_REMOVED:
954 return iwm_mlme_remove_bss(iwm, buf, buf_size, cmd);
955 break;
956 case WIFI_IF_NTFY_MGMT_FRAME:
957 return iwm_mlme_mgt_frame(iwm, buf, buf_size, cmd);
958 case WIFI_DBG_IF_NTFY_SCAN_SUPER_JOB_START:
959 case WIFI_DBG_IF_NTFY_SCAN_SUPER_JOB_COMPLETE:
960 case WIFI_DBG_IF_NTFY_SCAN_CHANNEL_START:
961 case WIFI_DBG_IF_NTFY_SCAN_CHANNEL_RESULT:
962 case WIFI_DBG_IF_NTFY_SCAN_MINI_JOB_START:
963 case WIFI_DBG_IF_NTFY_SCAN_MINI_JOB_COMPLETE:
964 case WIFI_DBG_IF_NTFY_CNCT_ATC_START:
965 case WIFI_DBG_IF_NTFY_COEX_NOTIFICATION:
966 case WIFI_DBG_IF_NTFY_COEX_HANDLE_ENVELOP:
967 case WIFI_DBG_IF_NTFY_COEX_HANDLE_RELEASE_ENVELOP:
968 IWM_DBG_MLME(iwm, DBG, "MLME debug notification: 0x%x\n",
969 notif->status);
970 break;
971 default:
972 IWM_ERR(iwm, "Unhandled notification: 0x%x\n", notif->status);
973 break;
974 }
975
976 return 0;
977}
978
979#define IWM_STATS_UPDATE_INTERVAL (2 * HZ)
980
981static int iwm_ntf_statistics(struct iwm_priv *iwm, u8 *buf,
982 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
983{
984 struct iwm_umac_notif_stats *stats = (struct iwm_umac_notif_stats *)buf;
985 struct iw_statistics *wstats = &iwm->wstats;
986 u16 max_rate = 0;
987 int i;
988
989 IWM_DBG_MLME(iwm, DBG, "Statistics notification received\n");
990
991 if (test_bit(IWM_STATUS_ASSOCIATED, &iwm->status)) {
992 for (i = 0; i < UMAC_NTF_RATE_SAMPLE_NR; i++) {
993 max_rate = max_t(u16, max_rate,
994 max(le16_to_cpu(stats->tx_rate[i]),
995 le16_to_cpu(stats->rx_rate[i])));
996 }
997 /* UMAC passes rate info multiplies by 2 */
998 iwm->rate = max_rate >> 1;
999 }
Zhu Yi257862f2009-06-15 21:59:56 +02001000 iwm->txpower = le32_to_cpu(stats->tx_power);
Zhu Yibb9f8692009-05-21 21:20:45 +08001001
1002 wstats->status = 0;
1003
1004 wstats->discard.nwid = le32_to_cpu(stats->rx_drop_other_bssid);
1005 wstats->discard.code = le32_to_cpu(stats->rx_drop_decode);
1006 wstats->discard.fragment = le32_to_cpu(stats->rx_drop_reassembly);
1007 wstats->discard.retries = le32_to_cpu(stats->tx_drop_max_retry);
1008
1009 wstats->miss.beacon = le32_to_cpu(stats->missed_beacons);
1010
1011 /* according to cfg80211 */
1012 if (stats->rssi_dbm < -110)
1013 wstats->qual.qual = 0;
1014 else if (stats->rssi_dbm > -40)
1015 wstats->qual.qual = 70;
1016 else
1017 wstats->qual.qual = stats->rssi_dbm + 110;
1018
1019 wstats->qual.level = stats->rssi_dbm;
1020 wstats->qual.noise = stats->noise_dbm;
1021 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1022
1023 schedule_delayed_work(&iwm->stats_request, IWM_STATS_UPDATE_INTERVAL);
1024
1025 mod_timer(&iwm->watchdog, round_jiffies(jiffies + IWM_WATCHDOG_PERIOD));
1026
1027 return 0;
1028}
1029
1030static int iwm_ntf_eeprom_proxy(struct iwm_priv *iwm, u8 *buf,
1031 unsigned long buf_size,
1032 struct iwm_wifi_cmd *cmd)
1033{
1034 struct iwm_umac_cmd_eeprom_proxy *eeprom_proxy =
1035 (struct iwm_umac_cmd_eeprom_proxy *)
1036 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
1037 struct iwm_umac_cmd_eeprom_proxy_hdr *hdr = &eeprom_proxy->hdr;
1038 u32 hdr_offset = le32_to_cpu(hdr->offset);
1039 u32 hdr_len = le32_to_cpu(hdr->len);
1040 u32 hdr_type = le32_to_cpu(hdr->type);
1041
1042 IWM_DBG_NTF(iwm, DBG, "type: 0x%x, len: %d, offset: 0x%x\n",
1043 hdr_type, hdr_len, hdr_offset);
1044
1045 if ((hdr_offset + hdr_len) > IWM_EEPROM_LEN)
1046 return -EINVAL;
1047
Zhu Yibb9f8692009-05-21 21:20:45 +08001048 switch (hdr_type) {
1049 case IWM_UMAC_CMD_EEPROM_TYPE_READ:
1050 memcpy(iwm->eeprom + hdr_offset, eeprom_proxy->buf, hdr_len);
1051 break;
1052 case IWM_UMAC_CMD_EEPROM_TYPE_WRITE:
1053 default:
1054 return -ENOTSUPP;
1055 }
1056
1057 return 0;
1058}
1059
1060static int iwm_ntf_channel_info_list(struct iwm_priv *iwm, u8 *buf,
1061 unsigned long buf_size,
1062 struct iwm_wifi_cmd *cmd)
1063{
1064 struct iwm_umac_cmd_get_channel_list *ch_list =
1065 (struct iwm_umac_cmd_get_channel_list *)
1066 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
1067 struct wiphy *wiphy = iwm_to_wiphy(iwm);
1068 struct ieee80211_supported_band *band;
1069 int i;
1070
1071 band = wiphy->bands[IEEE80211_BAND_2GHZ];
1072
1073 for (i = 0; i < band->n_channels; i++) {
1074 unsigned long ch_mask_0 =
1075 le32_to_cpu(ch_list->ch[0].channels_mask);
1076 unsigned long ch_mask_2 =
1077 le32_to_cpu(ch_list->ch[2].channels_mask);
1078
1079 if (!test_bit(i, &ch_mask_0))
1080 band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
1081
1082 if (!test_bit(i, &ch_mask_2))
1083 band->channels[i].flags |= IEEE80211_CHAN_NO_IBSS;
1084 }
1085
1086 band = wiphy->bands[IEEE80211_BAND_5GHZ];
1087
1088 for (i = 0; i < min(band->n_channels, 32); i++) {
1089 unsigned long ch_mask_1 =
1090 le32_to_cpu(ch_list->ch[1].channels_mask);
1091 unsigned long ch_mask_3 =
1092 le32_to_cpu(ch_list->ch[3].channels_mask);
1093
1094 if (!test_bit(i, &ch_mask_1))
1095 band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
1096
1097 if (!test_bit(i, &ch_mask_3))
1098 band->channels[i].flags |= IEEE80211_CHAN_NO_IBSS;
1099 }
1100
1101 return 0;
1102}
1103
Samuel Ortiza7af5302009-11-24 11:33:31 +08001104static int iwm_ntf_stop_resume_tx(struct iwm_priv *iwm, u8 *buf,
1105 unsigned long buf_size,
1106 struct iwm_wifi_cmd *cmd)
1107{
1108 struct iwm_umac_notif_stop_resume_tx *stp_res_tx =
1109 (struct iwm_umac_notif_stop_resume_tx *)buf;
1110 struct iwm_sta_info *sta_info;
1111 struct iwm_tid_info *tid_info;
1112 u8 sta_id = STA_ID_N_COLOR_ID(stp_res_tx->sta_id);
1113 u16 tid_msk = le16_to_cpu(stp_res_tx->stop_resume_tid_msk);
1114 int bit, ret = 0;
1115 bool stop = false;
1116
1117 IWM_DBG_NTF(iwm, DBG, "stop/resume notification:\n"
1118 "\tflags: 0x%x\n"
1119 "\tSTA id: %d\n"
1120 "\tTID bitmask: 0x%x\n",
1121 stp_res_tx->flags, stp_res_tx->sta_id,
1122 stp_res_tx->stop_resume_tid_msk);
1123
1124 if (stp_res_tx->flags & UMAC_STOP_TX_FLAG)
1125 stop = true;
1126
1127 sta_info = &iwm->sta_table[sta_id];
1128 if (!sta_info->valid) {
1129 IWM_ERR(iwm, "Stoping an invalid STA: %d %d\n",
1130 sta_id, stp_res_tx->sta_id);
1131 return -EINVAL;
1132 }
1133
1134 for_each_bit(bit, (unsigned long *)&tid_msk, IWM_UMAC_TID_NR) {
1135 tid_info = &sta_info->tid_info[bit];
1136
1137 mutex_lock(&tid_info->mutex);
1138 tid_info->stopped = stop;
1139 mutex_unlock(&tid_info->mutex);
1140
1141 if (!stop) {
1142 struct iwm_tx_queue *txq;
Roel Kluin8585c2b2009-12-16 17:01:38 +01001143 int queue = iwm_tid_to_queue(bit);
Samuel Ortiza7af5302009-11-24 11:33:31 +08001144
1145 if (queue < 0)
1146 continue;
1147
1148 txq = &iwm->txq[queue];
1149 /*
1150 * If we resume, we have to move our SKBs
1151 * back to the tx queue and queue some work.
1152 */
1153 spin_lock_bh(&txq->lock);
1154 skb_queue_splice_init(&txq->queue, &txq->stopped_queue);
1155 spin_unlock_bh(&txq->lock);
1156
1157 queue_work(txq->wq, &txq->worker);
1158 }
1159
1160 }
1161
1162 /* We send an ACK only for the stop case */
1163 if (stop)
1164 ret = iwm_send_umac_stop_resume_tx(iwm, stp_res_tx);
1165
1166 return ret;
1167}
1168
Zhu Yibb9f8692009-05-21 21:20:45 +08001169static int iwm_ntf_wifi_if_wrapper(struct iwm_priv *iwm, u8 *buf,
1170 unsigned long buf_size,
1171 struct iwm_wifi_cmd *cmd)
1172{
Samuel Ortiz708567e2009-10-16 13:18:55 +08001173 struct iwm_umac_wifi_if *hdr;
1174
1175 if (cmd == NULL) {
1176 IWM_ERR(iwm, "Couldn't find expected wifi command\n");
1177 return -EINVAL;
1178 }
1179
1180 hdr = (struct iwm_umac_wifi_if *)cmd->buf.payload;
Zhu Yibb9f8692009-05-21 21:20:45 +08001181
1182 IWM_DBG_NTF(iwm, DBG, "WIFI_IF_WRAPPER cmd is delivered to UMAC: "
Samuel Ortiza70742f2009-06-15 21:59:51 +02001183 "oid is 0x%x\n", hdr->oid);
1184
1185 if (hdr->oid <= WIFI_IF_NTFY_MAX) {
1186 set_bit(hdr->oid, &iwm->wifi_ntfy[0]);
1187 wake_up_interruptible(&iwm->wifi_ntfy_queue);
1188 } else
1189 return -EINVAL;
Zhu Yibb9f8692009-05-21 21:20:45 +08001190
1191 switch (hdr->oid) {
1192 case UMAC_WIFI_IF_CMD_SET_PROFILE:
1193 iwm->umac_profile_active = 1;
Zhu Yibb9f8692009-05-21 21:20:45 +08001194 break;
1195 default:
1196 break;
1197 }
1198
1199 return 0;
1200}
1201
Samuel Ortize85498b212009-10-16 13:18:48 +08001202#define CT_KILL_DELAY (30 * HZ)
Zhu Yibb9f8692009-05-21 21:20:45 +08001203static int iwm_ntf_card_state(struct iwm_priv *iwm, u8 *buf,
1204 unsigned long buf_size, struct iwm_wifi_cmd *cmd)
1205{
Zhu Yi257862f2009-06-15 21:59:56 +02001206 struct wiphy *wiphy = iwm_to_wiphy(iwm);
Zhu Yibb9f8692009-05-21 21:20:45 +08001207 struct iwm_lmac_card_state *state = (struct iwm_lmac_card_state *)
1208 (buf + sizeof(struct iwm_umac_wifi_in_hdr));
1209 u32 flags = le32_to_cpu(state->flags);
1210
1211 IWM_INFO(iwm, "HW RF Kill %s, CT Kill %s\n",
1212 flags & IWM_CARD_STATE_HW_DISABLED ? "ON" : "OFF",
1213 flags & IWM_CARD_STATE_CTKILL_DISABLED ? "ON" : "OFF");
1214
Samuel Ortize85498b212009-10-16 13:18:48 +08001215 if (flags & IWM_CARD_STATE_CTKILL_DISABLED) {
1216 /*
1217 * We got a CTKILL event: We bring the interface down in
1218 * oder to cool the device down, and try to bring it up
1219 * 30 seconds later. If it's still too hot, we'll go through
1220 * this code path again.
1221 */
1222 cancel_delayed_work_sync(&iwm->ct_kill_delay);
1223 schedule_delayed_work(&iwm->ct_kill_delay, CT_KILL_DELAY);
1224 }
1225
1226 wiphy_rfkill_set_hw_state(wiphy, flags &
1227 (IWM_CARD_STATE_HW_DISABLED |
1228 IWM_CARD_STATE_CTKILL_DISABLED));
Zhu Yibb9f8692009-05-21 21:20:45 +08001229
1230 return 0;
1231}
1232
1233static int iwm_rx_handle_wifi(struct iwm_priv *iwm, u8 *buf,
1234 unsigned long buf_size)
1235{
1236 struct iwm_umac_wifi_in_hdr *wifi_hdr;
1237 struct iwm_wifi_cmd *cmd;
1238 u8 source, cmd_id;
1239 u16 seq_num;
1240 u32 count;
1241 u8 resp;
1242
1243 wifi_hdr = (struct iwm_umac_wifi_in_hdr *)buf;
1244 cmd_id = wifi_hdr->sw_hdr.cmd.cmd;
1245
1246 source = GET_VAL32(wifi_hdr->hw_hdr.cmd, UMAC_HDI_IN_CMD_SOURCE);
1247 if (source >= IWM_SRC_NUM) {
1248 IWM_CRIT(iwm, "invalid source %d\n", source);
1249 return -EINVAL;
1250 }
1251
1252 count = (GET_VAL32(wifi_hdr->sw_hdr.meta_data, UMAC_FW_CMD_BYTE_COUNT));
1253 count += sizeof(struct iwm_umac_wifi_in_hdr) -
1254 sizeof(struct iwm_dev_cmd_hdr);
1255 if (count > buf_size) {
1256 IWM_CRIT(iwm, "count %d, buf size:%ld\n", count, buf_size);
1257 return -EINVAL;
1258 }
1259
1260 resp = GET_VAL32(wifi_hdr->sw_hdr.meta_data, UMAC_FW_CMD_STATUS);
1261
1262 seq_num = le16_to_cpu(wifi_hdr->sw_hdr.cmd.seq_num);
1263
1264 IWM_DBG_RX(iwm, DBG, "CMD:0x%x, source: 0x%x, seqnum: %d\n",
1265 cmd_id, source, seq_num);
1266
1267 /*
1268 * If this is a response to a previously sent command, there must
1269 * be a pending command for this sequence number.
1270 */
1271 cmd = iwm_get_pending_wifi_cmd(iwm, seq_num);
1272
1273 /* Notify the caller only for sync commands. */
1274 switch (source) {
1275 case UMAC_HDI_IN_SOURCE_FHRX:
1276 if (iwm->lmac_handlers[cmd_id] &&
1277 test_bit(cmd_id, &iwm->lmac_handler_map[0]))
1278 return iwm_notif_send(iwm, cmd, cmd_id, source,
1279 buf, count);
1280 break;
1281 case UMAC_HDI_IN_SOURCE_FW:
1282 if (iwm->umac_handlers[cmd_id] &&
1283 test_bit(cmd_id, &iwm->umac_handler_map[0]))
1284 return iwm_notif_send(iwm, cmd, cmd_id, source,
1285 buf, count);
1286 break;
1287 case UMAC_HDI_IN_SOURCE_UDMA:
1288 break;
1289 }
1290
1291 return iwm_rx_handle_resp(iwm, buf, count, cmd);
1292}
1293
1294int iwm_rx_handle_resp(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size,
1295 struct iwm_wifi_cmd *cmd)
1296{
1297 u8 source, cmd_id;
1298 struct iwm_umac_wifi_in_hdr *wifi_hdr;
1299 int ret = 0;
1300
1301 wifi_hdr = (struct iwm_umac_wifi_in_hdr *)buf;
1302 cmd_id = wifi_hdr->sw_hdr.cmd.cmd;
1303
1304 source = GET_VAL32(wifi_hdr->hw_hdr.cmd, UMAC_HDI_IN_CMD_SOURCE);
1305
1306 IWM_DBG_RX(iwm, DBG, "CMD:0x%x, source: 0x%x\n", cmd_id, source);
1307
1308 switch (source) {
1309 case UMAC_HDI_IN_SOURCE_FHRX:
1310 if (iwm->lmac_handlers[cmd_id])
1311 ret = iwm->lmac_handlers[cmd_id]
1312 (iwm, buf, buf_size, cmd);
1313 break;
1314 case UMAC_HDI_IN_SOURCE_FW:
1315 if (iwm->umac_handlers[cmd_id])
1316 ret = iwm->umac_handlers[cmd_id]
1317 (iwm, buf, buf_size, cmd);
1318 break;
1319 case UMAC_HDI_IN_SOURCE_UDMA:
1320 ret = -EINVAL;
1321 break;
1322 }
1323
1324 kfree(cmd);
1325
1326 return ret;
1327}
1328
1329static int iwm_rx_handle_nonwifi(struct iwm_priv *iwm, u8 *buf,
1330 unsigned long buf_size)
1331{
1332 u8 seq_num;
1333 struct iwm_udma_in_hdr *hdr = (struct iwm_udma_in_hdr *)buf;
1334 struct iwm_nonwifi_cmd *cmd, *next;
1335
1336 seq_num = GET_VAL32(hdr->cmd, UDMA_HDI_IN_CMD_NON_WIFI_HW_SEQ_NUM);
1337
1338 /*
1339 * We received a non wifi answer.
1340 * Let's check if there's a pending command for it, and if so
1341 * replace the command payload with the buffer, and then wake the
1342 * callers up.
1343 * That means we only support synchronised non wifi command response
1344 * schemes.
1345 */
1346 list_for_each_entry_safe(cmd, next, &iwm->nonwifi_pending_cmd, pending)
1347 if (cmd->seq_num == seq_num) {
1348 cmd->resp_received = 1;
1349 cmd->buf.len = buf_size;
1350 memcpy(cmd->buf.hdr, buf, buf_size);
1351 wake_up_interruptible(&iwm->nonwifi_queue);
1352 }
1353
1354 return 0;
1355}
1356
1357static int iwm_rx_handle_umac(struct iwm_priv *iwm, u8 *buf,
1358 unsigned long buf_size)
1359{
1360 int ret = 0;
1361 u8 op_code;
1362 unsigned long buf_offset = 0;
1363 struct iwm_udma_in_hdr *hdr;
1364
1365 /*
1366 * To allow for a more efficient bus usage, UMAC
1367 * messages are encapsulated into UDMA ones. This
1368 * way we can have several UMAC messages in one bus
1369 * transfer.
1370 * A UDMA frame size is always aligned on 16 bytes,
1371 * and a UDMA frame must not start with a UMAC_PAD_TERMINAL
1372 * word. This is how we parse a bus frame into several
1373 * UDMA ones.
1374 */
1375 while (buf_offset < buf_size) {
1376
1377 hdr = (struct iwm_udma_in_hdr *)(buf + buf_offset);
1378
1379 if (iwm_rx_check_udma_hdr(hdr) < 0) {
1380 IWM_DBG_RX(iwm, DBG, "End of frame\n");
1381 break;
1382 }
1383
1384 op_code = GET_VAL32(hdr->cmd, UMAC_HDI_IN_CMD_OPCODE);
1385
1386 IWM_DBG_RX(iwm, DBG, "Op code: 0x%x\n", op_code);
1387
1388 if (op_code == UMAC_HDI_IN_OPCODE_WIFI) {
1389 ret |= iwm_rx_handle_wifi(iwm, buf + buf_offset,
1390 buf_size - buf_offset);
1391 } else if (op_code < UMAC_HDI_IN_OPCODE_NONWIFI_MAX) {
1392 if (GET_VAL32(hdr->cmd,
1393 UDMA_HDI_IN_CMD_NON_WIFI_HW_SIG) !=
1394 UDMA_HDI_IN_CMD_NON_WIFI_HW_SIG) {
1395 IWM_ERR(iwm, "Incorrect hw signature\n");
1396 return -EINVAL;
1397 }
1398 ret |= iwm_rx_handle_nonwifi(iwm, buf + buf_offset,
1399 buf_size - buf_offset);
1400 } else {
1401 IWM_ERR(iwm, "Invalid RX opcode: 0x%x\n", op_code);
1402 ret |= -EINVAL;
1403 }
1404
1405 buf_offset += iwm_rx_resp_size(hdr);
1406 }
1407
1408 return ret;
1409}
1410
1411int iwm_rx_handle(struct iwm_priv *iwm, u8 *buf, unsigned long buf_size)
1412{
1413 struct iwm_udma_in_hdr *hdr;
1414
1415 hdr = (struct iwm_udma_in_hdr *)buf;
1416
1417 switch (le32_to_cpu(hdr->cmd)) {
1418 case UMAC_REBOOT_BARKER:
Samuel Ortiz7fd6b122009-10-16 13:18:58 +08001419 if (test_bit(IWM_STATUS_READY, &iwm->status)) {
1420 IWM_ERR(iwm, "Unexpected BARKER\n");
1421
1422 schedule_work(&iwm->reset_worker);
1423
1424 return 0;
1425 }
1426
Zhu Yibb9f8692009-05-21 21:20:45 +08001427 return iwm_notif_send(iwm, NULL, IWM_BARKER_REBOOT_NOTIFICATION,
1428 IWM_SRC_UDMA, buf, buf_size);
1429 case UMAC_ACK_BARKER:
1430 return iwm_notif_send(iwm, NULL, IWM_ACK_BARKER_NOTIFICATION,
1431 IWM_SRC_UDMA, NULL, 0);
1432 default:
1433 IWM_DBG_RX(iwm, DBG, "Received cmd: 0x%x\n", hdr->cmd);
1434 return iwm_rx_handle_umac(iwm, buf, buf_size);
1435 }
1436
1437 return 0;
1438}
1439
1440static const iwm_handler iwm_umac_handlers[] =
1441{
1442 [UMAC_NOTIFY_OPCODE_ERROR] = iwm_ntf_error,
1443 [UMAC_NOTIFY_OPCODE_ALIVE] = iwm_ntf_umac_alive,
1444 [UMAC_NOTIFY_OPCODE_INIT_COMPLETE] = iwm_ntf_init_complete,
1445 [UMAC_NOTIFY_OPCODE_WIFI_CORE_STATUS] = iwm_ntf_wifi_status,
1446 [UMAC_NOTIFY_OPCODE_WIFI_IF_WRAPPER] = iwm_ntf_mlme,
1447 [UMAC_NOTIFY_OPCODE_PAGE_DEALLOC] = iwm_ntf_tx_credit_update,
1448 [UMAC_NOTIFY_OPCODE_RX_TICKET] = iwm_ntf_rx_ticket,
1449 [UMAC_CMD_OPCODE_RESET] = iwm_ntf_umac_reset,
1450 [UMAC_NOTIFY_OPCODE_STATS] = iwm_ntf_statistics,
1451 [UMAC_CMD_OPCODE_EEPROM_PROXY] = iwm_ntf_eeprom_proxy,
1452 [UMAC_CMD_OPCODE_GET_CHAN_INFO_LIST] = iwm_ntf_channel_info_list,
Samuel Ortiza7af5302009-11-24 11:33:31 +08001453 [UMAC_CMD_OPCODE_STOP_RESUME_STA_TX] = iwm_ntf_stop_resume_tx,
Zhu Yibb9f8692009-05-21 21:20:45 +08001454 [REPLY_RX_MPDU_CMD] = iwm_ntf_rx_packet,
1455 [UMAC_CMD_OPCODE_WIFI_IF_WRAPPER] = iwm_ntf_wifi_if_wrapper,
1456};
1457
1458static const iwm_handler iwm_lmac_handlers[] =
1459{
1460 [REPLY_TX] = iwm_ntf_tx,
1461 [REPLY_ALIVE] = iwm_ntf_lmac_version,
1462 [CALIBRATION_RES_NOTIFICATION] = iwm_ntf_calib_res,
1463 [CALIBRATION_COMPLETE_NOTIFICATION] = iwm_ntf_calib_complete,
1464 [CALIBRATION_CFG_CMD] = iwm_ntf_calib_cfg,
1465 [REPLY_RX_MPDU_CMD] = iwm_ntf_rx_packet,
1466 [CARD_STATE_NOTIFICATION] = iwm_ntf_card_state,
1467};
1468
1469void iwm_rx_setup_handlers(struct iwm_priv *iwm)
1470{
1471 iwm->umac_handlers = (iwm_handler *) iwm_umac_handlers;
1472 iwm->lmac_handlers = (iwm_handler *) iwm_lmac_handlers;
1473}
1474
1475static void iwm_remove_iv(struct sk_buff *skb, u32 hdr_total_len)
1476{
1477 struct ieee80211_hdr *hdr;
1478 unsigned int hdr_len;
1479
1480 hdr = (struct ieee80211_hdr *)skb->data;
1481
1482 if (!ieee80211_has_protected(hdr->frame_control))
1483 return;
1484
1485 hdr_len = ieee80211_hdrlen(hdr->frame_control);
1486 if (hdr_total_len <= hdr_len)
1487 return;
1488
1489 memmove(skb->data + (hdr_total_len - hdr_len), skb->data, hdr_len);
1490 skb_pull(skb, (hdr_total_len - hdr_len));
1491}
1492
1493static void iwm_rx_adjust_packet(struct iwm_priv *iwm,
1494 struct iwm_rx_packet *packet,
1495 struct iwm_rx_ticket_node *ticket_node)
1496{
1497 u32 payload_offset = 0, payload_len;
1498 struct iwm_rx_ticket *ticket = ticket_node->ticket;
1499 struct iwm_rx_mpdu_hdr *mpdu_hdr;
1500 struct ieee80211_hdr *hdr;
1501
1502 mpdu_hdr = (struct iwm_rx_mpdu_hdr *)packet->skb->data;
1503 payload_offset += sizeof(struct iwm_rx_mpdu_hdr);
1504 /* Padding is 0 or 2 bytes */
1505 payload_len = le16_to_cpu(mpdu_hdr->len) +
1506 (le16_to_cpu(ticket->flags) & IWM_RX_TICKET_PAD_SIZE_MSK);
1507 payload_len -= ticket->tail_len;
1508
1509 IWM_DBG_RX(iwm, DBG, "Packet adjusted, len:%d, offset:%d, "
1510 "ticket offset:%d ticket tail len:%d\n",
1511 payload_len, payload_offset, ticket->payload_offset,
1512 ticket->tail_len);
1513
1514 IWM_HEXDUMP(iwm, DBG, RX, "RAW: ", packet->skb->data, packet->skb->len);
1515
1516 skb_pull(packet->skb, payload_offset);
1517 skb_trim(packet->skb, payload_len);
1518
1519 iwm_remove_iv(packet->skb, ticket->payload_offset);
1520
1521 hdr = (struct ieee80211_hdr *) packet->skb->data;
1522 if (ieee80211_is_data_qos(hdr->frame_control)) {
1523 /* UMAC handed QOS_DATA frame with 2 padding bytes appended
1524 * to the qos_ctl field in IEEE 802.11 headers. */
1525 memmove(packet->skb->data + IEEE80211_QOS_CTL_LEN + 2,
1526 packet->skb->data,
1527 ieee80211_hdrlen(hdr->frame_control) -
1528 IEEE80211_QOS_CTL_LEN);
1529 hdr = (struct ieee80211_hdr *) skb_pull(packet->skb,
1530 IEEE80211_QOS_CTL_LEN + 2);
1531 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1532 }
1533
1534 IWM_HEXDUMP(iwm, DBG, RX, "ADJUSTED: ",
1535 packet->skb->data, packet->skb->len);
1536}
1537
1538static void classify8023(struct sk_buff *skb)
1539{
1540 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1541
1542 if (ieee80211_is_data_qos(hdr->frame_control)) {
1543 u8 *qc = ieee80211_get_qos_ctl(hdr);
1544 /* frame has qos control */
1545 skb->priority = *qc & IEEE80211_QOS_CTL_TID_MASK;
1546 } else {
1547 skb->priority = 0;
1548 }
1549}
1550
Zhu Yi18974b52009-12-01 10:18:38 +08001551static void iwm_rx_process_amsdu(struct iwm_priv *iwm, struct sk_buff *skb)
1552{
1553 struct wireless_dev *wdev = iwm_to_wdev(iwm);
1554 struct net_device *ndev = iwm_to_ndev(iwm);
1555 struct sk_buff_head list;
1556 struct sk_buff *frame;
1557
1558 IWM_HEXDUMP(iwm, DBG, RX, "A-MSDU: ", skb->data, skb->len);
1559
1560 __skb_queue_head_init(&list);
1561 ieee80211_amsdu_to_8023s(skb, &list, ndev->dev_addr, wdev->iftype, 0);
1562
1563 while ((frame = __skb_dequeue(&list))) {
1564 ndev->stats.rx_packets++;
1565 ndev->stats.rx_bytes += frame->len;
1566
1567 frame->protocol = eth_type_trans(frame, ndev);
1568 frame->ip_summed = CHECKSUM_NONE;
1569 memset(frame->cb, 0, sizeof(frame->cb));
1570
1571 if (netif_rx_ni(frame) == NET_RX_DROP) {
1572 IWM_ERR(iwm, "Packet dropped\n");
1573 ndev->stats.rx_dropped++;
1574 }
1575 }
1576}
1577
Zhu Yibb9f8692009-05-21 21:20:45 +08001578static void iwm_rx_process_packet(struct iwm_priv *iwm,
1579 struct iwm_rx_packet *packet,
1580 struct iwm_rx_ticket_node *ticket_node)
1581{
1582 int ret;
1583 struct sk_buff *skb = packet->skb;
1584 struct wireless_dev *wdev = iwm_to_wdev(iwm);
1585 struct net_device *ndev = iwm_to_ndev(iwm);
1586
1587 IWM_DBG_RX(iwm, DBG, "Processing packet ID %d\n", packet->id);
1588
1589 switch (le16_to_cpu(ticket_node->ticket->action)) {
1590 case IWM_RX_TICKET_RELEASE:
1591 IWM_DBG_RX(iwm, DBG, "RELEASE packet\n");
Zhu Yi18974b52009-12-01 10:18:38 +08001592
Zhu Yibb9f8692009-05-21 21:20:45 +08001593 iwm_rx_adjust_packet(iwm, packet, ticket_node);
Zhu Yi18974b52009-12-01 10:18:38 +08001594 skb->dev = iwm_to_ndev(iwm);
1595 classify8023(skb);
1596
1597 if (le16_to_cpu(ticket_node->ticket->flags) &
1598 IWM_RX_TICKET_AMSDU_MSK) {
1599 iwm_rx_process_amsdu(iwm, skb);
1600 break;
1601 }
1602
Zhu Yibb9f8692009-05-21 21:20:45 +08001603 ret = ieee80211_data_to_8023(skb, ndev->dev_addr, wdev->iftype);
1604 if (ret < 0) {
1605 IWM_DBG_RX(iwm, DBG, "Couldn't convert 802.11 header - "
1606 "%d\n", ret);
Zhu Yi18974b52009-12-01 10:18:38 +08001607 kfree_skb(packet->skb);
Zhu Yibb9f8692009-05-21 21:20:45 +08001608 break;
1609 }
1610
1611 IWM_HEXDUMP(iwm, DBG, RX, "802.3: ", skb->data, skb->len);
1612
Zhu Yi18974b52009-12-01 10:18:38 +08001613 ndev->stats.rx_packets++;
1614 ndev->stats.rx_bytes += skb->len;
1615
Zhu Yibb9f8692009-05-21 21:20:45 +08001616 skb->protocol = eth_type_trans(skb, ndev);
Zhu Yi3a0e4852009-07-16 17:34:07 +08001617 skb->ip_summed = CHECKSUM_NONE;
Zhu Yibb9f8692009-05-21 21:20:45 +08001618 memset(skb->cb, 0, sizeof(skb->cb));
1619
Zhu Yidd13fd62009-06-25 18:28:30 +08001620 if (netif_rx_ni(skb) == NET_RX_DROP) {
Zhu Yibb9f8692009-05-21 21:20:45 +08001621 IWM_ERR(iwm, "Packet dropped\n");
1622 ndev->stats.rx_dropped++;
1623 }
1624 break;
1625 case IWM_RX_TICKET_DROP:
Samuel Ortiz69cf6e22009-10-16 13:18:50 +08001626 IWM_DBG_RX(iwm, DBG, "DROP packet: 0x%x\n",
1627 le16_to_cpu(ticket_node->ticket->flags));
Zhu Yibb9f8692009-05-21 21:20:45 +08001628 kfree_skb(packet->skb);
1629 break;
1630 default:
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001631 IWM_ERR(iwm, "Unknown ticket action: %d\n",
Zhu Yibb9f8692009-05-21 21:20:45 +08001632 le16_to_cpu(ticket_node->ticket->action));
1633 kfree_skb(packet->skb);
1634 }
1635
1636 kfree(packet);
1637 iwm_rx_ticket_node_free(ticket_node);
1638}
1639
1640/*
1641 * Rx data processing:
1642 *
1643 * We're receiving Rx packet from the LMAC, and Rx ticket from
1644 * the UMAC.
1645 * To forward a target data packet upstream (i.e. to the
1646 * kernel network stack), we must have received an Rx ticket
1647 * that tells us we're allowed to release this packet (ticket
1648 * action is IWM_RX_TICKET_RELEASE). The Rx ticket also indicates,
1649 * among other things, where valid data actually starts in the Rx
1650 * packet.
1651 */
1652void iwm_rx_worker(struct work_struct *work)
1653{
1654 struct iwm_priv *iwm;
1655 struct iwm_rx_ticket_node *ticket, *next;
1656
1657 iwm = container_of(work, struct iwm_priv, rx_worker);
1658
1659 /*
1660 * We go through the tickets list and if there is a pending
1661 * packet for it, we push it upstream.
1662 * We stop whenever a ticket is missing its packet, as we're
1663 * supposed to send the packets in order.
1664 */
1665 list_for_each_entry_safe(ticket, next, &iwm->rx_tickets, node) {
1666 struct iwm_rx_packet *packet =
1667 iwm_rx_packet_get(iwm, le16_to_cpu(ticket->ticket->id));
1668
1669 if (!packet) {
1670 IWM_DBG_RX(iwm, DBG, "Skip rx_work: Wait for ticket %d "
1671 "to be handled first\n",
1672 le16_to_cpu(ticket->ticket->id));
1673 return;
1674 }
1675
1676 list_del(&ticket->node);
1677 list_del(&packet->node);
1678 iwm_rx_process_packet(iwm, packet, ticket);
1679 }
1680}
1681