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