wifi: b43: AC microcode TX and RX formats (series 3/4)
cover wifi: b43: AC microcode TX and RX formats (series 3/4)
The TX descriptor, TX status, RX header and A-MPDU handling of the AC microcode, gated on the microcode revision. Only revision 832 has been tested; the layouts of 784 and 928 are expected to match but are not verified. Based on series 2/4.
Where the values come from: the register sequences and table contents were taken from Broadcom's wl driver running on this MacBook, by tracing its register accesses (bpftrace on wl's MMIO accessors), and reduced to what the hardware needs. Parts come from Alessio Ferri's AC-PHY work (the PHY init sequence, the 40 and 80 MHz coefficient tables, a TX gain table, the Farrow resampler formula, the VHT fields of the TX descriptor, register and table names), and some formats follow brcmsmac.
The result was tested on the hardware as described below.
Each patch compiles on its own (kernel 7.2.10 headers). The four series together were run on a MacBookAir6,1 (14e4:43a0, BCM4360, core revision 42, microcode 832.127, 2 of 3 chains wired) on top of v7.3-rc5's b43. The AC PHY only comes with series 4, so the earlier series cannot be exercised on this hardware alone.
Andreas Wendleder (4):
wifi: b43: 11ac chanspec for the AC microcode
wifi: b43: TX descriptor and TX status for the AC microcode
wifi: b43: RX header handling for the AC microcode
wifi: b43: A-MPDU for the AC microcode
drivers/net/wireless/broadcom/b43/dma.c | 61 ++++ drivers/net/wireless/broadcom/b43/dma.h | 1 + drivers/net/wireless/broadcom/b43/main.c | 113 ++++++ .../net/wireless/broadcom/b43/phy_common.c | 13 + .../net/wireless/broadcom/b43/phy_common.h | 7 + drivers/net/wireless/broadcom/b43/xmit.c | 327 +++++++++++++++++- drivers/net/wireless/broadcom/b43/xmit.h | 13 + 7 files changed, 528 insertions(+), 7 deletions(-)
RFC PATCH 1/4 wifi: b43: 11ac chanspec for the AC microcode
The AC microcode keeps an 11ac chanspec of the current channel in SHM (where older microcode keeps the channel cookie) and takes one in every TX descriptor and puts one in every RX header: the channel, 0x1000 for 20 MHz and 0xc000 on 5 GHz.
Add b43_ac_chanspec() and use it for the channel cookie in b43_switch_channel(). The TX and RX header patches that follow use it too.
--- drivers/net/wireless/broadcom/b43/phy_common.c | 13 +++++++++++++ drivers/net/wireless/broadcom/b43/phy_common.h | 7 +++++++ 2 files changed, 20 insertions(+)
drivers/net/wireless/broadcom/b43/phy_common.c +13 -0
@@ -413,6 +413,17 @@ void b43_phy_take_out_of_reset(struct b43_wldev *dev) } } +/* +* The 11ac chanspec of a primary channel as the AC microcode takes it in +* SHM and in the TX and RX headers: channel, 0x1000 for 20 MHz, 0xc000 on +* 5 GHz. +*/ +u16 b43_ac_chanspec (struct b43_wldev *dev,unsigned int channel) +{ +return channel |0x1000 | + (b43_current_band (dev->wl) ==NL80211_BAND_5GHZ ?0xc000 :0 ); +} +int b43_switch_channel (struct b43_wldev *dev,unsigned int new_channel) {struct b43_phy *phy = &(dev->phy);
@@ -428,6 +439,8 @@ int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel)/* FIXME: set 40Mhz flag if required */ if (0 ) channelcookie |=B43_SHM_SH_CHAN_40MHZ ; +if (b43_ucode_is_ac (dev)) + channelcookie =b43_ac_chanspec (dev, new_channel); savedcookie =b43_shm_read16 (dev,B43_SHM_SHARED ,B43_SHM_SH_CHAN );b43_shm_write16 (dev,B43_SHM_SHARED ,B43_SHM_SH_CHAN , channelcookie);
drivers/net/wireless/broadcom/b43/phy_common.h +7 -0
@@ -390,6 +390,13 @@ void b43_phy_take_out_of_reset(struct b43_wldev *dev);*/ int b43_switch_channel (struct b43_wldev *dev,unsigned int new_channel); +/* +* 11ac chanspec of the AC microcode, and the centre channel of the 80 MHz block +* of a 5 GHz primary (0: none) +*/ +u16 b43_ac_chanspec (struct b43_wldev *dev,unsigned int channel); +unsigned int b43_ac_80mhz_centre (unsigned int channel); +/** * b43_software_rfkill - Turn the radio ON or OFF in software. */
RFC PATCH 2/4 wifi: b43: TX descriptor and TX status for the AC microcode
In reply to Andreas WendlederThe AC microcode takes a 4 byte passthrough prefix and a 124 byte descriptor with four 20 byte rate entries. Add the descriptor builder:
legacy CCK and OFDM rates, HT rates with the PLCP laid out as brcmsmac does, VHT rate blocks (frame type 3, with the width and the subband of the primary channel in the first two words and the VHT-SIG-A fields), and the cache info that session frames carry (the microcode builds the A-MPDU from them). The cache info must not carry a cipher: mac80211 has encrypted the frame already.
The TX status comes as two 4 word records. The attempt count is the low byte of word 2, not the sum of its bytes, and a record with more than one MPDU carries a block ack bitmap for the consecutive cookies; the cookies are advanced with the new b43_dma_cookie_advance().
Only microcode revision 832 has been tested.
--- drivers/net/wireless/broadcom/b43/dma.c | 13 ++ drivers/net/wireless/broadcom/b43/dma.h | 1 + drivers/net/wireless/broadcom/b43/main.c | 76 ++++++++ drivers/net/wireless/broadcom/b43/xmit.c | 214 +++++++++++++++++++++++ drivers/net/wireless/broadcom/b43/xmit.h | 11 ++ 5 files changed, 315 insertions(+)
drivers/net/wireless/broadcom/b43/dma.c +13 -0
@@ -1444,6 +1444,19 @@ out:return err; } +/* The cookie of the frame @n frames after @cookie on the same ring. */ +u16 b43_dma_cookie_advance (struct b43_wldev *dev,u16 cookie,unsigned int n) +{ +struct b43_dmaring *ring; +int slot; + + ring =parse_cookie (dev, cookie, &slot); +if (!ring) +return cookie; +return generate_cookie (ring, (slot + n *TX_SLOTS_PER_FRAME ) % + ring->nr_slots); +} +void b43_dma_handle_txstatus (struct b43_wldev *dev,const struct b43_txstatus *status) {
drivers/net/wireless/broadcom/b43/dma.h +1 -0
@@ -298,6 +298,7 @@ void b43_dma_tx_resume(struct b43_wldev *dev);int b43_dma_tx (struct b43_wldev *dev,struct sk_buff *skb); +u16 b43_dma_cookie_advance (struct b43_wldev *dev,u16 cookie,unsigned int n);void b43_dma_handle_txstatus (struct b43_wldev *dev,const struct b43_txstatus *status);
drivers/net/wireless/broadcom/b43/main.c +76 -0
88 lines not on this page · raw message
drivers/net/wireless/broadcom/b43/xmit.c +214 -0
226 lines not on this page · raw message
drivers/net/wireless/broadcom/b43/xmit.h +11 -0
@@ -188,9 +188,19 @@ struct b43_tx_legacy_rate_phy_ctl_entry {#define B43_TXH_PHY1_MODUL_QAM256 0x2000/* QAM256 */ +/* +* rev 40+ (AC) TX buffer: 4-byte TX offload passthrough prefix, then the +* 124-byte descriptor (packet info + 4 rate entries + cache). +*/ +#define B43_TXH_AC_PREFIX 4 +#define B43_TXH_AC_LEN (B43_TXH_AC_PREFIX + 124) +#define B43_TXH_AC_RATE (i) (0x14 + (i) * 0x14) +static inline size_t b43_txhdr_size (struct b43_wldev *dev) { +if (b43_ucode_is_ac (dev)) +return B43_TXH_AC_LEN ;switch (dev->fw.hdr_format) {case B43_FW_HDR_598 :return 112 +sizeof (struct b43_plcp_hdr6 );
@@ -214,6 +224,7 @@ struct b43_txstatus {u16 seq;/* Sequence number */ u8 phy_stat;/* PHY TX status */ u8 frame_count;/* Frame transmit count */ +u8 fb_count;/* AC: attempts at the fallback rate */ u8 rts_count;/* RTS transmit count */ u8 supp_reason;/* Suppression reason */ /* flags */
RFC PATCH 3/4 wifi: b43: RX header handling for the AC microcode
In reply to Andreas WendlederThe RX header of the AC microcode keeps the MAC status at 0x10, the TSF at 0x14, an 11ac chanspec at 0x16 and the power of the two antennas at 0x09 and 0x0a. Decode the channel (including the 80 MHz block with the position of the primary channel), the signal, and the HT-SIG and VHT-SIG-A bytes that precede the frame for the rate, bandwidth, guard interval, coding and stream count.
The microcode sets the decryption error bit on frames it never decrypted, because no hardware key is programmed (the 4-way handshake message 3 and DHCP replies carry it). Pass such frames up; mac80211's own decryption still rejects anything corrupt.
Only microcode revision 832 has been tested.
--- drivers/net/wireless/broadcom/b43/xmit.c | 91 ++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 6 deletions(-)
drivers/net/wireless/broadcom/b43/xmit.c +85 -6
@@ -855,6 +855,7 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)u32 macstat;u16 chanid;int padding, rate_idx; +s8 ac_signal =0 ;memset (&status,0 ,sizeof (status));
@@ -874,6 +875,31 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr) chanstat =le16_to_cpu (rxhdr->format_351.channel);break ; } +if (b43_ucode_is_ac (dev)) { +/* AC ucode (rev 40+) header: RxStatus1 @0x10, TSF @0x14, +* 11ac-style chanspec @0x16, per-antenna power @0x09/0x0a. +*/ +const u8 *h = _rxhdr; +u16 cs =get_unaligned_le16 (h +0x16 ); +s8 p0 = h[0x09 ], p1 = h[0x0a ]; + + macstat =get_unaligned_le16 (h +0x10 ); + mactime =get_unaligned_le16 (h +0x14 ); +/* 80 MHz chanspec: centre channel and the primary's position */ +if ((cs &0x3800 ) ==0x2000 ) + cs = (cs &0xff00 ) | + ((cs &0xff ) -6 +4 * ((cs >>8 ) &0x7 )); + chanstat = ((cs &0xff ) <<B43_RX_CHAN_ID_SHIFT ) | +B43_PHYTYPE_N ; +if ((cs &0xc000 ) ==0xc000 ) + chanstat |=B43_RX_CHAN_5GHZ ; +if (p0 ==-128 ) + ac_signal = p1; +else if (p1 ==-128 ) + ac_signal = p0; +else + ac_signal =max (p0, p1); + }if (unlikely (macstat &B43_RX_MAC_FCSERR )) { dev->wl->ieee_stats.dot11FCSErrorCount++;
@@ -884,10 +910,19 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)if (phystat0 &B43_RX_PHYST0_SHORTPRMBL ) status.enc_flags |=RX_ENC_FLAG_SHORTPRE ;if (macstat &B43_RX_MAC_DECERR ) { -/* Decryption with the given key failed. -* Drop the packet. We also won't be able to decrypt it with -* the key in software. */ - goto drop; +/* The AC ucode sets this bit on frames it never decrypted: this +* port programs no hardware keys on AC, and it shows up even on +* unprotected EAPOL frames. Dropping here killed +* 4-way handshake message 3 and DHCP replies; mac80211's own +* software decryption still rejects anything really corrupt. +*/ +if (b43_ucode_is_ac (dev)) { +b43dbg (dev->wl, +"RX: DECERR passed up (len %u, macstat %04x)\n" , + skb->len, macstat); + }else { + goto drop; + } }/* Skip PLCP and padding */
@@ -931,7 +966,11 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr) }/* Link quality statistics */ -switch (chanstat &B43_RX_CHAN_PHYTYPE ) { +switch (b43_ucode_is_ac (dev) ?B43_PHYTYPE_AC : + (chanstat &B43_RX_CHAN_PHYTYPE )) { +case B43_PHYTYPE_AC : + status.signal = ac_signal; +break ;case B43_PHYTYPE_HT :/* TODO: is max the right choice? */ status.signal = max_t(__s8,
@@ -955,7 +994,47 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)break ; } -if (phystat0 &B43_RX_PHYST0_OFDM ) +if (b43_ucode_is_ac (dev) && + (phystat0 &B43_RX_PHYST0_FTYPE ) ==B43_RX_PHYST0_PRE_N ) { +/* HT frame: the six bytes before the frame are HT-SIG: MCS and +* 40 MHz bit in byte 0, coding/STBC/short GI in byte 3. +*/ +const u8 *sig = plcp->raw; + + status.encoding =RX_ENC_HT ; +if (sig[0 ] &0x80 ) + status.bw =RATE_INFO_BW_40 ; +if (sig[3 ] &0x80 ) + status.enc_flags |=RX_ENC_FLAG_SHORT_GI ; +if (sig[3 ] &0x40 ) + status.enc_flags |=RX_ENC_FLAG_LDPC ; + status.enc_flags |= ((sig[3 ] >>4 ) &0x3 ) + <<RX_ENC_FLAG_STBC_SHIFT ; + rate_idx = (sig[0 ] &0x7f ) <=15 ? sig[0 ] &0x7f :-1 ; + }else if (b43_ucode_is_ac (dev) && + (phystat0 &B43_RX_PHYST0_FTYPE ) ==B43_RX_PHYST0_STD_N ) { +/* VHT: the six bytes are VHT-SIG-A1/A2 */ +const u8 *p = plcp->raw; +u32 a1 = p[0 ] | (p[1 ] <<8 ) | (p[2 ] <<16 ); +u32 a2 = p[3 ] | (p[4 ] <<8 ) | (p[5 ] <<16 ); +u8 nsts = ((a1 >>10 ) &0x7 ) +1 ; + + status.encoding =RX_ENC_VHT ; +if ((a1 &0x3 ) ==1 ) + status.bw =RATE_INFO_BW_40 ; +else if ((a1 &0x3 ) ==2 ) + status.bw =RATE_INFO_BW_80 ; +if (a1 &0x8 ) { + status.enc_flags |=1 <<RX_ENC_FLAG_STBC_SHIFT ; + nsts /=2 ; + } + status.nss =max_t (u8, nsts,1 ); +if (a2 &0x1 ) + status.enc_flags |=RX_ENC_FLAG_SHORT_GI ; +if (a2 &0x4 ) + status.enc_flags |=RX_ENC_FLAG_LDPC ; + rate_idx = ((a2 >>4 ) &0xf ) <=9 ? (a2 >>4 ) &0xf :-1 ; + }else if (phystat0 &B43_RX_PHYST0_OFDM ) rate_idx =b43_plcp_get_bitrate_idx_ofdm (plcp, !!(chanstat &B43_RX_CHAN_5GHZ ));else
RFC PATCH 4/4 wifi: b43: A-MPDU for the AC microcode
In reply to Andreas WendlederThe microcode builds the aggregates and sends the block acks. Accept block ack sessions on both sides (ampdu_action) and set IEEE80211_HW_AMPDU_AGGREGATION on the AC cores.
Frames of a session that the microcode gave up on are put back on the ring, up to four times, with the retry bit set; the block ack window lets them follow later frames. The cache info limits an aggregate to four MPDUs, longer ones lose their later MPDUs.
--- drivers/net/wireless/broadcom/b43/dma.c | 48 ++++++++++++++++++++++++ drivers/net/wireless/broadcom/b43/main.c | 37 ++++++++++++++++++ drivers/net/wireless/broadcom/b43/xmit.c | 22 ++++++++++- drivers/net/wireless/broadcom/b43/xmit.h | 2 + 4 files changed, 108 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43/dma.c +48 -0
@@ -34,6 +34,9 @@* into separate slots. */ #define TX_SLOTS_PER_FRAME 2 +/* Times an unacknowledged A-MPDU session frame is put back on the ring */ +#define B43_AC_AMPDU_REQUEUE 4 +static u32 b43_dma_address (struct b43_dma *dma,dma_addr_t dmaaddr,enum b43_addrtype addrtype) {
@@ -1378,6 +1381,7 @@ int b43_dma_tx(struct b43_wldev *dev, struct sk_buff *skb)struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb); hdr = (struct ieee80211_hdr *)skb->data; +b43_get_priv_tx_info (info)->requeues =0 ;if (info->flags &IEEE80211_TX_CTL_SEND_AFTER_DTIM ) {/* The multicast ring will be sent after the DTIM */ ring = dev->dma.tx_ring_mcast;
@@ -1466,6 +1470,7 @@ void b43_dma_handle_txstatus(struct b43_wldev *dev,static const struct b43_txstatus fake;/* filled with 0 */ const struct b43_txstatus *txstat;int slot, firstused; +struct sk_buff *requeue =NULL ;bool frame_succeed;int skip;static u8 err_out1;
@@ -1568,6 +1573,29 @@ void b43_dma_handle_txstatus(struct b43_wldev *dev,else txstat = status; +/* A session frame the microcode gave up on goes back +* on the ring, as the stock driver requeues it; the +* block ack window lets it follow later frames. +*/ +if (!skip && !txstat->acked && + (info->flags &IEEE80211_TX_CTL_AMPDU ) && + !(info->flags &IEEE80211_TX_CTL_NO_ACK )) { +struct b43_private_tx_info *pi = +b43_get_priv_tx_info (info); + +if (pi->requeues <B43_AC_AMPDU_REQUEUE ) { +struct ieee80211_hdr *hdr = + (void *)meta->skb->data; + + pi->requeues++; + hdr->frame_control |=cpu_to_le16 ( +IEEE80211_FCTL_RETRY ); + requeue = meta->skb; + meta->skb =B43_DMA_PTR_POISON ; + ring->used_slots--; +break ; + } + } frame_succeed =b43_fill_txstatus_report (dev, info, txstat);#ifdef CONFIG_B43_DEBUG
@@ -1606,6 +1634,26 @@ void b43_dma_handle_txstatus(struct b43_wldev *dev,if (skip >0 ) --skip; } +if (requeue) { +if (dma_tx_fragment (ring, requeue)) { +struct ieee80211_tx_info *info = +IEEE80211_SKB_CB (requeue); + +b43_fill_txstatus_report (dev, info, status); +ieee80211_tx_status_skb (dev->wl->hw, requeue); + }else if (free_slots (ring) <TX_SLOTS_PER_FRAME ) { +/* The requeued frame took the slots this status freed: +* the ring is still full, keep the queue stopped. +*/ +if (!ring->stopped) { +b43_stop_queue (dev, ring->queue_prio); + dev->wl->tx_queue_stopped[ring->queue_prio] = + true; + ring->stopped = true; + } +return ; + } + }if (ring->stopped) {B43_WARN_ON (free_slots (ring) <TX_SLOTS_PER_FRAME ); ring->stopped = false;
drivers/net/wireless/broadcom/b43/main.c +37 -0
@@ -5479,6 +5479,39 @@ static int b43_op_get_survey(struct ieee80211_hw *hw, int idx,return 0 ; } +static int b43_op_ampdu_action (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_ampdu_params *params) +{ +struct b43_wl *wl =hw_to_b43_wl (hw); + +/* Only the AC-PHY path builds session frames */ +if (!wl->current_dev || !b43_ucode_is_ac (wl->current_dev)) +return -EOPNOTSUPP ; + +switch (params->action) { +case IEEE80211_AMPDU_TX_START : +return IEEE80211_AMPDU_TX_START_IMMEDIATE ; +case IEEE80211_AMPDU_TX_STOP_CONT : +case IEEE80211_AMPDU_TX_STOP_FLUSH : +case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT : +ieee80211_stop_tx_ba_cb_irqsafe (vif, params->sta->addr, + params->tid); +return 0 ; +case IEEE80211_AMPDU_TX_OPERATIONAL : +return 0 ; +case IEEE80211_AMPDU_RX_START : +case IEEE80211_AMPDU_RX_STOP : +/* +* The microcode deaggregates and sends the block acks, mac80211 +* reorders. +*/ +return 0 ; +default : +return -EOPNOTSUPP ; + } +} +static const struct ieee80211_ops b43_hw_ops = { .add_chanctx = ieee80211_emulate_add_chanctx, .remove_chanctx = ieee80211_emulate_remove_chanctx,
@@ -5501,6 +5534,7 @@ static const struct ieee80211_ops b43_hw_ops = { .stop = b43_op_stop, .set_tim = b43_op_beacon_set_tim, .sta_notify = b43_op_sta_notify, + .ampdu_action = b43_op_ampdu_action, .sw_scan_start = b43_op_sw_scan_start_notifier, .sw_scan_complete = b43_op_sw_scan_complete_notifier, .get_survey = b43_op_get_survey,
@@ -5590,6 +5624,9 @@ static int b43_setup_bands(struct b43_wldev *dev, hw->wiphy->bands[NL80211_BAND_5GHZ ] = &b43_band_5GHz_aphy; } +if (b43_is_ac_core (dev)) +ieee80211_hw_set (hw,AMPDU_AGGREGATION ); + dev->phy.supports_2ghz = have_2ghz_phy; dev->phy.supports_5ghz = have_5ghz_phy;
drivers/net/wireless/broadcom/b43/xmit.c +21 -1
@@ -1160,7 +1160,27 @@ bool b43_fill_txstatus_report(struct b43_wldev *dev, frame_success = false; } } -if (status->frame_count ==0 ) { +if (report->flags &IEEE80211_TX_CTL_AMPDU ) { +/* +* minstrel_ht ignores session frames without this; one report +* per MPDU +*/ + report->flags |=IEEE80211_TX_STAT_AMPDU ; + report->status.ampdu_len =1 ; + report->status.ampdu_ack_len = status->acked ?1 :0 ; + } +if ((report->flags &IEEE80211_TX_CTL_AMPDU ) && + (report->status.rates[0 ].flags & + (IEEE80211_TX_RC_MCS |IEEE80211_TX_RC_VHT_MCS ))) { +/* Sent with two rate blocks: attempts at each */ + report->status.rates[0 ].count = status->frame_count; +if (status->fb_count && report->status.rates[1 ].idx >=0 && + (report->status.rates[1 ].flags & + (IEEE80211_TX_RC_MCS |IEEE80211_TX_RC_VHT_MCS ))) + report->status.rates[1 ].count = status->fb_count; +else + report->status.rates[1 ].idx =-1 ; + }else if (status->frame_count ==0 ) {/* The frame was not transmitted at all. */ report->status.rates[0 ].count =0 ; }else if (status->rts_count > dev->wl->hw->conf.short_frame_max_tx_count) {
drivers/net/wireless/broadcom/b43/xmit.h +2 -0
@@ -412,9 +412,11 @@ static inline u8 b43_kidx_to_raw(struct b43_wldev *dev, u8 firmware_kidx)* The structure is placed in (struct ieee80211_tx_info *)->rate_driver_data * * @bouncebuffer: DMA Bouncebuffer (if used) +* @requeues: times the frame was put back on the ring (AC-PHY A-MPDU) */ struct b43_private_tx_info {void *bouncebuffer; +u8 requeues; }; static inline struct b43_private_tx_info *