2 * Atheros CARL9170 driver
4 * 802.11 & command trap routines
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING. If not, see
21 * http://www.gnu.org/licenses/.
23 * This file incorporates work covered by the following copyright and
25 * Copyright (c) 2007-2008 Atheros Communications, Inc.
27 * Permission to use, copy, modify, and/or distribute this software for any
28 * purpose with or without fee is hereby granted, provided that the above
29 * copyright notice and this permission notice appear in all copies.
31 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
32 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
34 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
35 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
36 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
37 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 #include <linux/init.h>
41 #include <linux/slab.h>
42 #include <linux/module.h>
43 #include <linux/etherdevice.h>
44 #include <linux/crc32.h>
45 #include <net/mac80211.h>
50 static void carl9170_dbg_message(struct ar9170
*ar
, const char *buf
, u32 len
)
53 enum carl9170_restart_reasons reason
= CARL9170_RR_NO_REASON
;
56 if (memcmp(buf
, CARL9170_ERR_MAGIC
, 3) == 0) {
58 if (ar
->fw
.err_counter
> 3) {
60 reason
= CARL9170_RR_TOO_MANY_FIRMWARE_ERRORS
;
64 if (memcmp(buf
, CARL9170_BUG_MAGIC
, 3) == 0) {
67 reason
= CARL9170_RR_FATAL_FIRMWARE_ERROR
;
71 wiphy_info(ar
->hw
->wiphy
, "FW: %.*s\n", len
, buf
);
74 carl9170_restart(ar
, reason
);
77 static void carl9170_handle_ps(struct ar9170
*ar
, struct carl9170_rsp
*rsp
)
82 ps
= le32_to_cpu(rsp
->psm
.state
);
84 new_ps
= (ps
& CARL9170_PSM_COUNTER
) != CARL9170_PSM_WAKE
;
85 if (ar
->ps
.state
!= new_ps
) {
87 ar
->ps
.sleep_ms
= jiffies_to_msecs(jiffies
-
91 ar
->ps
.last_action
= jiffies
;
93 ar
->ps
.state
= new_ps
;
97 static int carl9170_check_sequence(struct ar9170
*ar
, unsigned int seq
)
109 * The sequence is strictly monotonic increasing and it never skips!
111 * Therefore we can safely assume that whenever we received an
112 * unexpected sequence we have lost some valuable data.
114 if (seq
!= ar
->cmd_seq
) {
117 count
= (seq
- ar
->cmd_seq
) % ar
->fw
.cmd_bufs
;
119 wiphy_err(ar
->hw
->wiphy
, "lost %d command responses/traps! "
120 "w:%d g:%d\n", count
, ar
->cmd_seq
, seq
);
122 carl9170_restart(ar
, CARL9170_RR_LOST_RSP
);
126 ar
->cmd_seq
= (ar
->cmd_seq
+ 1) % ar
->fw
.cmd_bufs
;
130 static void carl9170_cmd_callback(struct ar9170
*ar
, u32 len
, void *buffer
)
133 * Some commands may have a variable response length
134 * and we cannot predict the correct length in advance.
135 * So we only check if we provided enough space for the data.
137 if (unlikely(ar
->readlen
!= (len
- 4))) {
138 dev_warn(&ar
->udev
->dev
, "received invalid command response:"
139 "got %d, instead of %d\n", len
- 4, ar
->readlen
);
140 print_hex_dump_bytes("carl9170 cmd:", DUMP_PREFIX_OFFSET
,
141 ar
->cmd_buf
, (ar
->cmd
.hdr
.len
+ 4) & 0x3f);
142 print_hex_dump_bytes("carl9170 rsp:", DUMP_PREFIX_OFFSET
,
145 * Do not complete. The command times out,
146 * and we get a stack trace from there.
148 carl9170_restart(ar
, CARL9170_RR_INVALID_RSP
);
151 spin_lock(&ar
->cmd_lock
);
154 memcpy(ar
->readbuf
, buffer
+ 4, len
- 4);
158 complete(&ar
->cmd_wait
);
159 spin_unlock(&ar
->cmd_lock
);
162 void carl9170_handle_command_response(struct ar9170
*ar
, void *buf
, u32 len
)
164 struct carl9170_rsp
*cmd
= (void *) buf
;
165 struct ieee80211_vif
*vif
;
167 if (carl9170_check_sequence(ar
, cmd
->hdr
.seq
))
170 if ((cmd
->hdr
.cmd
& CARL9170_RSP_FLAG
) != CARL9170_RSP_FLAG
) {
171 if (!(cmd
->hdr
.cmd
& CARL9170_CMD_ASYNC_FLAG
))
172 carl9170_cmd_callback(ar
, len
, buf
);
177 if (unlikely(cmd
->hdr
.len
!= (len
- 4))) {
178 if (net_ratelimit()) {
179 wiphy_err(ar
->hw
->wiphy
, "FW: received over-/under"
180 "sized event %x (%d, but should be %d).\n",
181 cmd
->hdr
.cmd
, cmd
->hdr
.len
, len
- 4);
183 print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE
,
190 /* hardware event handlers */
191 switch (cmd
->hdr
.cmd
) {
192 case CARL9170_RSP_PRETBTT
:
195 vif
= carl9170_get_main_vif(ar
);
203 case NL80211_IFTYPE_STATION
:
204 carl9170_handle_ps(ar
, cmd
);
207 case NL80211_IFTYPE_AP
:
208 case NL80211_IFTYPE_ADHOC
:
209 carl9170_update_beacon(ar
, true);
220 case CARL9170_RSP_TXCOMP
:
221 /* TX status notification */
222 carl9170_tx_process_status(ar
, cmd
);
225 case CARL9170_RSP_BEACON_CONFIG
:
227 * (IBSS) beacon send notification
228 * bytes: 04 c2 XX YY B4 B3 B2 B1
232 * B1-B4 "should" be the number of send out beacons.
236 case CARL9170_RSP_ATIM
:
237 /* End of Atim Window */
240 case CARL9170_RSP_WATCHDOG
:
241 /* Watchdog Interrupt */
242 carl9170_restart(ar
, CARL9170_RR_WATCHDOG
);
245 case CARL9170_RSP_TEXT
:
247 carl9170_dbg_message(ar
, (char *)buf
+ 4, len
- 4);
250 case CARL9170_RSP_HEXDUMP
:
251 wiphy_dbg(ar
->hw
->wiphy
, "FW: HD %d\n", len
- 4);
252 print_hex_dump_bytes("FW:", DUMP_PREFIX_NONE
,
253 (char *)buf
+ 4, len
- 4);
256 case CARL9170_RSP_RADAR
:
257 if (!net_ratelimit())
260 wiphy_info(ar
->hw
->wiphy
, "FW: RADAR! Please report this "
261 "incident to linux-wireless@vger.kernel.org !\n");
264 case CARL9170_RSP_GPIO
:
265 #ifdef CONFIG_CARL9170_WPC
267 bool state
= !!(cmd
->gpio
.gpio
& cpu_to_le32(
268 AR9170_GPIO_PORT_WPS_BUTTON_PRESSED
));
270 if (state
!= ar
->wps
.pbc_state
) {
271 ar
->wps
.pbc_state
= state
;
272 input_report_key(ar
->wps
.pbc
, KEY_WPS_BUTTON
,
274 input_sync(ar
->wps
.pbc
);
277 #endif /* CONFIG_CARL9170_WPC */
280 case CARL9170_RSP_BOOT
:
281 complete(&ar
->fw_boot_wait
);
285 wiphy_err(ar
->hw
->wiphy
, "FW: received unhandled event %x\n",
287 print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE
, buf
, len
);
292 static int carl9170_rx_mac_status(struct ar9170
*ar
,
293 struct ar9170_rx_head
*head
, struct ar9170_rx_macstatus
*mac
,
294 struct ieee80211_rx_status
*status
)
296 struct ieee80211_channel
*chan
;
299 BUILD_BUG_ON(sizeof(struct ar9170_rx_head
) != 12);
300 BUILD_BUG_ON(sizeof(struct ar9170_rx_macstatus
) != 4);
304 if (error
& AR9170_RX_ERROR_WRONG_RA
) {
305 if (!ar
->sniffer_enabled
)
309 if (error
& AR9170_RX_ERROR_PLCP
) {
310 if (!(ar
->filter_state
& FIF_PLCPFAIL
))
313 status
->flag
|= RX_FLAG_FAILED_PLCP_CRC
;
316 if (error
& AR9170_RX_ERROR_FCS
) {
319 if (!(ar
->filter_state
& FIF_FCSFAIL
))
322 status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
325 decrypt
= ar9170_get_decrypt_type(mac
);
326 if (!(decrypt
& AR9170_RX_ENC_SOFTWARE
) &&
327 decrypt
!= AR9170_ENC_ALG_NONE
) {
328 if ((decrypt
== AR9170_ENC_ALG_TKIP
) &&
329 (error
& AR9170_RX_ERROR_MMIC
))
330 status
->flag
|= RX_FLAG_MMIC_ERROR
;
332 status
->flag
|= RX_FLAG_DECRYPTED
;
335 if (error
& AR9170_RX_ERROR_DECRYPT
&& !ar
->sniffer_enabled
)
338 error
&= ~(AR9170_RX_ERROR_MMIC
|
339 AR9170_RX_ERROR_FCS
|
340 AR9170_RX_ERROR_WRONG_RA
|
341 AR9170_RX_ERROR_DECRYPT
|
342 AR9170_RX_ERROR_PLCP
);
344 /* drop any other error frames */
345 if (unlikely(error
)) {
346 /* TODO: update netdevice's RX dropped/errors statistics */
349 wiphy_dbg(ar
->hw
->wiphy
, "received frame with "
350 "suspicious error code (%#x).\n", error
);
357 status
->band
= chan
->band
;
358 status
->freq
= chan
->center_freq
;
361 switch (mac
->status
& AR9170_RX_STATUS_MODULATION
) {
362 case AR9170_RX_STATUS_MODULATION_CCK
:
363 if (mac
->status
& AR9170_RX_STATUS_SHORT_PREAMBLE
)
364 status
->flag
|= RX_FLAG_SHORTPRE
;
365 switch (head
->plcp
[0]) {
366 case AR9170_RX_PHY_RATE_CCK_1M
:
367 status
->rate_idx
= 0;
369 case AR9170_RX_PHY_RATE_CCK_2M
:
370 status
->rate_idx
= 1;
372 case AR9170_RX_PHY_RATE_CCK_5M
:
373 status
->rate_idx
= 2;
375 case AR9170_RX_PHY_RATE_CCK_11M
:
376 status
->rate_idx
= 3;
379 if (net_ratelimit()) {
380 wiphy_err(ar
->hw
->wiphy
, "invalid plcp cck "
381 "rate (%x).\n", head
->plcp
[0]);
388 case AR9170_RX_STATUS_MODULATION_DUPOFDM
:
389 case AR9170_RX_STATUS_MODULATION_OFDM
:
390 switch (head
->plcp
[0] & 0xf) {
391 case AR9170_TXRX_PHY_RATE_OFDM_6M
:
392 status
->rate_idx
= 0;
394 case AR9170_TXRX_PHY_RATE_OFDM_9M
:
395 status
->rate_idx
= 1;
397 case AR9170_TXRX_PHY_RATE_OFDM_12M
:
398 status
->rate_idx
= 2;
400 case AR9170_TXRX_PHY_RATE_OFDM_18M
:
401 status
->rate_idx
= 3;
403 case AR9170_TXRX_PHY_RATE_OFDM_24M
:
404 status
->rate_idx
= 4;
406 case AR9170_TXRX_PHY_RATE_OFDM_36M
:
407 status
->rate_idx
= 5;
409 case AR9170_TXRX_PHY_RATE_OFDM_48M
:
410 status
->rate_idx
= 6;
412 case AR9170_TXRX_PHY_RATE_OFDM_54M
:
413 status
->rate_idx
= 7;
416 if (net_ratelimit()) {
417 wiphy_err(ar
->hw
->wiphy
, "invalid plcp ofdm "
418 "rate (%x).\n", head
->plcp
[0]);
423 if (status
->band
== IEEE80211_BAND_2GHZ
)
424 status
->rate_idx
+= 4;
427 case AR9170_RX_STATUS_MODULATION_HT
:
428 if (head
->plcp
[3] & 0x80)
429 status
->flag
|= RX_FLAG_40MHZ
;
430 if (head
->plcp
[6] & 0x80)
431 status
->flag
|= RX_FLAG_SHORT_GI
;
433 status
->rate_idx
= clamp(0, 75, head
->plcp
[3] & 0x7f);
434 status
->flag
|= RX_FLAG_HT
;
445 static void carl9170_rx_phy_status(struct ar9170
*ar
,
446 struct ar9170_rx_phystatus
*phy
, struct ieee80211_rx_status
*status
)
450 BUILD_BUG_ON(sizeof(struct ar9170_rx_phystatus
) != 20);
452 for (i
= 0; i
< 3; i
++)
453 if (phy
->rssi
[i
] != 0x80)
454 status
->antenna
|= BIT(i
);
456 /* post-process RSSI */
457 for (i
= 0; i
< 7; i
++)
458 if (phy
->rssi
[i
] & 0x80)
459 phy
->rssi
[i
] = ((phy
->rssi
[i
] & 0x7f) + 1) & 0x7f;
461 /* TODO: we could do something with phy_errors */
462 status
->signal
= ar
->noise
[0] + phy
->rssi_combined
;
465 static struct sk_buff
*carl9170_rx_copy_data(u8
*buf
, int len
)
469 struct ieee80211_hdr
*hdr
= (void *) buf
;
471 if (ieee80211_is_data_qos(hdr
->frame_control
)) {
472 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
473 reserved
+= NET_IP_ALIGN
;
475 if (*qc
& IEEE80211_QOS_CTL_A_MSDU_PRESENT
)
476 reserved
+= NET_IP_ALIGN
;
479 if (ieee80211_has_a4(hdr
->frame_control
))
480 reserved
+= NET_IP_ALIGN
;
482 reserved
= 32 + (reserved
& NET_IP_ALIGN
);
484 skb
= dev_alloc_skb(len
+ reserved
);
486 skb_reserve(skb
, reserved
);
487 memcpy(skb_put(skb
, len
), buf
, len
);
493 static u8
*carl9170_find_ie(u8
*data
, unsigned int len
, u8 ie
)
495 struct ieee80211_mgmt
*mgmt
= (void *)data
;
498 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
501 if (pos
+ 2 + pos
[1] > end
)
515 * The firmware is in charge of waking up the device just before
516 * the AP is expected to transmit the next beacon.
518 * This leaves the driver with the important task of deciding when
519 * to set the PHY back to bed again.
521 static void carl9170_ps_beacon(struct ar9170
*ar
, void *data
, unsigned int len
)
523 struct ieee80211_hdr
*hdr
= (void *) data
;
524 struct ieee80211_tim_ie
*tim_ie
;
529 if (likely(!(ar
->hw
->conf
.flags
& IEEE80211_CONF_PS
)))
532 /* check if this really is a beacon */
533 if (!ieee80211_is_beacon(hdr
->frame_control
))
536 /* min. beacon length + FCS_LEN */
537 if (len
<= 40 + FCS_LEN
)
540 /* and only beacons from the associated BSSID, please */
541 if (compare_ether_addr(hdr
->addr3
, ar
->common
.curbssid
) ||
545 ar
->ps
.last_beacon
= jiffies
;
547 tim
= carl9170_find_ie(data
, len
- FCS_LEN
, WLAN_EID_TIM
);
551 if (tim
[1] < sizeof(*tim_ie
))
555 tim_ie
= (struct ieee80211_tim_ie
*) &tim
[2];
557 if (!WARN_ON_ONCE(!ar
->hw
->conf
.ps_dtim_period
))
558 ar
->ps
.dtim_counter
= (tim_ie
->dtim_count
- 1) %
559 ar
->hw
->conf
.ps_dtim_period
;
561 /* Check whenever the PHY can be turned off again. */
563 /* 1. What about buffered unicast traffic for our AID? */
564 cam
= ieee80211_check_tim(tim_ie
, tim_len
, ar
->common
.curaid
);
566 /* 2. Maybe the AP wants to send multicast/broadcast data? */
567 cam
|= !!(tim_ie
->bitmap_ctrl
& 0x01);
570 /* back to low-power land. */
571 ar
->ps
.off_override
&= ~PS_OFF_BCN
;
572 carl9170_ps_check(ar
);
575 ar
->ps
.off_override
|= PS_OFF_BCN
;
579 static bool carl9170_ampdu_check(struct ar9170
*ar
, u8
*buf
, u8 ms
)
583 if ((ms
& AR9170_RX_STATUS_MPDU
) == AR9170_RX_STATUS_MPDU_SINGLE
) {
585 * This frame is not part of an aMPDU.
586 * Therefore it is not subjected to any
587 * of the following content restrictions.
593 * "802.11n - 7.4a.3 A-MPDU contents" describes in which contexts
594 * certain frame types can be part of an aMPDU.
596 * In order to keep the processing cost down, I opted for a
597 * stateless filter solely based on the frame control field.
600 fc
= ((struct ieee80211_hdr
*)buf
)->frame_control
;
601 if (ieee80211_is_data_qos(fc
) && ieee80211_is_data_present(fc
))
604 if (ieee80211_is_ack(fc
) || ieee80211_is_back(fc
) ||
605 ieee80211_is_back_req(fc
))
608 if (ieee80211_is_action(fc
))
615 * If the frame alignment is right (or the kernel has
616 * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there
617 * is only a single MPDU in the USB frame, then we could
618 * submit to mac80211 the SKB directly. However, since
619 * there may be multiple packets in one SKB in stream
620 * mode, and we need to observe the proper ordering,
621 * this is non-trivial.
624 static void carl9170_handle_mpdu(struct ar9170
*ar
, u8
*buf
, int len
)
626 struct ar9170_rx_head
*head
;
627 struct ar9170_rx_macstatus
*mac
;
628 struct ar9170_rx_phystatus
*phy
= NULL
;
629 struct ieee80211_rx_status status
;
637 if (unlikely(len
< sizeof(*mac
)))
640 mpdu_len
= len
- sizeof(*mac
);
642 mac
= (void *)(buf
+ mpdu_len
);
643 mac_status
= mac
->status
;
644 switch (mac_status
& AR9170_RX_STATUS_MPDU
) {
645 case AR9170_RX_STATUS_MPDU_FIRST
:
646 /* Aggregated MPDUs start with an PLCP header */
647 if (likely(mpdu_len
>= sizeof(struct ar9170_rx_head
))) {
651 * The PLCP header needs to be cached for the
652 * following MIDDLE + LAST A-MPDU packets.
654 * So, if you are wondering why all frames seem
655 * to share a common RX status information,
656 * then you have the answer right here...
658 memcpy(&ar
->rx_plcp
, (void *) buf
,
659 sizeof(struct ar9170_rx_head
));
661 mpdu_len
-= sizeof(struct ar9170_rx_head
);
662 buf
+= sizeof(struct ar9170_rx_head
);
664 ar
->rx_has_plcp
= true;
666 if (net_ratelimit()) {
667 wiphy_err(ar
->hw
->wiphy
, "plcp info "
675 case AR9170_RX_STATUS_MPDU_LAST
:
677 * The last frame of an A-MPDU has an extra tail
678 * which does contain the phy status of the whole
682 if (likely(mpdu_len
>= sizeof(struct ar9170_rx_phystatus
))) {
683 mpdu_len
-= sizeof(struct ar9170_rx_phystatus
);
684 phy
= (void *)(buf
+ mpdu_len
);
686 if (net_ratelimit()) {
687 wiphy_err(ar
->hw
->wiphy
, "frame tail "
694 case AR9170_RX_STATUS_MPDU_MIDDLE
:
695 /* These are just data + mac status */
696 if (unlikely(!ar
->rx_has_plcp
)) {
697 if (!net_ratelimit())
700 wiphy_err(ar
->hw
->wiphy
, "rx stream does not start "
701 "with a first_mpdu frame tag.\n");
709 case AR9170_RX_STATUS_MPDU_SINGLE
:
710 /* single mpdu has both: plcp (head) and phy status (tail) */
713 mpdu_len
-= sizeof(struct ar9170_rx_head
);
714 mpdu_len
-= sizeof(struct ar9170_rx_phystatus
);
716 buf
+= sizeof(struct ar9170_rx_head
);
717 phy
= (void *)(buf
+ mpdu_len
);
725 /* FC + DU + RA + FCS */
726 if (unlikely(mpdu_len
< (2 + 2 + ETH_ALEN
+ FCS_LEN
)))
729 memset(&status
, 0, sizeof(status
));
730 if (unlikely(carl9170_rx_mac_status(ar
, head
, mac
, &status
)))
733 if (!carl9170_ampdu_check(ar
, buf
, mac_status
))
737 carl9170_rx_phy_status(ar
, phy
, &status
);
739 carl9170_ps_beacon(ar
, buf
, mpdu_len
);
741 skb
= carl9170_rx_copy_data(buf
, mpdu_len
);
745 memcpy(IEEE80211_SKB_RXCB(skb
), &status
, sizeof(status
));
746 ieee80211_rx(ar
->hw
, skb
);
753 static void carl9170_rx_untie_cmds(struct ar9170
*ar
, const u8
*respbuf
,
754 const unsigned int resplen
)
756 struct carl9170_rsp
*cmd
;
759 while (i
< resplen
) {
760 cmd
= (void *) &respbuf
[i
];
762 i
+= cmd
->hdr
.len
+ 4;
763 if (unlikely(i
> resplen
))
766 carl9170_handle_command_response(ar
, cmd
, cmd
->hdr
.len
+ 4);
769 if (unlikely(i
!= resplen
)) {
770 if (!net_ratelimit())
773 wiphy_err(ar
->hw
->wiphy
, "malformed firmware trap:\n");
774 print_hex_dump_bytes("rxcmd:", DUMP_PREFIX_OFFSET
,
779 static void __carl9170_rx(struct ar9170
*ar
, u8
*buf
, unsigned int len
)
783 /* weird thing, but this is the same in the original driver */
784 while (len
> 2 && i
< 12 && buf
[0] == 0xff && buf
[1] == 0xff) {
790 if (unlikely(len
< 4))
793 /* found the 6 * 0xffff marker? */
795 carl9170_rx_untie_cmds(ar
, buf
, len
);
797 carl9170_handle_mpdu(ar
, buf
, len
);
800 static void carl9170_rx_stream(struct ar9170
*ar
, void *buf
, unsigned int len
)
802 unsigned int tlen
, wlen
= 0, clen
= 0;
803 struct ar9170_stream
*rx_stream
;
810 rx_stream
= (void *) tbuf
;
811 clen
= le16_to_cpu(rx_stream
->length
);
812 wlen
= ALIGN(clen
, 4);
814 /* check if this is stream has a valid tag.*/
815 if (rx_stream
->tag
!= cpu_to_le16(AR9170_RX_STREAM_TAG
)) {
817 * TODO: handle the highly unlikely event that the
818 * corrupted stream has the TAG at the right position.
821 /* check if the frame can be repaired. */
822 if (!ar
->rx_failover_missing
) {
824 /* this is not "short read". */
825 if (net_ratelimit()) {
826 wiphy_err(ar
->hw
->wiphy
,
830 __carl9170_rx(ar
, tbuf
, tlen
);
834 if (ar
->rx_failover_missing
> tlen
) {
835 if (net_ratelimit()) {
836 wiphy_err(ar
->hw
->wiphy
,
838 "stream corruption!\n");
845 memcpy(skb_put(ar
->rx_failover
, tlen
), tbuf
, tlen
);
846 ar
->rx_failover_missing
-= tlen
;
848 if (ar
->rx_failover_missing
<= 0) {
850 * nested carl9170_rx_stream call!
852 * termination is guaranteed, even when the
853 * combined frame also have an element with
857 ar
->rx_failover_missing
= 0;
858 carl9170_rx_stream(ar
, ar
->rx_failover
->data
,
859 ar
->rx_failover
->len
);
861 skb_reset_tail_pointer(ar
->rx_failover
);
862 skb_trim(ar
->rx_failover
, 0);
868 /* check if stream is clipped */
869 if (wlen
> tlen
- 4) {
870 if (ar
->rx_failover_missing
) {
871 /* TODO: handle double stream corruption. */
872 if (net_ratelimit()) {
873 wiphy_err(ar
->hw
->wiphy
, "double rx "
874 "stream corruption!\n");
882 * save incomplete data set.
883 * the firmware will resend the missing bits when
884 * the rx - descriptor comes round again.
887 memcpy(skb_put(ar
->rx_failover
, tlen
), tbuf
, tlen
);
888 ar
->rx_failover_missing
= clen
- tlen
;
891 __carl9170_rx(ar
, rx_stream
->payload
, clen
);
898 if (net_ratelimit()) {
899 wiphy_err(ar
->hw
->wiphy
, "%d bytes of unprocessed "
900 "data left in rx stream!\n", tlen
);
909 wiphy_err(ar
->hw
->wiphy
, "damaged RX stream data [want:%d, "
910 "data:%d, rx:%d, pending:%d ]\n", clen
, wlen
, tlen
,
911 ar
->rx_failover_missing
);
913 if (ar
->rx_failover_missing
)
914 print_hex_dump_bytes("rxbuf:", DUMP_PREFIX_OFFSET
,
915 ar
->rx_failover
->data
,
916 ar
->rx_failover
->len
);
918 print_hex_dump_bytes("stream:", DUMP_PREFIX_OFFSET
,
921 wiphy_err(ar
->hw
->wiphy
, "please check your hardware and cables, if "
922 "you see this message frequently.\n");
925 if (ar
->rx_failover_missing
) {
926 skb_reset_tail_pointer(ar
->rx_failover
);
927 skb_trim(ar
->rx_failover
, 0);
928 ar
->rx_failover_missing
= 0;
932 void carl9170_rx(struct ar9170
*ar
, void *buf
, unsigned int len
)
934 if (ar
->fw
.rx_stream
)
935 carl9170_rx_stream(ar
, buf
, len
);
937 __carl9170_rx(ar
, buf
, len
);