Lines Matching +full:max +full:- +full:bitrate

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
38 b43_tx_legacy_rate_phy_ctl_ent(u8 bitrate) in b43_tx_legacy_rate_phy_ctl_ent() argument
45 if (e->bitrate == bitrate) in b43_tx_legacy_rate_phy_ctl_ent()
53 /* Extract the bitrate index out of a CCK PLCP header. */
56 switch (plcp->raw[0]) { in b43_plcp_get_bitrate_idx_cck()
66 return -1; in b43_plcp_get_bitrate_idx_cck()
69 /* Extract the bitrate index out of an OFDM PLCP header. */
75 switch (plcp->raw[0] & 0xF) { in b43_plcp_get_bitrate_idx_ofdm()
93 return -1; in b43_plcp_get_bitrate_idx_ofdm()
96 u8 b43_plcp_get_ratecode_cck(const u8 bitrate) in b43_plcp_get_ratecode_cck() argument
98 switch (bitrate) { in b43_plcp_get_ratecode_cck()
112 u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate) in b43_plcp_get_ratecode_ofdm() argument
114 switch (bitrate) { in b43_plcp_get_ratecode_ofdm()
137 const u16 octets, const u8 bitrate) in b43_generate_plcp_hdr() argument
139 __u8 *raw = plcp->raw; in b43_generate_plcp_hdr()
141 if (b43_is_ofdm_rate(bitrate)) { in b43_generate_plcp_hdr()
144 d = b43_plcp_get_ratecode_ofdm(bitrate); in b43_generate_plcp_hdr()
147 plcp->data = cpu_to_le32(d); in b43_generate_plcp_hdr()
151 plen = octets * 16 / bitrate; in b43_generate_plcp_hdr()
152 if ((octets * 16 % bitrate) > 0) { in b43_generate_plcp_hdr()
154 if ((bitrate == B43_CCK_RATE_11MB) in b43_generate_plcp_hdr()
161 plcp->data |= cpu_to_le32(plen << 16); in b43_generate_plcp_hdr()
162 raw[0] = b43_plcp_get_ratecode_cck(bitrate); in b43_generate_plcp_hdr()
167 static u16 b43_generate_tx_phy_ctl1(struct b43_wldev *dev, u8 bitrate) in b43_generate_tx_phy_ctl1() argument
169 const struct b43_phy *phy = &dev->phy; in b43_generate_tx_phy_ctl1()
174 if (phy->type == B43_PHYTYPE_LP) in b43_generate_tx_phy_ctl1()
180 } else if (b43_is_cck_rate(bitrate) && phy->type != B43_PHYTYPE_LP) { in b43_generate_tx_phy_ctl1()
184 e = b43_tx_legacy_rate_phy_ctl_ent(bitrate); in b43_generate_tx_phy_ctl1()
186 control |= e->coding_rate; in b43_generate_tx_phy_ctl1()
187 control |= e->modulation; in b43_generate_tx_phy_ctl1()
195 static u8 b43_calc_fallback_rate(u8 bitrate, int gmode) in b43_calc_fallback_rate() argument
197 switch (bitrate) { in b43_calc_fallback_rate()
241 const unsigned char *fragment_data = skb_frag->data; in b43_generate_txhdr()
242 unsigned int fragment_len = skb_frag->len; in b43_generate_txhdr()
244 const struct b43_phy *phy = &dev->phy; in b43_generate_txhdr()
247 int use_encryption = !!info->control.hw_key; in b43_generate_txhdr()
248 __le16 fctl = wlhdr->frame_control; in b43_generate_txhdr()
255 bool fill_phy_ctl1 = (phy->type == B43_PHYTYPE_LP || in b43_generate_txhdr()
256 phy->type == B43_PHYTYPE_N || in b43_generate_txhdr()
257 phy->type == B43_PHYTYPE_HT); in b43_generate_txhdr()
264 txrate = ieee80211_get_tx_rate(dev->wl->hw, info); in b43_generate_txhdr()
265 rate = txrate ? txrate->hw_value : B43_CCK_RATE_1MB; in b43_generate_txhdr()
267 fbrate = ieee80211_get_alt_retry_rate(dev->wl->hw, info, 0) ? : txrate; in b43_generate_txhdr()
268 rate_fb = fbrate->hw_value; in b43_generate_txhdr()
272 txhdr->phy_rate = b43_plcp_get_ratecode_ofdm(rate); in b43_generate_txhdr()
274 txhdr->phy_rate = b43_plcp_get_ratecode_cck(rate); in b43_generate_txhdr()
275 txhdr->mac_frame_ctl = wlhdr->frame_control; in b43_generate_txhdr()
276 memcpy(txhdr->tx_receiver, wlhdr->addr1, ETH_ALEN); in b43_generate_txhdr()
280 (wlhdr->duration_id & cpu_to_le16(0x8000)) || in b43_generate_txhdr()
281 (wlhdr->duration_id == cpu_to_le16(0))) { in b43_generate_txhdr()
285 txhdr->dur_fb = wlhdr->duration_id; in b43_generate_txhdr()
287 txhdr->dur_fb = ieee80211_generic_frame_duration( in b43_generate_txhdr()
288 dev->wl->hw, info->control.vif, info->band, in b43_generate_txhdr()
294 u8 key_idx = info->control.hw_key->hw_key_idx; in b43_generate_txhdr()
299 B43_WARN_ON(key_idx >= ARRAY_SIZE(dev->key)); in b43_generate_txhdr()
300 key = &(dev->key[key_idx]); in b43_generate_txhdr()
302 if (unlikely(!key->keyconf)) { in b43_generate_txhdr()
308 return -ENOKEY; in b43_generate_txhdr()
312 plcp_fragment_len += info->control.hw_key->icv_len; in b43_generate_txhdr()
317 mac_ctl |= (key->algorithm << B43_TXH_MAC_KEYALG_SHIFT) & in b43_generate_txhdr()
320 if (key->algorithm == B43_SEC_ALGO_TKIP) { in b43_generate_txhdr()
326 ieee80211_get_tkip_p1k(info->control.hw_key, skb_frag, phase1key); in b43_generate_txhdr()
327 /* phase1key is in host endian. Copy to little-endian txhdr->iv. */ in b43_generate_txhdr()
329 txhdr->iv[i * 2 + 0] = phase1key[i]; in b43_generate_txhdr()
330 txhdr->iv[i * 2 + 1] = phase1key[i] >> 8; in b43_generate_txhdr()
333 memcpy(txhdr->iv + 10, ((u8 *) wlhdr) + wlhdr_len, 3); in b43_generate_txhdr()
335 iv_len = min_t(size_t, info->control.hw_key->iv_len, in b43_generate_txhdr()
336 ARRAY_SIZE(txhdr->iv)); in b43_generate_txhdr()
337 memcpy(txhdr->iv, ((u8 *) wlhdr) + wlhdr_len, iv_len); in b43_generate_txhdr()
340 switch (dev->fw.hdr_format) { in b43_generate_txhdr()
342 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_598.plcp), in b43_generate_txhdr()
346 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_351.plcp), in b43_generate_txhdr()
350 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->format_410.plcp), in b43_generate_txhdr()
354 b43_generate_plcp_hdr((struct b43_plcp_hdr4 *)(&txhdr->plcp_fb), in b43_generate_txhdr()
367 txhdr->chan_radio_code = phy->channel; in b43_generate_txhdr()
374 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) in b43_generate_txhdr()
397 rates = info->control.rates; in b43_generate_txhdr()
399 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) in b43_generate_txhdr()
401 /* use hardware sequence counter as the non-TID counter */ in b43_generate_txhdr()
402 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) in b43_generate_txhdr()
404 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) in b43_generate_txhdr()
406 if (!phy->gmode) in b43_generate_txhdr()
414 (rates[0].count <= dev->wl->hw->conf.long_frame_max_tx_count)) { in b43_generate_txhdr()
415 rates[0].count = dev->wl->hw->conf.long_frame_max_tx_count; in b43_generate_txhdr()
418 rates[0].count = dev->wl->hw->conf.short_frame_max_tx_count; in b43_generate_txhdr()
421 /* Generate the RTS or CTS-to-self frame */ in b43_generate_txhdr()
431 rts_cts_rate = ieee80211_get_rts_cts_rate(dev->wl->hw, info); in b43_generate_txhdr()
433 rts_rate = rts_cts_rate ? rts_cts_rate->hw_value : B43_CCK_RATE_1MB; in b43_generate_txhdr()
435 rts_rate_fb = b43_calc_fallback_rate(rts_rate, phy->gmode); in b43_generate_txhdr()
441 switch (dev->fw.hdr_format) { in b43_generate_txhdr()
444 (txhdr->format_598.rts_frame); in b43_generate_txhdr()
448 (txhdr->format_351.rts_frame); in b43_generate_txhdr()
452 (txhdr->format_410.rts_frame); in b43_generate_txhdr()
455 ieee80211_ctstoself_get(dev->wl->hw, info->control.vif, in b43_generate_txhdr()
463 switch (dev->fw.hdr_format) { in b43_generate_txhdr()
466 (txhdr->format_598.rts_frame); in b43_generate_txhdr()
470 (txhdr->format_351.rts_frame); in b43_generate_txhdr()
474 (txhdr->format_410.rts_frame); in b43_generate_txhdr()
477 ieee80211_rts_get(dev->wl->hw, info->control.vif, in b43_generate_txhdr()
486 switch (dev->fw.hdr_format) { in b43_generate_txhdr()
488 plcp = &txhdr->format_598.rts_plcp; in b43_generate_txhdr()
491 plcp = &txhdr->format_351.rts_plcp; in b43_generate_txhdr()
494 plcp = &txhdr->format_410.rts_plcp; in b43_generate_txhdr()
499 plcp = &txhdr->rts_plcp_fb; in b43_generate_txhdr()
503 switch (dev->fw.hdr_format) { in b43_generate_txhdr()
506 (&txhdr->format_598.rts_frame); in b43_generate_txhdr()
510 (&txhdr->format_351.rts_frame); in b43_generate_txhdr()
514 (&txhdr->format_410.rts_frame); in b43_generate_txhdr()
517 txhdr->rts_dur_fb = hdr->duration_id; in b43_generate_txhdr()
521 txhdr->phy_rate_rts = in b43_generate_txhdr()
525 txhdr->phy_rate_rts = in b43_generate_txhdr()
535 txhdr->phy_ctl1_rts = cpu_to_le16( in b43_generate_txhdr()
537 txhdr->phy_ctl1_rts_fb = cpu_to_le16( in b43_generate_txhdr()
543 switch (dev->fw.hdr_format) { in b43_generate_txhdr()
545 txhdr->format_598.cookie = cpu_to_le16(cookie); in b43_generate_txhdr()
548 txhdr->format_351.cookie = cpu_to_le16(cookie); in b43_generate_txhdr()
551 txhdr->format_410.cookie = cpu_to_le16(cookie); in b43_generate_txhdr()
556 txhdr->phy_ctl1 = in b43_generate_txhdr()
558 txhdr->phy_ctl1_fb = in b43_generate_txhdr()
563 txhdr->mac_ctl = cpu_to_le32(mac_ctl); in b43_generate_txhdr()
564 txhdr->phy_ctl = cpu_to_le16(phy_ctl); in b43_generate_txhdr()
565 txhdr->extra_ft = extra_ft; in b43_generate_txhdr()
574 struct b43_phy *phy = &dev->phy; in b43_rssi_postprocess()
575 struct b43_phy_g *gphy = phy->g; in b43_rssi_postprocess()
578 switch (phy->radio_ver) { in b43_rssi_postprocess()
583 tmp -= 256; in b43_rssi_postprocess()
589 tmp -= 3; in b43_rssi_postprocess()
591 if (dev->dev->bus_sprom-> in b43_rssi_postprocess()
595 B43_WARN_ON(phy->type != B43_PHYTYPE_G); in b43_rssi_postprocess()
596 tmp = gphy->nrssi_lt[in_rssi]; in b43_rssi_postprocess()
597 tmp = 31 - tmp; in b43_rssi_postprocess()
598 tmp *= -131; in b43_rssi_postprocess()
600 tmp -= 57; in b43_rssi_postprocess()
603 tmp = 31 - tmp; in b43_rssi_postprocess()
604 tmp *= -149; in b43_rssi_postprocess()
606 tmp -= 68; in b43_rssi_postprocess()
608 if (phy->type == B43_PHYTYPE_G && adjust_2050) in b43_rssi_postprocess()
614 tmp = in_rssi - 256; in b43_rssi_postprocess()
620 tmp -= 11; in b43_rssi_postprocess()
624 tmp -= 109; in b43_rssi_postprocess()
626 tmp -= 83; in b43_rssi_postprocess()
648 phystat0 = le16_to_cpu(rxhdr->phy_status0); in b43_rx()
649 phystat3 = le16_to_cpu(rxhdr->phy_status3); in b43_rx()
650 switch (dev->fw.hdr_format) { in b43_rx()
652 macstat = le32_to_cpu(rxhdr->format_598.mac_status); in b43_rx()
653 mactime = le16_to_cpu(rxhdr->format_598.mac_time); in b43_rx()
654 chanstat = le16_to_cpu(rxhdr->format_598.channel); in b43_rx()
658 macstat = le32_to_cpu(rxhdr->format_351.mac_status); in b43_rx()
659 mactime = le16_to_cpu(rxhdr->format_351.mac_time); in b43_rx()
660 chanstat = le16_to_cpu(rxhdr->format_351.channel); in b43_rx()
665 dev->wl->ieee_stats.dot11FCSErrorCount++; in b43_rx()
681 if (unlikely(skb->len < (sizeof(struct b43_plcp_hdr6) + padding))) { in b43_rx()
682 b43dbg(dev->wl, "RX: Packet size underrun (1)\n"); in b43_rx()
685 plcp = (struct b43_plcp_hdr6 *)(skb->data + padding); in b43_rx()
688 if (unlikely(skb->len < (2 + 2 + 6 /*minimum hdr */ + FCS_LEN))) { in b43_rx()
689 b43dbg(dev->wl, "RX: Packet size underrun (2)\n"); in b43_rx()
692 wlhdr = (struct ieee80211_hdr *)(skb->data); in b43_rx()
693 fctl = wlhdr->frame_control; in b43_rx()
705 B43_WARN_ON(keyidx >= ARRAY_SIZE(dev->key)); in b43_rx()
707 if (dev->key[keyidx].algorithm != B43_SEC_ALGO_NONE) { in b43_rx()
709 if (unlikely(skb->len < (wlhdr_len + 3))) { in b43_rx()
710 b43dbg(dev->wl, in b43_rx()
721 /* TODO: is max the right choice? */ in b43_rx()
723 max(rxhdr->phy_ht_power0, rxhdr->phy_ht_power1), in b43_rx()
724 rxhdr->phy_ht_power2); in b43_rx()
727 /* Broadcom has code for min and avg, but always uses max */ in b43_rx()
728 if (rxhdr->power0 == 16 || rxhdr->power0 == 32) in b43_rx()
729 status.signal = max(rxhdr->power1, rxhdr->power2); in b43_rx()
731 status.signal = max(rxhdr->power0, rxhdr->power1); in b43_rx()
736 status.signal = b43_rssi_postprocess(dev, rxhdr->jssi, in b43_rx()
748 if (unlikely(rate_idx == -1)) { in b43_rx()
751 if (!(dev->wl->filter_flags & FIF_PLCPFAIL)) in b43_rx()
759 * 64-bit timestamp. Monitor interfaces need it for diagnostic in b43_rx()
765 if (ieee80211_is_beacon(fctl) || dev->wl->radiotap_enabled) { in b43_rx()
773 status.mactime -= 0x10000; in b43_rx()
781 /* Somewhere between 478.104 and 508.1084 firmware for G-PHY in b43_rx()
782 * has been modified to be compatible with N-PHY and others. in b43_rx()
784 if (dev->fw.rev >= 508) in b43_rx()
807 ieee80211_rx_ni(dev->wl->hw, skb); in b43_rx()
810 dev->rx_count++; in b43_rx()
822 if (status->intermediate) in b43_handle_txstatus()
824 if (status->for_ampdu) in b43_handle_txstatus()
826 if (!status->acked) in b43_handle_txstatus()
827 dev->wl->ieee_stats.dot11ACKFailureCount++; in b43_handle_txstatus()
828 if (status->rts_count) { in b43_handle_txstatus()
829 if (status->rts_count == 0xF) //FIXME in b43_handle_txstatus()
830 dev->wl->ieee_stats.dot11RTSFailureCount++; in b43_handle_txstatus()
832 dev->wl->ieee_stats.dot11RTSSuccessCount++; in b43_handle_txstatus()
843 /* Fill out the mac80211 TXstatus report based on the b43-specific
856 retry_limit = report->status.rates[0].count; in b43_fill_txstatus_report()
859 if (status->acked) { in b43_fill_txstatus_report()
861 report->flags |= IEEE80211_TX_STAT_ACK; in b43_fill_txstatus_report()
864 if (!(report->flags & IEEE80211_TX_CTL_NO_ACK)) { in b43_fill_txstatus_report()
869 if (status->frame_count == 0) { in b43_fill_txstatus_report()
871 report->status.rates[0].count = 0; in b43_fill_txstatus_report()
872 } else if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) { in b43_fill_txstatus_report()
880 report->status.rates[0].count = 0; in b43_fill_txstatus_report()
881 report->status.rates[1].count = status->frame_count; in b43_fill_txstatus_report()
883 if (status->frame_count > retry_limit) { in b43_fill_txstatus_report()
884 report->status.rates[0].count = retry_limit; in b43_fill_txstatus_report()
885 report->status.rates[1].count = status->frame_count - in b43_fill_txstatus_report()
889 report->status.rates[0].count = status->frame_count; in b43_fill_txstatus_report()
890 report->status.rates[1].idx = -1; in b43_fill_txstatus_report()