1*b4c3e9b5SBjoern A. Zeeb /*
2*b4c3e9b5SBjoern A. Zeeb * Copyright (c) 2010 Broadcom Corporation
3*b4c3e9b5SBjoern A. Zeeb *
4*b4c3e9b5SBjoern A. Zeeb * Permission to use, copy, modify, and/or distribute this software for any
5*b4c3e9b5SBjoern A. Zeeb * purpose with or without fee is hereby granted, provided that the above
6*b4c3e9b5SBjoern A. Zeeb * copyright notice and this permission notice appear in all copies.
7*b4c3e9b5SBjoern A. Zeeb *
8*b4c3e9b5SBjoern A. Zeeb * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*b4c3e9b5SBjoern A. Zeeb * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*b4c3e9b5SBjoern A. Zeeb * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11*b4c3e9b5SBjoern A. Zeeb * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*b4c3e9b5SBjoern A. Zeeb * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13*b4c3e9b5SBjoern A. Zeeb * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14*b4c3e9b5SBjoern A. Zeeb * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*b4c3e9b5SBjoern A. Zeeb */
16*b4c3e9b5SBjoern A. Zeeb #include <net/mac80211.h>
17*b4c3e9b5SBjoern A. Zeeb
18*b4c3e9b5SBjoern A. Zeeb #include "rate.h"
19*b4c3e9b5SBjoern A. Zeeb #include "scb.h"
20*b4c3e9b5SBjoern A. Zeeb #include "phy/phy_hal.h"
21*b4c3e9b5SBjoern A. Zeeb #include "antsel.h"
22*b4c3e9b5SBjoern A. Zeeb #include "main.h"
23*b4c3e9b5SBjoern A. Zeeb #include "ampdu.h"
24*b4c3e9b5SBjoern A. Zeeb #include "debug.h"
25*b4c3e9b5SBjoern A. Zeeb #include "brcms_trace_events.h"
26*b4c3e9b5SBjoern A. Zeeb
27*b4c3e9b5SBjoern A. Zeeb /* max number of mpdus in an ampdu */
28*b4c3e9b5SBjoern A. Zeeb #define AMPDU_MAX_MPDU 32
29*b4c3e9b5SBjoern A. Zeeb /* max number of mpdus in an ampdu to a legacy */
30*b4c3e9b5SBjoern A. Zeeb #define AMPDU_NUM_MPDU_LEGACY 16
31*b4c3e9b5SBjoern A. Zeeb /* max Tx ba window size (in pdu) */
32*b4c3e9b5SBjoern A. Zeeb #define AMPDU_TX_BA_MAX_WSIZE 64
33*b4c3e9b5SBjoern A. Zeeb /* default Tx ba window size (in pdu) */
34*b4c3e9b5SBjoern A. Zeeb #define AMPDU_TX_BA_DEF_WSIZE 64
35*b4c3e9b5SBjoern A. Zeeb /* default Rx ba window size (in pdu) */
36*b4c3e9b5SBjoern A. Zeeb #define AMPDU_RX_BA_DEF_WSIZE 64
37*b4c3e9b5SBjoern A. Zeeb /* max Rx ba window size (in pdu) */
38*b4c3e9b5SBjoern A. Zeeb #define AMPDU_RX_BA_MAX_WSIZE 64
39*b4c3e9b5SBjoern A. Zeeb /* max dur of tx ampdu (in msec) */
40*b4c3e9b5SBjoern A. Zeeb #define AMPDU_MAX_DUR 5
41*b4c3e9b5SBjoern A. Zeeb /* default tx retry limit */
42*b4c3e9b5SBjoern A. Zeeb #define AMPDU_DEF_RETRY_LIMIT 5
43*b4c3e9b5SBjoern A. Zeeb /* default tx retry limit at reg rate */
44*b4c3e9b5SBjoern A. Zeeb #define AMPDU_DEF_RR_RETRY_LIMIT 2
45*b4c3e9b5SBjoern A. Zeeb /* default ffpld reserved bytes */
46*b4c3e9b5SBjoern A. Zeeb #define AMPDU_DEF_FFPLD_RSVD 2048
47*b4c3e9b5SBjoern A. Zeeb /* # of inis to be freed on detach */
48*b4c3e9b5SBjoern A. Zeeb #define AMPDU_INI_FREE 10
49*b4c3e9b5SBjoern A. Zeeb /* max # of mpdus released at a time */
50*b4c3e9b5SBjoern A. Zeeb #define AMPDU_SCB_MAX_RELEASE 20
51*b4c3e9b5SBjoern A. Zeeb
52*b4c3e9b5SBjoern A. Zeeb #define NUM_FFPLD_FIFO 4 /* number of fifo concerned by pre-loading */
53*b4c3e9b5SBjoern A. Zeeb #define FFPLD_TX_MAX_UNFL 200 /* default value of the average number of ampdu
54*b4c3e9b5SBjoern A. Zeeb * without underflows
55*b4c3e9b5SBjoern A. Zeeb */
56*b4c3e9b5SBjoern A. Zeeb #define FFPLD_MPDU_SIZE 1800 /* estimate of maximum mpdu size */
57*b4c3e9b5SBjoern A. Zeeb #define FFPLD_MAX_MCS 23 /* we don't deal with mcs 32 */
58*b4c3e9b5SBjoern A. Zeeb #define FFPLD_PLD_INCR 1000 /* increments in bytes */
59*b4c3e9b5SBjoern A. Zeeb #define FFPLD_MAX_AMPDU_CNT 5000 /* maximum number of ampdu we
60*b4c3e9b5SBjoern A. Zeeb * accumulate between resets.
61*b4c3e9b5SBjoern A. Zeeb */
62*b4c3e9b5SBjoern A. Zeeb
63*b4c3e9b5SBjoern A. Zeeb #define AMPDU_DELIMITER_LEN 4
64*b4c3e9b5SBjoern A. Zeeb
65*b4c3e9b5SBjoern A. Zeeb /* max allowed number of mpdus in an ampdu (2 streams) */
66*b4c3e9b5SBjoern A. Zeeb #define AMPDU_NUM_MPDU 16
67*b4c3e9b5SBjoern A. Zeeb
68*b4c3e9b5SBjoern A. Zeeb #define TX_SEQ_TO_INDEX(seq) ((seq) % AMPDU_TX_BA_MAX_WSIZE)
69*b4c3e9b5SBjoern A. Zeeb
70*b4c3e9b5SBjoern A. Zeeb /* max possible overhead per mpdu in the ampdu; 3 is for roundup if needed */
71*b4c3e9b5SBjoern A. Zeeb #define AMPDU_MAX_MPDU_OVERHEAD (FCS_LEN + DOT11_ICV_AES_LEN +\
72*b4c3e9b5SBjoern A. Zeeb AMPDU_DELIMITER_LEN + 3\
73*b4c3e9b5SBjoern A. Zeeb + DOT11_A4_HDR_LEN + DOT11_QOS_LEN + DOT11_IV_MAX_LEN)
74*b4c3e9b5SBjoern A. Zeeb
75*b4c3e9b5SBjoern A. Zeeb /* modulo add/sub, bound = 2^k */
76*b4c3e9b5SBjoern A. Zeeb #define MODADD_POW2(x, y, bound) (((x) + (y)) & ((bound) - 1))
77*b4c3e9b5SBjoern A. Zeeb #define MODSUB_POW2(x, y, bound) (((x) - (y)) & ((bound) - 1))
78*b4c3e9b5SBjoern A. Zeeb
79*b4c3e9b5SBjoern A. Zeeb /* structure to hold tx fifo information and pre-loading state
80*b4c3e9b5SBjoern A. Zeeb * counters specific to tx underflows of ampdus
81*b4c3e9b5SBjoern A. Zeeb * some counters might be redundant with the ones in wlc or ampdu structures.
82*b4c3e9b5SBjoern A. Zeeb * This allows to maintain a specific state independently of
83*b4c3e9b5SBjoern A. Zeeb * how often and/or when the wlc counters are updated.
84*b4c3e9b5SBjoern A. Zeeb *
85*b4c3e9b5SBjoern A. Zeeb * ampdu_pld_size: number of bytes to be pre-loaded
86*b4c3e9b5SBjoern A. Zeeb * mcs2ampdu_table: per-mcs max # of mpdus in an ampdu
87*b4c3e9b5SBjoern A. Zeeb * prev_txfunfl: num of underflows last read from the HW macstats counter
88*b4c3e9b5SBjoern A. Zeeb * accum_txfunfl: num of underflows since we modified pld params
89*b4c3e9b5SBjoern A. Zeeb * accum_txampdu: num of tx ampdu since we modified pld params
90*b4c3e9b5SBjoern A. Zeeb * prev_txampdu: previous reading of tx ampdu
91*b4c3e9b5SBjoern A. Zeeb * dmaxferrate: estimated dma avg xfer rate in kbits/sec
92*b4c3e9b5SBjoern A. Zeeb */
93*b4c3e9b5SBjoern A. Zeeb struct brcms_fifo_info {
94*b4c3e9b5SBjoern A. Zeeb u16 ampdu_pld_size;
95*b4c3e9b5SBjoern A. Zeeb u8 mcs2ampdu_table[FFPLD_MAX_MCS + 1];
96*b4c3e9b5SBjoern A. Zeeb u16 prev_txfunfl;
97*b4c3e9b5SBjoern A. Zeeb u32 accum_txfunfl;
98*b4c3e9b5SBjoern A. Zeeb u32 accum_txampdu;
99*b4c3e9b5SBjoern A. Zeeb u32 prev_txampdu;
100*b4c3e9b5SBjoern A. Zeeb u32 dmaxferrate;
101*b4c3e9b5SBjoern A. Zeeb };
102*b4c3e9b5SBjoern A. Zeeb
103*b4c3e9b5SBjoern A. Zeeb /* AMPDU module specific state
104*b4c3e9b5SBjoern A. Zeeb *
105*b4c3e9b5SBjoern A. Zeeb * wlc: pointer to main wlc structure
106*b4c3e9b5SBjoern A. Zeeb * scb_handle: scb cubby handle to retrieve data from scb
107*b4c3e9b5SBjoern A. Zeeb * ini_enable: per-tid initiator enable/disable of ampdu
108*b4c3e9b5SBjoern A. Zeeb * ba_tx_wsize: Tx ba window size (in pdu)
109*b4c3e9b5SBjoern A. Zeeb * ba_rx_wsize: Rx ba window size (in pdu)
110*b4c3e9b5SBjoern A. Zeeb * retry_limit: mpdu transmit retry limit
111*b4c3e9b5SBjoern A. Zeeb * rr_retry_limit: mpdu transmit retry limit at regular rate
112*b4c3e9b5SBjoern A. Zeeb * retry_limit_tid: per-tid mpdu transmit retry limit
113*b4c3e9b5SBjoern A. Zeeb * rr_retry_limit_tid: per-tid mpdu transmit retry limit at regular rate
114*b4c3e9b5SBjoern A. Zeeb * mpdu_density: min mpdu spacing (0-7) ==> 2^(x-1)/8 usec
115*b4c3e9b5SBjoern A. Zeeb * max_pdu: max pdus allowed in ampdu
116*b4c3e9b5SBjoern A. Zeeb * dur: max duration of an ampdu (in msec)
117*b4c3e9b5SBjoern A. Zeeb * rx_factor: maximum rx ampdu factor (0-3) ==> 2^(13+x) bytes
118*b4c3e9b5SBjoern A. Zeeb * ffpld_rsvd: number of bytes to reserve for preload
119*b4c3e9b5SBjoern A. Zeeb * max_txlen: max size of ampdu per mcs, bw and sgi
120*b4c3e9b5SBjoern A. Zeeb * mfbr: enable multiple fallback rate
121*b4c3e9b5SBjoern A. Zeeb * tx_max_funl: underflows should be kept such that
122*b4c3e9b5SBjoern A. Zeeb * (tx_max_funfl*underflows) < tx frames
123*b4c3e9b5SBjoern A. Zeeb * fifo_tb: table of fifo infos
124*b4c3e9b5SBjoern A. Zeeb */
125*b4c3e9b5SBjoern A. Zeeb struct ampdu_info {
126*b4c3e9b5SBjoern A. Zeeb struct brcms_c_info *wlc;
127*b4c3e9b5SBjoern A. Zeeb int scb_handle;
128*b4c3e9b5SBjoern A. Zeeb u8 ini_enable[AMPDU_MAX_SCB_TID];
129*b4c3e9b5SBjoern A. Zeeb u8 ba_tx_wsize;
130*b4c3e9b5SBjoern A. Zeeb u8 ba_rx_wsize;
131*b4c3e9b5SBjoern A. Zeeb u8 retry_limit;
132*b4c3e9b5SBjoern A. Zeeb u8 rr_retry_limit;
133*b4c3e9b5SBjoern A. Zeeb u8 retry_limit_tid[AMPDU_MAX_SCB_TID];
134*b4c3e9b5SBjoern A. Zeeb u8 rr_retry_limit_tid[AMPDU_MAX_SCB_TID];
135*b4c3e9b5SBjoern A. Zeeb u8 mpdu_density;
136*b4c3e9b5SBjoern A. Zeeb s8 max_pdu;
137*b4c3e9b5SBjoern A. Zeeb u8 dur;
138*b4c3e9b5SBjoern A. Zeeb u8 rx_factor;
139*b4c3e9b5SBjoern A. Zeeb u32 ffpld_rsvd;
140*b4c3e9b5SBjoern A. Zeeb u32 max_txlen[MCS_TABLE_SIZE][2][2];
141*b4c3e9b5SBjoern A. Zeeb bool mfbr;
142*b4c3e9b5SBjoern A. Zeeb u32 tx_max_funl;
143*b4c3e9b5SBjoern A. Zeeb struct brcms_fifo_info fifo_tb[NUM_FFPLD_FIFO];
144*b4c3e9b5SBjoern A. Zeeb };
145*b4c3e9b5SBjoern A. Zeeb
brcms_c_scb_ampdu_update_max_txlen(struct ampdu_info * ampdu,u8 dur)146*b4c3e9b5SBjoern A. Zeeb static void brcms_c_scb_ampdu_update_max_txlen(struct ampdu_info *ampdu, u8 dur)
147*b4c3e9b5SBjoern A. Zeeb {
148*b4c3e9b5SBjoern A. Zeeb u32 rate, mcs;
149*b4c3e9b5SBjoern A. Zeeb
150*b4c3e9b5SBjoern A. Zeeb for (mcs = 0; mcs < MCS_TABLE_SIZE; mcs++) {
151*b4c3e9b5SBjoern A. Zeeb /* rate is in Kbps; dur is in msec ==> len = (rate * dur) / 8 */
152*b4c3e9b5SBjoern A. Zeeb /* 20MHz, No SGI */
153*b4c3e9b5SBjoern A. Zeeb rate = mcs_2_rate(mcs, false, false);
154*b4c3e9b5SBjoern A. Zeeb ampdu->max_txlen[mcs][0][0] = (rate * dur) >> 3;
155*b4c3e9b5SBjoern A. Zeeb /* 40 MHz, No SGI */
156*b4c3e9b5SBjoern A. Zeeb rate = mcs_2_rate(mcs, true, false);
157*b4c3e9b5SBjoern A. Zeeb ampdu->max_txlen[mcs][1][0] = (rate * dur) >> 3;
158*b4c3e9b5SBjoern A. Zeeb /* 20MHz, SGI */
159*b4c3e9b5SBjoern A. Zeeb rate = mcs_2_rate(mcs, false, true);
160*b4c3e9b5SBjoern A. Zeeb ampdu->max_txlen[mcs][0][1] = (rate * dur) >> 3;
161*b4c3e9b5SBjoern A. Zeeb /* 40 MHz, SGI */
162*b4c3e9b5SBjoern A. Zeeb rate = mcs_2_rate(mcs, true, true);
163*b4c3e9b5SBjoern A. Zeeb ampdu->max_txlen[mcs][1][1] = (rate * dur) >> 3;
164*b4c3e9b5SBjoern A. Zeeb }
165*b4c3e9b5SBjoern A. Zeeb }
166*b4c3e9b5SBjoern A. Zeeb
brcms_c_ampdu_cap(struct ampdu_info * ampdu)167*b4c3e9b5SBjoern A. Zeeb static bool brcms_c_ampdu_cap(struct ampdu_info *ampdu)
168*b4c3e9b5SBjoern A. Zeeb {
169*b4c3e9b5SBjoern A. Zeeb if (BRCMS_PHY_11N_CAP(ampdu->wlc->band))
170*b4c3e9b5SBjoern A. Zeeb return true;
171*b4c3e9b5SBjoern A. Zeeb else
172*b4c3e9b5SBjoern A. Zeeb return false;
173*b4c3e9b5SBjoern A. Zeeb }
174*b4c3e9b5SBjoern A. Zeeb
brcms_c_ampdu_set(struct ampdu_info * ampdu,bool on)175*b4c3e9b5SBjoern A. Zeeb static int brcms_c_ampdu_set(struct ampdu_info *ampdu, bool on)
176*b4c3e9b5SBjoern A. Zeeb {
177*b4c3e9b5SBjoern A. Zeeb struct brcms_c_info *wlc = ampdu->wlc;
178*b4c3e9b5SBjoern A. Zeeb struct bcma_device *core = wlc->hw->d11core;
179*b4c3e9b5SBjoern A. Zeeb
180*b4c3e9b5SBjoern A. Zeeb wlc->pub->_ampdu = false;
181*b4c3e9b5SBjoern A. Zeeb
182*b4c3e9b5SBjoern A. Zeeb if (on) {
183*b4c3e9b5SBjoern A. Zeeb if (!(wlc->pub->_n_enab & SUPPORT_11N)) {
184*b4c3e9b5SBjoern A. Zeeb brcms_err(core, "wl%d: driver not nmode enabled\n",
185*b4c3e9b5SBjoern A. Zeeb wlc->pub->unit);
186*b4c3e9b5SBjoern A. Zeeb return -ENOTSUPP;
187*b4c3e9b5SBjoern A. Zeeb }
188*b4c3e9b5SBjoern A. Zeeb if (!brcms_c_ampdu_cap(ampdu)) {
189*b4c3e9b5SBjoern A. Zeeb brcms_err(core, "wl%d: device not ampdu capable\n",
190*b4c3e9b5SBjoern A. Zeeb wlc->pub->unit);
191*b4c3e9b5SBjoern A. Zeeb return -ENOTSUPP;
192*b4c3e9b5SBjoern A. Zeeb }
193*b4c3e9b5SBjoern A. Zeeb wlc->pub->_ampdu = on;
194*b4c3e9b5SBjoern A. Zeeb }
195*b4c3e9b5SBjoern A. Zeeb
196*b4c3e9b5SBjoern A. Zeeb return 0;
197*b4c3e9b5SBjoern A. Zeeb }
198*b4c3e9b5SBjoern A. Zeeb
brcms_c_ffpld_init(struct ampdu_info * ampdu)199*b4c3e9b5SBjoern A. Zeeb static void brcms_c_ffpld_init(struct ampdu_info *ampdu)
200*b4c3e9b5SBjoern A. Zeeb {
201*b4c3e9b5SBjoern A. Zeeb int i, j;
202*b4c3e9b5SBjoern A. Zeeb struct brcms_fifo_info *fifo;
203*b4c3e9b5SBjoern A. Zeeb
204*b4c3e9b5SBjoern A. Zeeb for (j = 0; j < NUM_FFPLD_FIFO; j++) {
205*b4c3e9b5SBjoern A. Zeeb fifo = (ampdu->fifo_tb + j);
206*b4c3e9b5SBjoern A. Zeeb fifo->ampdu_pld_size = 0;
207*b4c3e9b5SBjoern A. Zeeb for (i = 0; i <= FFPLD_MAX_MCS; i++)
208*b4c3e9b5SBjoern A. Zeeb fifo->mcs2ampdu_table[i] = 255;
209*b4c3e9b5SBjoern A. Zeeb fifo->dmaxferrate = 0;
210*b4c3e9b5SBjoern A. Zeeb fifo->accum_txampdu = 0;
211*b4c3e9b5SBjoern A. Zeeb fifo->prev_txfunfl = 0;
212*b4c3e9b5SBjoern A. Zeeb fifo->accum_txfunfl = 0;
213*b4c3e9b5SBjoern A. Zeeb
214*b4c3e9b5SBjoern A. Zeeb }
215*b4c3e9b5SBjoern A. Zeeb }
216*b4c3e9b5SBjoern A. Zeeb
brcms_c_ampdu_attach(struct brcms_c_info * wlc)217*b4c3e9b5SBjoern A. Zeeb struct ampdu_info *brcms_c_ampdu_attach(struct brcms_c_info *wlc)
218*b4c3e9b5SBjoern A. Zeeb {
219*b4c3e9b5SBjoern A. Zeeb struct ampdu_info *ampdu;
220*b4c3e9b5SBjoern A. Zeeb int i;
221*b4c3e9b5SBjoern A. Zeeb
222*b4c3e9b5SBjoern A. Zeeb ampdu = kzalloc(sizeof(*ampdu), GFP_ATOMIC);
223*b4c3e9b5SBjoern A. Zeeb if (!ampdu)
224*b4c3e9b5SBjoern A. Zeeb return NULL;
225*b4c3e9b5SBjoern A. Zeeb
226*b4c3e9b5SBjoern A. Zeeb ampdu->wlc = wlc;
227*b4c3e9b5SBjoern A. Zeeb
228*b4c3e9b5SBjoern A. Zeeb for (i = 0; i < AMPDU_MAX_SCB_TID; i++)
229*b4c3e9b5SBjoern A. Zeeb ampdu->ini_enable[i] = true;
230*b4c3e9b5SBjoern A. Zeeb /* Disable ampdu for VO by default */
231*b4c3e9b5SBjoern A. Zeeb ampdu->ini_enable[PRIO_8021D_VO] = false;
232*b4c3e9b5SBjoern A. Zeeb ampdu->ini_enable[PRIO_8021D_NC] = false;
233*b4c3e9b5SBjoern A. Zeeb
234*b4c3e9b5SBjoern A. Zeeb /* Disable ampdu for BK by default since not enough fifo space */
235*b4c3e9b5SBjoern A. Zeeb ampdu->ini_enable[PRIO_8021D_NONE] = false;
236*b4c3e9b5SBjoern A. Zeeb ampdu->ini_enable[PRIO_8021D_BK] = false;
237*b4c3e9b5SBjoern A. Zeeb
238*b4c3e9b5SBjoern A. Zeeb ampdu->ba_tx_wsize = AMPDU_TX_BA_DEF_WSIZE;
239*b4c3e9b5SBjoern A. Zeeb ampdu->ba_rx_wsize = AMPDU_RX_BA_DEF_WSIZE;
240*b4c3e9b5SBjoern A. Zeeb ampdu->mpdu_density = AMPDU_DEF_MPDU_DENSITY;
241*b4c3e9b5SBjoern A. Zeeb ampdu->max_pdu = AUTO;
242*b4c3e9b5SBjoern A. Zeeb ampdu->dur = AMPDU_MAX_DUR;
243*b4c3e9b5SBjoern A. Zeeb
244*b4c3e9b5SBjoern A. Zeeb ampdu->ffpld_rsvd = AMPDU_DEF_FFPLD_RSVD;
245*b4c3e9b5SBjoern A. Zeeb /*
246*b4c3e9b5SBjoern A. Zeeb * bump max ampdu rcv size to 64k for all 11n
247*b4c3e9b5SBjoern A. Zeeb * devices except 4321A0 and 4321A1
248*b4c3e9b5SBjoern A. Zeeb */
249*b4c3e9b5SBjoern A. Zeeb if (BRCMS_ISNPHY(wlc->band) && NREV_LT(wlc->band->phyrev, 2))
250*b4c3e9b5SBjoern A. Zeeb ampdu->rx_factor = IEEE80211_HT_MAX_AMPDU_32K;
251*b4c3e9b5SBjoern A. Zeeb else
252*b4c3e9b5SBjoern A. Zeeb ampdu->rx_factor = IEEE80211_HT_MAX_AMPDU_64K;
253*b4c3e9b5SBjoern A. Zeeb ampdu->retry_limit = AMPDU_DEF_RETRY_LIMIT;
254*b4c3e9b5SBjoern A. Zeeb ampdu->rr_retry_limit = AMPDU_DEF_RR_RETRY_LIMIT;
255*b4c3e9b5SBjoern A. Zeeb
256*b4c3e9b5SBjoern A. Zeeb for (i = 0; i < AMPDU_MAX_SCB_TID; i++) {
257*b4c3e9b5SBjoern A. Zeeb ampdu->retry_limit_tid[i] = ampdu->retry_limit;
258*b4c3e9b5SBjoern A. Zeeb ampdu->rr_retry_limit_tid[i] = ampdu->rr_retry_limit;
259*b4c3e9b5SBjoern A. Zeeb }
260*b4c3e9b5SBjoern A. Zeeb
261*b4c3e9b5SBjoern A. Zeeb brcms_c_scb_ampdu_update_max_txlen(ampdu, ampdu->dur);
262*b4c3e9b5SBjoern A. Zeeb ampdu->mfbr = false;
263*b4c3e9b5SBjoern A. Zeeb /* try to set ampdu to the default value */
264*b4c3e9b5SBjoern A. Zeeb brcms_c_ampdu_set(ampdu, wlc->pub->_ampdu);
265*b4c3e9b5SBjoern A. Zeeb
266*b4c3e9b5SBjoern A. Zeeb ampdu->tx_max_funl = FFPLD_TX_MAX_UNFL;
267*b4c3e9b5SBjoern A. Zeeb brcms_c_ffpld_init(ampdu);
268*b4c3e9b5SBjoern A. Zeeb
269*b4c3e9b5SBjoern A. Zeeb return ampdu;
270*b4c3e9b5SBjoern A. Zeeb }
271*b4c3e9b5SBjoern A. Zeeb
brcms_c_ampdu_detach(struct ampdu_info * ampdu)272*b4c3e9b5SBjoern A. Zeeb void brcms_c_ampdu_detach(struct ampdu_info *ampdu)
273*b4c3e9b5SBjoern A. Zeeb {
274*b4c3e9b5SBjoern A. Zeeb kfree(ampdu);
275*b4c3e9b5SBjoern A. Zeeb }
276*b4c3e9b5SBjoern A. Zeeb
brcms_c_scb_ampdu_update_config(struct ampdu_info * ampdu,struct scb * scb)277*b4c3e9b5SBjoern A. Zeeb static void brcms_c_scb_ampdu_update_config(struct ampdu_info *ampdu,
278*b4c3e9b5SBjoern A. Zeeb struct scb *scb)
279*b4c3e9b5SBjoern A. Zeeb {
280*b4c3e9b5SBjoern A. Zeeb struct scb_ampdu *scb_ampdu = &scb->scb_ampdu;
281*b4c3e9b5SBjoern A. Zeeb int i;
282*b4c3e9b5SBjoern A. Zeeb
283*b4c3e9b5SBjoern A. Zeeb scb_ampdu->max_pdu = AMPDU_NUM_MPDU;
284*b4c3e9b5SBjoern A. Zeeb
285*b4c3e9b5SBjoern A. Zeeb /* go back to legacy size if some preloading is occurring */
286*b4c3e9b5SBjoern A. Zeeb for (i = 0; i < NUM_FFPLD_FIFO; i++) {
287*b4c3e9b5SBjoern A. Zeeb if (ampdu->fifo_tb[i].ampdu_pld_size > FFPLD_PLD_INCR)
288*b4c3e9b5SBjoern A. Zeeb scb_ampdu->max_pdu = AMPDU_NUM_MPDU_LEGACY;
289*b4c3e9b5SBjoern A. Zeeb }
290*b4c3e9b5SBjoern A. Zeeb
291*b4c3e9b5SBjoern A. Zeeb /* apply user override */
292*b4c3e9b5SBjoern A. Zeeb if (ampdu->max_pdu != AUTO)
293*b4c3e9b5SBjoern A. Zeeb scb_ampdu->max_pdu = (u8) ampdu->max_pdu;
294*b4c3e9b5SBjoern A. Zeeb
295*b4c3e9b5SBjoern A. Zeeb scb_ampdu->release = min_t(u8, scb_ampdu->max_pdu,
296*b4c3e9b5SBjoern A. Zeeb AMPDU_SCB_MAX_RELEASE);
297*b4c3e9b5SBjoern A. Zeeb
298*b4c3e9b5SBjoern A. Zeeb if (scb_ampdu->max_rx_ampdu_bytes)
299*b4c3e9b5SBjoern A. Zeeb scb_ampdu->release = min_t(u8, scb_ampdu->release,
300*b4c3e9b5SBjoern A. Zeeb scb_ampdu->max_rx_ampdu_bytes / 1600);
301*b4c3e9b5SBjoern A. Zeeb
302*b4c3e9b5SBjoern A. Zeeb scb_ampdu->release = min(scb_ampdu->release,
303*b4c3e9b5SBjoern A. Zeeb ampdu->fifo_tb[TX_AC_BE_FIFO].
304*b4c3e9b5SBjoern A. Zeeb mcs2ampdu_table[FFPLD_MAX_MCS]);
305*b4c3e9b5SBjoern A. Zeeb }
306*b4c3e9b5SBjoern A. Zeeb
brcms_c_scb_ampdu_update_config_all(struct ampdu_info * ampdu)307*b4c3e9b5SBjoern A. Zeeb static void brcms_c_scb_ampdu_update_config_all(struct ampdu_info *ampdu)
308*b4c3e9b5SBjoern A. Zeeb {
309*b4c3e9b5SBjoern A. Zeeb brcms_c_scb_ampdu_update_config(ampdu, &du->wlc->pri_scb);
310*b4c3e9b5SBjoern A. Zeeb }
311*b4c3e9b5SBjoern A. Zeeb
brcms_c_ffpld_calc_mcs2ampdu_table(struct ampdu_info * ampdu,int f)312*b4c3e9b5SBjoern A. Zeeb static void brcms_c_ffpld_calc_mcs2ampdu_table(struct ampdu_info *ampdu, int f)
313*b4c3e9b5SBjoern A. Zeeb {
314*b4c3e9b5SBjoern A. Zeeb int i;
315*b4c3e9b5SBjoern A. Zeeb u32 phy_rate, dma_rate, tmp;
316*b4c3e9b5SBjoern A. Zeeb u8 max_mpdu;
317*b4c3e9b5SBjoern A. Zeeb struct brcms_fifo_info *fifo = (ampdu->fifo_tb + f);
318*b4c3e9b5SBjoern A. Zeeb
319*b4c3e9b5SBjoern A. Zeeb /* recompute the dma rate */
320*b4c3e9b5SBjoern A. Zeeb /* note : we divide/multiply by 100 to avoid integer overflows */
321*b4c3e9b5SBjoern A. Zeeb max_mpdu = min_t(u8, fifo->mcs2ampdu_table[FFPLD_MAX_MCS],
322*b4c3e9b5SBjoern A. Zeeb AMPDU_NUM_MPDU_LEGACY);
323*b4c3e9b5SBjoern A. Zeeb phy_rate = mcs_2_rate(FFPLD_MAX_MCS, true, false);
324*b4c3e9b5SBjoern A. Zeeb dma_rate =
325*b4c3e9b5SBjoern A. Zeeb (((phy_rate / 100) *
326*b4c3e9b5SBjoern A. Zeeb (max_mpdu * FFPLD_MPDU_SIZE - fifo->ampdu_pld_size))
327*b4c3e9b5SBjoern A. Zeeb / (max_mpdu * FFPLD_MPDU_SIZE)) * 100;
328*b4c3e9b5SBjoern A. Zeeb fifo->dmaxferrate = dma_rate;
329*b4c3e9b5SBjoern A. Zeeb
330*b4c3e9b5SBjoern A. Zeeb /* fill up the mcs2ampdu table; do not recalc the last mcs */
331*b4c3e9b5SBjoern A. Zeeb dma_rate = dma_rate >> 7;
332*b4c3e9b5SBjoern A. Zeeb for (i = 0; i < FFPLD_MAX_MCS; i++) {
333*b4c3e9b5SBjoern A. Zeeb /* shifting to keep it within integer range */
334*b4c3e9b5SBjoern A. Zeeb phy_rate = mcs_2_rate(i, true, false) >> 7;
335*b4c3e9b5SBjoern A. Zeeb if (phy_rate > dma_rate) {
336*b4c3e9b5SBjoern A. Zeeb tmp = ((fifo->ampdu_pld_size * phy_rate) /
337*b4c3e9b5SBjoern A. Zeeb ((phy_rate - dma_rate) * FFPLD_MPDU_SIZE)) + 1;
338*b4c3e9b5SBjoern A. Zeeb tmp = min_t(u32, tmp, 255);
339*b4c3e9b5SBjoern A. Zeeb fifo->mcs2ampdu_table[i] = (u8) tmp;
340*b4c3e9b5SBjoern A. Zeeb }
341*b4c3e9b5SBjoern A. Zeeb }
342*b4c3e9b5SBjoern A. Zeeb }
343*b4c3e9b5SBjoern A. Zeeb
344*b4c3e9b5SBjoern A. Zeeb /* evaluate the dma transfer rate using the tx underflows as feedback.
345*b4c3e9b5SBjoern A. Zeeb * If necessary, increase tx fifo preloading. If not enough,
346*b4c3e9b5SBjoern A. Zeeb * decrease maximum ampdu size for each mcs till underflows stop
347*b4c3e9b5SBjoern A. Zeeb * Return 1 if pre-loading not active, -1 if not an underflow event,
348*b4c3e9b5SBjoern A. Zeeb * 0 if pre-loading module took care of the event.
349*b4c3e9b5SBjoern A. Zeeb */
brcms_c_ffpld_check_txfunfl(struct brcms_c_info * wlc,int fid)350*b4c3e9b5SBjoern A. Zeeb static int brcms_c_ffpld_check_txfunfl(struct brcms_c_info *wlc, int fid)
351*b4c3e9b5SBjoern A. Zeeb {
352*b4c3e9b5SBjoern A. Zeeb struct ampdu_info *ampdu = wlc->ampdu;
353*b4c3e9b5SBjoern A. Zeeb u32 phy_rate = mcs_2_rate(FFPLD_MAX_MCS, true, false);
354*b4c3e9b5SBjoern A. Zeeb u8 max_mpdu;
355*b4c3e9b5SBjoern A. Zeeb u16 max_pld_size;
356*b4c3e9b5SBjoern A. Zeeb u32 new_txunfl;
357*b4c3e9b5SBjoern A. Zeeb struct brcms_fifo_info *fifo = (ampdu->fifo_tb + fid);
358*b4c3e9b5SBjoern A. Zeeb uint xmtfifo_sz;
359*b4c3e9b5SBjoern A. Zeeb u16 cur_txunfl;
360*b4c3e9b5SBjoern A. Zeeb
361*b4c3e9b5SBjoern A. Zeeb /* return if we got here for a different reason than underflows */
362*b4c3e9b5SBjoern A. Zeeb cur_txunfl = brcms_b_read_shm(wlc->hw,
363*b4c3e9b5SBjoern A. Zeeb M_UCODE_MACSTAT +
364*b4c3e9b5SBjoern A. Zeeb offsetof(struct macstat, txfunfl[fid]));
365*b4c3e9b5SBjoern A. Zeeb new_txunfl = (u16) (cur_txunfl - fifo->prev_txfunfl);
366*b4c3e9b5SBjoern A. Zeeb if (new_txunfl == 0) {
367*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core,
368*b4c3e9b5SBjoern A. Zeeb "TX status FRAG set but no tx underflows\n");
369*b4c3e9b5SBjoern A. Zeeb return -1;
370*b4c3e9b5SBjoern A. Zeeb }
371*b4c3e9b5SBjoern A. Zeeb fifo->prev_txfunfl = cur_txunfl;
372*b4c3e9b5SBjoern A. Zeeb
373*b4c3e9b5SBjoern A. Zeeb if (!ampdu->tx_max_funl)
374*b4c3e9b5SBjoern A. Zeeb return 1;
375*b4c3e9b5SBjoern A. Zeeb
376*b4c3e9b5SBjoern A. Zeeb /* check if fifo is big enough */
377*b4c3e9b5SBjoern A. Zeeb if (brcms_b_xmtfifo_sz_get(wlc->hw, fid, &xmtfifo_sz))
378*b4c3e9b5SBjoern A. Zeeb return -1;
379*b4c3e9b5SBjoern A. Zeeb
380*b4c3e9b5SBjoern A. Zeeb if ((TXFIFO_SIZE_UNIT * (u32) xmtfifo_sz) <= ampdu->ffpld_rsvd)
381*b4c3e9b5SBjoern A. Zeeb return 1;
382*b4c3e9b5SBjoern A. Zeeb
383*b4c3e9b5SBjoern A. Zeeb max_pld_size = TXFIFO_SIZE_UNIT * xmtfifo_sz - ampdu->ffpld_rsvd;
384*b4c3e9b5SBjoern A. Zeeb fifo->accum_txfunfl += new_txunfl;
385*b4c3e9b5SBjoern A. Zeeb
386*b4c3e9b5SBjoern A. Zeeb /* we need to wait for at least 10 underflows */
387*b4c3e9b5SBjoern A. Zeeb if (fifo->accum_txfunfl < 10)
388*b4c3e9b5SBjoern A. Zeeb return 0;
389*b4c3e9b5SBjoern A. Zeeb
390*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core, "tx_underflows %d\n", fifo->accum_txfunfl);
391*b4c3e9b5SBjoern A. Zeeb
392*b4c3e9b5SBjoern A. Zeeb max_mpdu = min_t(u8, fifo->mcs2ampdu_table[FFPLD_MAX_MCS],
393*b4c3e9b5SBjoern A. Zeeb AMPDU_NUM_MPDU_LEGACY);
394*b4c3e9b5SBjoern A. Zeeb
395*b4c3e9b5SBjoern A. Zeeb /* In case max value max_pdu is already lower than
396*b4c3e9b5SBjoern A. Zeeb the fifo depth, there is nothing more we can do.
397*b4c3e9b5SBjoern A. Zeeb */
398*b4c3e9b5SBjoern A. Zeeb
399*b4c3e9b5SBjoern A. Zeeb if (fifo->ampdu_pld_size >= max_mpdu * FFPLD_MPDU_SIZE) {
400*b4c3e9b5SBjoern A. Zeeb fifo->accum_txfunfl = 0;
401*b4c3e9b5SBjoern A. Zeeb return 0;
402*b4c3e9b5SBjoern A. Zeeb }
403*b4c3e9b5SBjoern A. Zeeb
404*b4c3e9b5SBjoern A. Zeeb if (fifo->ampdu_pld_size < max_pld_size) {
405*b4c3e9b5SBjoern A. Zeeb
406*b4c3e9b5SBjoern A. Zeeb /* increment by TX_FIFO_PLD_INC bytes */
407*b4c3e9b5SBjoern A. Zeeb fifo->ampdu_pld_size += FFPLD_PLD_INCR;
408*b4c3e9b5SBjoern A. Zeeb if (fifo->ampdu_pld_size > max_pld_size)
409*b4c3e9b5SBjoern A. Zeeb fifo->ampdu_pld_size = max_pld_size;
410*b4c3e9b5SBjoern A. Zeeb
411*b4c3e9b5SBjoern A. Zeeb /* update scb release size */
412*b4c3e9b5SBjoern A. Zeeb brcms_c_scb_ampdu_update_config_all(ampdu);
413*b4c3e9b5SBjoern A. Zeeb
414*b4c3e9b5SBjoern A. Zeeb /*
415*b4c3e9b5SBjoern A. Zeeb * compute a new dma xfer rate for max_mpdu @ max mcs.
416*b4c3e9b5SBjoern A. Zeeb * This is the minimum dma rate that can achieve no
417*b4c3e9b5SBjoern A. Zeeb * underflow condition for the current mpdu size.
418*b4c3e9b5SBjoern A. Zeeb *
419*b4c3e9b5SBjoern A. Zeeb * note : we divide/multiply by 100 to avoid integer overflows
420*b4c3e9b5SBjoern A. Zeeb */
421*b4c3e9b5SBjoern A. Zeeb fifo->dmaxferrate =
422*b4c3e9b5SBjoern A. Zeeb (((phy_rate / 100) *
423*b4c3e9b5SBjoern A. Zeeb (max_mpdu * FFPLD_MPDU_SIZE - fifo->ampdu_pld_size))
424*b4c3e9b5SBjoern A. Zeeb / (max_mpdu * FFPLD_MPDU_SIZE)) * 100;
425*b4c3e9b5SBjoern A. Zeeb
426*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core,
427*b4c3e9b5SBjoern A. Zeeb "DMA estimated transfer rate %d; "
428*b4c3e9b5SBjoern A. Zeeb "pre-load size %d\n",
429*b4c3e9b5SBjoern A. Zeeb fifo->dmaxferrate, fifo->ampdu_pld_size);
430*b4c3e9b5SBjoern A. Zeeb } else {
431*b4c3e9b5SBjoern A. Zeeb
432*b4c3e9b5SBjoern A. Zeeb /* decrease ampdu size */
433*b4c3e9b5SBjoern A. Zeeb if (fifo->mcs2ampdu_table[FFPLD_MAX_MCS] > 1) {
434*b4c3e9b5SBjoern A. Zeeb if (fifo->mcs2ampdu_table[FFPLD_MAX_MCS] == 255)
435*b4c3e9b5SBjoern A. Zeeb fifo->mcs2ampdu_table[FFPLD_MAX_MCS] =
436*b4c3e9b5SBjoern A. Zeeb AMPDU_NUM_MPDU_LEGACY - 1;
437*b4c3e9b5SBjoern A. Zeeb else
438*b4c3e9b5SBjoern A. Zeeb fifo->mcs2ampdu_table[FFPLD_MAX_MCS] -= 1;
439*b4c3e9b5SBjoern A. Zeeb
440*b4c3e9b5SBjoern A. Zeeb /* recompute the table */
441*b4c3e9b5SBjoern A. Zeeb brcms_c_ffpld_calc_mcs2ampdu_table(ampdu, fid);
442*b4c3e9b5SBjoern A. Zeeb
443*b4c3e9b5SBjoern A. Zeeb /* update scb release size */
444*b4c3e9b5SBjoern A. Zeeb brcms_c_scb_ampdu_update_config_all(ampdu);
445*b4c3e9b5SBjoern A. Zeeb }
446*b4c3e9b5SBjoern A. Zeeb }
447*b4c3e9b5SBjoern A. Zeeb fifo->accum_txfunfl = 0;
448*b4c3e9b5SBjoern A. Zeeb return 0;
449*b4c3e9b5SBjoern A. Zeeb }
450*b4c3e9b5SBjoern A. Zeeb
451*b4c3e9b5SBjoern A. Zeeb void
brcms_c_ampdu_tx_operational(struct brcms_c_info * wlc,u8 tid,uint max_rx_ampdu_bytes)452*b4c3e9b5SBjoern A. Zeeb brcms_c_ampdu_tx_operational(struct brcms_c_info *wlc, u8 tid,
453*b4c3e9b5SBjoern A. Zeeb uint max_rx_ampdu_bytes) /* from ht_cap in beacon */
454*b4c3e9b5SBjoern A. Zeeb {
455*b4c3e9b5SBjoern A. Zeeb struct scb_ampdu *scb_ampdu;
456*b4c3e9b5SBjoern A. Zeeb struct ampdu_info *ampdu = wlc->ampdu;
457*b4c3e9b5SBjoern A. Zeeb struct scb *scb = &wlc->pri_scb;
458*b4c3e9b5SBjoern A. Zeeb scb_ampdu = &scb->scb_ampdu;
459*b4c3e9b5SBjoern A. Zeeb
460*b4c3e9b5SBjoern A. Zeeb if (!ampdu->ini_enable[tid]) {
461*b4c3e9b5SBjoern A. Zeeb brcms_err(wlc->hw->d11core, "%s: Rejecting tid %d\n",
462*b4c3e9b5SBjoern A. Zeeb __func__, tid);
463*b4c3e9b5SBjoern A. Zeeb return;
464*b4c3e9b5SBjoern A. Zeeb }
465*b4c3e9b5SBjoern A. Zeeb
466*b4c3e9b5SBjoern A. Zeeb scb_ampdu->max_rx_ampdu_bytes = max_rx_ampdu_bytes;
467*b4c3e9b5SBjoern A. Zeeb }
468*b4c3e9b5SBjoern A. Zeeb
brcms_c_ampdu_reset_session(struct brcms_ampdu_session * session,struct brcms_c_info * wlc)469*b4c3e9b5SBjoern A. Zeeb void brcms_c_ampdu_reset_session(struct brcms_ampdu_session *session,
470*b4c3e9b5SBjoern A. Zeeb struct brcms_c_info *wlc)
471*b4c3e9b5SBjoern A. Zeeb {
472*b4c3e9b5SBjoern A. Zeeb session->wlc = wlc;
473*b4c3e9b5SBjoern A. Zeeb skb_queue_head_init(&session->skb_list);
474*b4c3e9b5SBjoern A. Zeeb session->max_ampdu_len = 0; /* determined from first MPDU */
475*b4c3e9b5SBjoern A. Zeeb session->max_ampdu_frames = 0; /* determined from first MPDU */
476*b4c3e9b5SBjoern A. Zeeb session->ampdu_len = 0;
477*b4c3e9b5SBjoern A. Zeeb session->dma_len = 0;
478*b4c3e9b5SBjoern A. Zeeb }
479*b4c3e9b5SBjoern A. Zeeb
480*b4c3e9b5SBjoern A. Zeeb /*
481*b4c3e9b5SBjoern A. Zeeb * Preps the given packet for AMPDU based on the session data. If the
482*b4c3e9b5SBjoern A. Zeeb * frame cannot be accommodated in the current session, -ENOSPC is
483*b4c3e9b5SBjoern A. Zeeb * returned.
484*b4c3e9b5SBjoern A. Zeeb */
brcms_c_ampdu_add_frame(struct brcms_ampdu_session * session,struct sk_buff * p)485*b4c3e9b5SBjoern A. Zeeb int brcms_c_ampdu_add_frame(struct brcms_ampdu_session *session,
486*b4c3e9b5SBjoern A. Zeeb struct sk_buff *p)
487*b4c3e9b5SBjoern A. Zeeb {
488*b4c3e9b5SBjoern A. Zeeb struct brcms_c_info *wlc = session->wlc;
489*b4c3e9b5SBjoern A. Zeeb struct ampdu_info *ampdu = wlc->ampdu;
490*b4c3e9b5SBjoern A. Zeeb struct scb *scb = &wlc->pri_scb;
491*b4c3e9b5SBjoern A. Zeeb struct scb_ampdu *scb_ampdu = &scb->scb_ampdu;
492*b4c3e9b5SBjoern A. Zeeb struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(p);
493*b4c3e9b5SBjoern A. Zeeb struct ieee80211_tx_rate *txrate = tx_info->status.rates;
494*b4c3e9b5SBjoern A. Zeeb struct d11txh *txh = (struct d11txh *)p->data;
495*b4c3e9b5SBjoern A. Zeeb unsigned ampdu_frames;
496*b4c3e9b5SBjoern A. Zeeb u8 ndelim, tid;
497*b4c3e9b5SBjoern A. Zeeb u8 *plcp;
498*b4c3e9b5SBjoern A. Zeeb uint len;
499*b4c3e9b5SBjoern A. Zeeb u16 mcl;
500*b4c3e9b5SBjoern A. Zeeb bool fbr_iscck;
501*b4c3e9b5SBjoern A. Zeeb bool rr;
502*b4c3e9b5SBjoern A. Zeeb
503*b4c3e9b5SBjoern A. Zeeb ndelim = txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM];
504*b4c3e9b5SBjoern A. Zeeb plcp = (u8 *)(txh + 1);
505*b4c3e9b5SBjoern A. Zeeb fbr_iscck = !(le16_to_cpu(txh->XtraFrameTypes) & 0x03);
506*b4c3e9b5SBjoern A. Zeeb len = fbr_iscck ? BRCMS_GET_CCK_PLCP_LEN(txh->FragPLCPFallback) :
507*b4c3e9b5SBjoern A. Zeeb BRCMS_GET_MIMO_PLCP_LEN(txh->FragPLCPFallback);
508*b4c3e9b5SBjoern A. Zeeb len = roundup(len, 4) + (ndelim + 1) * AMPDU_DELIMITER_LEN;
509*b4c3e9b5SBjoern A. Zeeb
510*b4c3e9b5SBjoern A. Zeeb ampdu_frames = skb_queue_len(&session->skb_list);
511*b4c3e9b5SBjoern A. Zeeb if (ampdu_frames != 0) {
512*b4c3e9b5SBjoern A. Zeeb struct sk_buff *first;
513*b4c3e9b5SBjoern A. Zeeb
514*b4c3e9b5SBjoern A. Zeeb if (ampdu_frames + 1 > session->max_ampdu_frames ||
515*b4c3e9b5SBjoern A. Zeeb session->ampdu_len + len > session->max_ampdu_len)
516*b4c3e9b5SBjoern A. Zeeb return -ENOSPC;
517*b4c3e9b5SBjoern A. Zeeb
518*b4c3e9b5SBjoern A. Zeeb /*
519*b4c3e9b5SBjoern A. Zeeb * We aren't really out of space if the new frame is of
520*b4c3e9b5SBjoern A. Zeeb * a different priority, but we want the same behaviour
521*b4c3e9b5SBjoern A. Zeeb * so return -ENOSPC anyway.
522*b4c3e9b5SBjoern A. Zeeb *
523*b4c3e9b5SBjoern A. Zeeb * XXX: The old AMPDU code did this, but is it really
524*b4c3e9b5SBjoern A. Zeeb * necessary?
525*b4c3e9b5SBjoern A. Zeeb */
526*b4c3e9b5SBjoern A. Zeeb first = skb_peek(&session->skb_list);
527*b4c3e9b5SBjoern A. Zeeb if (p->priority != first->priority)
528*b4c3e9b5SBjoern A. Zeeb return -ENOSPC;
529*b4c3e9b5SBjoern A. Zeeb }
530*b4c3e9b5SBjoern A. Zeeb
531*b4c3e9b5SBjoern A. Zeeb /*
532*b4c3e9b5SBjoern A. Zeeb * Now that we're sure this frame can be accommodated, update the
533*b4c3e9b5SBjoern A. Zeeb * session information.
534*b4c3e9b5SBjoern A. Zeeb */
535*b4c3e9b5SBjoern A. Zeeb session->ampdu_len += len;
536*b4c3e9b5SBjoern A. Zeeb session->dma_len += p->len;
537*b4c3e9b5SBjoern A. Zeeb
538*b4c3e9b5SBjoern A. Zeeb tid = (u8)p->priority;
539*b4c3e9b5SBjoern A. Zeeb
540*b4c3e9b5SBjoern A. Zeeb /* Handle retry limits */
541*b4c3e9b5SBjoern A. Zeeb if (txrate[0].count <= ampdu->rr_retry_limit_tid[tid]) {
542*b4c3e9b5SBjoern A. Zeeb txrate[0].count++;
543*b4c3e9b5SBjoern A. Zeeb rr = true;
544*b4c3e9b5SBjoern A. Zeeb } else {
545*b4c3e9b5SBjoern A. Zeeb txrate[1].count++;
546*b4c3e9b5SBjoern A. Zeeb rr = false;
547*b4c3e9b5SBjoern A. Zeeb }
548*b4c3e9b5SBjoern A. Zeeb
549*b4c3e9b5SBjoern A. Zeeb if (ampdu_frames == 0) {
550*b4c3e9b5SBjoern A. Zeeb u8 plcp0, plcp3, is40, sgi, mcs;
551*b4c3e9b5SBjoern A. Zeeb uint fifo = le16_to_cpu(txh->TxFrameID) & TXFID_QUEUE_MASK;
552*b4c3e9b5SBjoern A. Zeeb struct brcms_fifo_info *f = &du->fifo_tb[fifo];
553*b4c3e9b5SBjoern A. Zeeb
554*b4c3e9b5SBjoern A. Zeeb if (rr) {
555*b4c3e9b5SBjoern A. Zeeb plcp0 = plcp[0];
556*b4c3e9b5SBjoern A. Zeeb plcp3 = plcp[3];
557*b4c3e9b5SBjoern A. Zeeb } else {
558*b4c3e9b5SBjoern A. Zeeb plcp0 = txh->FragPLCPFallback[0];
559*b4c3e9b5SBjoern A. Zeeb plcp3 = txh->FragPLCPFallback[3];
560*b4c3e9b5SBjoern A. Zeeb
561*b4c3e9b5SBjoern A. Zeeb }
562*b4c3e9b5SBjoern A. Zeeb
563*b4c3e9b5SBjoern A. Zeeb /* Limit AMPDU size based on MCS */
564*b4c3e9b5SBjoern A. Zeeb is40 = (plcp0 & MIMO_PLCP_40MHZ) ? 1 : 0;
565*b4c3e9b5SBjoern A. Zeeb sgi = plcp3_issgi(plcp3) ? 1 : 0;
566*b4c3e9b5SBjoern A. Zeeb mcs = plcp0 & ~MIMO_PLCP_40MHZ;
567*b4c3e9b5SBjoern A. Zeeb session->max_ampdu_len = min(scb_ampdu->max_rx_ampdu_bytes,
568*b4c3e9b5SBjoern A. Zeeb ampdu->max_txlen[mcs][is40][sgi]);
569*b4c3e9b5SBjoern A. Zeeb
570*b4c3e9b5SBjoern A. Zeeb session->max_ampdu_frames = scb_ampdu->max_pdu;
571*b4c3e9b5SBjoern A. Zeeb if (mcs_2_rate(mcs, true, false) >= f->dmaxferrate) {
572*b4c3e9b5SBjoern A. Zeeb session->max_ampdu_frames =
573*b4c3e9b5SBjoern A. Zeeb min_t(u16, f->mcs2ampdu_table[mcs],
574*b4c3e9b5SBjoern A. Zeeb session->max_ampdu_frames);
575*b4c3e9b5SBjoern A. Zeeb }
576*b4c3e9b5SBjoern A. Zeeb }
577*b4c3e9b5SBjoern A. Zeeb
578*b4c3e9b5SBjoern A. Zeeb /*
579*b4c3e9b5SBjoern A. Zeeb * Treat all frames as "middle" frames of AMPDU here. First and
580*b4c3e9b5SBjoern A. Zeeb * last frames must be fixed up after all MPDUs have been prepped.
581*b4c3e9b5SBjoern A. Zeeb */
582*b4c3e9b5SBjoern A. Zeeb mcl = le16_to_cpu(txh->MacTxControlLow);
583*b4c3e9b5SBjoern A. Zeeb mcl &= ~TXC_AMPDU_MASK;
584*b4c3e9b5SBjoern A. Zeeb mcl |= (TXC_AMPDU_MIDDLE << TXC_AMPDU_SHIFT);
585*b4c3e9b5SBjoern A. Zeeb mcl &= ~(TXC_STARTMSDU | TXC_SENDRTS | TXC_SENDCTS);
586*b4c3e9b5SBjoern A. Zeeb txh->MacTxControlLow = cpu_to_le16(mcl);
587*b4c3e9b5SBjoern A. Zeeb txh->PreloadSize = 0; /* always default to 0 */
588*b4c3e9b5SBjoern A. Zeeb
589*b4c3e9b5SBjoern A. Zeeb skb_queue_tail(&session->skb_list, p);
590*b4c3e9b5SBjoern A. Zeeb
591*b4c3e9b5SBjoern A. Zeeb return 0;
592*b4c3e9b5SBjoern A. Zeeb }
593*b4c3e9b5SBjoern A. Zeeb
brcms_c_ampdu_finalize(struct brcms_ampdu_session * session)594*b4c3e9b5SBjoern A. Zeeb void brcms_c_ampdu_finalize(struct brcms_ampdu_session *session)
595*b4c3e9b5SBjoern A. Zeeb {
596*b4c3e9b5SBjoern A. Zeeb struct brcms_c_info *wlc = session->wlc;
597*b4c3e9b5SBjoern A. Zeeb struct ampdu_info *ampdu = wlc->ampdu;
598*b4c3e9b5SBjoern A. Zeeb struct sk_buff *first, *last;
599*b4c3e9b5SBjoern A. Zeeb struct d11txh *txh;
600*b4c3e9b5SBjoern A. Zeeb struct ieee80211_tx_info *tx_info;
601*b4c3e9b5SBjoern A. Zeeb struct ieee80211_tx_rate *txrate;
602*b4c3e9b5SBjoern A. Zeeb u8 ndelim;
603*b4c3e9b5SBjoern A. Zeeb u8 *plcp;
604*b4c3e9b5SBjoern A. Zeeb uint len;
605*b4c3e9b5SBjoern A. Zeeb uint fifo;
606*b4c3e9b5SBjoern A. Zeeb struct brcms_fifo_info *f;
607*b4c3e9b5SBjoern A. Zeeb u16 mcl;
608*b4c3e9b5SBjoern A. Zeeb bool fbr;
609*b4c3e9b5SBjoern A. Zeeb bool fbr_iscck;
610*b4c3e9b5SBjoern A. Zeeb struct ieee80211_rts *rts;
611*b4c3e9b5SBjoern A. Zeeb bool use_rts = false, use_cts = false;
612*b4c3e9b5SBjoern A. Zeeb u16 dma_len = session->dma_len;
613*b4c3e9b5SBjoern A. Zeeb u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
614*b4c3e9b5SBjoern A. Zeeb u32 rspec = 0, rspec_fallback = 0;
615*b4c3e9b5SBjoern A. Zeeb u32 rts_rspec = 0, rts_rspec_fallback = 0;
616*b4c3e9b5SBjoern A. Zeeb u8 plcp0, is40, mcs;
617*b4c3e9b5SBjoern A. Zeeb u16 mch;
618*b4c3e9b5SBjoern A. Zeeb u8 preamble_type = BRCMS_GF_PREAMBLE;
619*b4c3e9b5SBjoern A. Zeeb u8 fbr_preamble_type = BRCMS_GF_PREAMBLE;
620*b4c3e9b5SBjoern A. Zeeb u8 rts_preamble_type = BRCMS_LONG_PREAMBLE;
621*b4c3e9b5SBjoern A. Zeeb u8 rts_fbr_preamble_type = BRCMS_LONG_PREAMBLE;
622*b4c3e9b5SBjoern A. Zeeb
623*b4c3e9b5SBjoern A. Zeeb if (skb_queue_empty(&session->skb_list))
624*b4c3e9b5SBjoern A. Zeeb return;
625*b4c3e9b5SBjoern A. Zeeb
626*b4c3e9b5SBjoern A. Zeeb first = skb_peek(&session->skb_list);
627*b4c3e9b5SBjoern A. Zeeb last = skb_peek_tail(&session->skb_list);
628*b4c3e9b5SBjoern A. Zeeb
629*b4c3e9b5SBjoern A. Zeeb /* Need to fix up last MPDU first to adjust AMPDU length */
630*b4c3e9b5SBjoern A. Zeeb txh = (struct d11txh *)last->data;
631*b4c3e9b5SBjoern A. Zeeb fifo = le16_to_cpu(txh->TxFrameID) & TXFID_QUEUE_MASK;
632*b4c3e9b5SBjoern A. Zeeb f = &du->fifo_tb[fifo];
633*b4c3e9b5SBjoern A. Zeeb
634*b4c3e9b5SBjoern A. Zeeb mcl = le16_to_cpu(txh->MacTxControlLow);
635*b4c3e9b5SBjoern A. Zeeb mcl &= ~TXC_AMPDU_MASK;
636*b4c3e9b5SBjoern A. Zeeb mcl |= (TXC_AMPDU_LAST << TXC_AMPDU_SHIFT);
637*b4c3e9b5SBjoern A. Zeeb txh->MacTxControlLow = cpu_to_le16(mcl);
638*b4c3e9b5SBjoern A. Zeeb
639*b4c3e9b5SBjoern A. Zeeb /* remove the null delimiter after last mpdu */
640*b4c3e9b5SBjoern A. Zeeb ndelim = txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM];
641*b4c3e9b5SBjoern A. Zeeb txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] = 0;
642*b4c3e9b5SBjoern A. Zeeb session->ampdu_len -= ndelim * AMPDU_DELIMITER_LEN;
643*b4c3e9b5SBjoern A. Zeeb
644*b4c3e9b5SBjoern A. Zeeb /* remove the pad len from last mpdu */
645*b4c3e9b5SBjoern A. Zeeb fbr_iscck = ((le16_to_cpu(txh->XtraFrameTypes) & 0x3) == 0);
646*b4c3e9b5SBjoern A. Zeeb len = fbr_iscck ? BRCMS_GET_CCK_PLCP_LEN(txh->FragPLCPFallback) :
647*b4c3e9b5SBjoern A. Zeeb BRCMS_GET_MIMO_PLCP_LEN(txh->FragPLCPFallback);
648*b4c3e9b5SBjoern A. Zeeb session->ampdu_len -= roundup(len, 4) - len;
649*b4c3e9b5SBjoern A. Zeeb
650*b4c3e9b5SBjoern A. Zeeb /* Now fix up the first MPDU */
651*b4c3e9b5SBjoern A. Zeeb tx_info = IEEE80211_SKB_CB(first);
652*b4c3e9b5SBjoern A. Zeeb txrate = tx_info->status.rates;
653*b4c3e9b5SBjoern A. Zeeb txh = (struct d11txh *)first->data;
654*b4c3e9b5SBjoern A. Zeeb plcp = (u8 *)(txh + 1);
655*b4c3e9b5SBjoern A. Zeeb rts = (struct ieee80211_rts *)&txh->rts_frame;
656*b4c3e9b5SBjoern A. Zeeb
657*b4c3e9b5SBjoern A. Zeeb mcl = le16_to_cpu(txh->MacTxControlLow);
658*b4c3e9b5SBjoern A. Zeeb /* If only one MPDU leave it marked as last */
659*b4c3e9b5SBjoern A. Zeeb if (first != last) {
660*b4c3e9b5SBjoern A. Zeeb mcl &= ~TXC_AMPDU_MASK;
661*b4c3e9b5SBjoern A. Zeeb mcl |= (TXC_AMPDU_FIRST << TXC_AMPDU_SHIFT);
662*b4c3e9b5SBjoern A. Zeeb }
663*b4c3e9b5SBjoern A. Zeeb mcl |= TXC_STARTMSDU;
664*b4c3e9b5SBjoern A. Zeeb if (ieee80211_is_rts(rts->frame_control)) {
665*b4c3e9b5SBjoern A. Zeeb mcl |= TXC_SENDRTS;
666*b4c3e9b5SBjoern A. Zeeb use_rts = true;
667*b4c3e9b5SBjoern A. Zeeb }
668*b4c3e9b5SBjoern A. Zeeb if (ieee80211_is_cts(rts->frame_control)) {
669*b4c3e9b5SBjoern A. Zeeb mcl |= TXC_SENDCTS;
670*b4c3e9b5SBjoern A. Zeeb use_cts = true;
671*b4c3e9b5SBjoern A. Zeeb }
672*b4c3e9b5SBjoern A. Zeeb txh->MacTxControlLow = cpu_to_le16(mcl);
673*b4c3e9b5SBjoern A. Zeeb
674*b4c3e9b5SBjoern A. Zeeb fbr = txrate[1].count > 0;
675*b4c3e9b5SBjoern A. Zeeb if (!fbr)
676*b4c3e9b5SBjoern A. Zeeb plcp0 = plcp[0];
677*b4c3e9b5SBjoern A. Zeeb else
678*b4c3e9b5SBjoern A. Zeeb plcp0 = txh->FragPLCPFallback[0];
679*b4c3e9b5SBjoern A. Zeeb
680*b4c3e9b5SBjoern A. Zeeb is40 = (plcp0 & MIMO_PLCP_40MHZ) ? 1 : 0;
681*b4c3e9b5SBjoern A. Zeeb mcs = plcp0 & ~MIMO_PLCP_40MHZ;
682*b4c3e9b5SBjoern A. Zeeb
683*b4c3e9b5SBjoern A. Zeeb if (is40) {
684*b4c3e9b5SBjoern A. Zeeb if (CHSPEC_SB_UPPER(wlc_phy_chanspec_get(wlc->band->pi)))
685*b4c3e9b5SBjoern A. Zeeb mimo_ctlchbw = PHY_TXC1_BW_20MHZ_UP;
686*b4c3e9b5SBjoern A. Zeeb else
687*b4c3e9b5SBjoern A. Zeeb mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
688*b4c3e9b5SBjoern A. Zeeb }
689*b4c3e9b5SBjoern A. Zeeb
690*b4c3e9b5SBjoern A. Zeeb /* rebuild the rspec and rspec_fallback */
691*b4c3e9b5SBjoern A. Zeeb rspec = RSPEC_MIMORATE;
692*b4c3e9b5SBjoern A. Zeeb rspec |= plcp[0] & ~MIMO_PLCP_40MHZ;
693*b4c3e9b5SBjoern A. Zeeb if (plcp[0] & MIMO_PLCP_40MHZ)
694*b4c3e9b5SBjoern A. Zeeb rspec |= (PHY_TXC1_BW_40MHZ << RSPEC_BW_SHIFT);
695*b4c3e9b5SBjoern A. Zeeb
696*b4c3e9b5SBjoern A. Zeeb fbr_iscck = !(le16_to_cpu(txh->XtraFrameTypes) & 0x03);
697*b4c3e9b5SBjoern A. Zeeb if (fbr_iscck) {
698*b4c3e9b5SBjoern A. Zeeb rspec_fallback =
699*b4c3e9b5SBjoern A. Zeeb cck_rspec(cck_phy2mac_rate(txh->FragPLCPFallback[0]));
700*b4c3e9b5SBjoern A. Zeeb } else {
701*b4c3e9b5SBjoern A. Zeeb rspec_fallback = RSPEC_MIMORATE;
702*b4c3e9b5SBjoern A. Zeeb rspec_fallback |= txh->FragPLCPFallback[0] & ~MIMO_PLCP_40MHZ;
703*b4c3e9b5SBjoern A. Zeeb if (txh->FragPLCPFallback[0] & MIMO_PLCP_40MHZ)
704*b4c3e9b5SBjoern A. Zeeb rspec_fallback |= PHY_TXC1_BW_40MHZ << RSPEC_BW_SHIFT;
705*b4c3e9b5SBjoern A. Zeeb }
706*b4c3e9b5SBjoern A. Zeeb
707*b4c3e9b5SBjoern A. Zeeb if (use_rts || use_cts) {
708*b4c3e9b5SBjoern A. Zeeb rts_rspec =
709*b4c3e9b5SBjoern A. Zeeb brcms_c_rspec_to_rts_rspec(wlc, rspec,
710*b4c3e9b5SBjoern A. Zeeb false, mimo_ctlchbw);
711*b4c3e9b5SBjoern A. Zeeb rts_rspec_fallback =
712*b4c3e9b5SBjoern A. Zeeb brcms_c_rspec_to_rts_rspec(wlc, rspec_fallback,
713*b4c3e9b5SBjoern A. Zeeb false, mimo_ctlchbw);
714*b4c3e9b5SBjoern A. Zeeb }
715*b4c3e9b5SBjoern A. Zeeb
716*b4c3e9b5SBjoern A. Zeeb BRCMS_SET_MIMO_PLCP_LEN(plcp, session->ampdu_len);
717*b4c3e9b5SBjoern A. Zeeb /* mark plcp to indicate ampdu */
718*b4c3e9b5SBjoern A. Zeeb BRCMS_SET_MIMO_PLCP_AMPDU(plcp);
719*b4c3e9b5SBjoern A. Zeeb
720*b4c3e9b5SBjoern A. Zeeb /* reset the mixed mode header durations */
721*b4c3e9b5SBjoern A. Zeeb if (txh->MModeLen) {
722*b4c3e9b5SBjoern A. Zeeb u16 mmodelen = brcms_c_calc_lsig_len(wlc, rspec,
723*b4c3e9b5SBjoern A. Zeeb session->ampdu_len);
724*b4c3e9b5SBjoern A. Zeeb txh->MModeLen = cpu_to_le16(mmodelen);
725*b4c3e9b5SBjoern A. Zeeb preamble_type = BRCMS_MM_PREAMBLE;
726*b4c3e9b5SBjoern A. Zeeb }
727*b4c3e9b5SBjoern A. Zeeb if (txh->MModeFbrLen) {
728*b4c3e9b5SBjoern A. Zeeb u16 mmfbrlen = brcms_c_calc_lsig_len(wlc, rspec_fallback,
729*b4c3e9b5SBjoern A. Zeeb session->ampdu_len);
730*b4c3e9b5SBjoern A. Zeeb txh->MModeFbrLen = cpu_to_le16(mmfbrlen);
731*b4c3e9b5SBjoern A. Zeeb fbr_preamble_type = BRCMS_MM_PREAMBLE;
732*b4c3e9b5SBjoern A. Zeeb }
733*b4c3e9b5SBjoern A. Zeeb
734*b4c3e9b5SBjoern A. Zeeb /* set the preload length */
735*b4c3e9b5SBjoern A. Zeeb if (mcs_2_rate(mcs, true, false) >= f->dmaxferrate) {
736*b4c3e9b5SBjoern A. Zeeb dma_len = min(dma_len, f->ampdu_pld_size);
737*b4c3e9b5SBjoern A. Zeeb txh->PreloadSize = cpu_to_le16(dma_len);
738*b4c3e9b5SBjoern A. Zeeb } else {
739*b4c3e9b5SBjoern A. Zeeb txh->PreloadSize = 0;
740*b4c3e9b5SBjoern A. Zeeb }
741*b4c3e9b5SBjoern A. Zeeb
742*b4c3e9b5SBjoern A. Zeeb mch = le16_to_cpu(txh->MacTxControlHigh);
743*b4c3e9b5SBjoern A. Zeeb
744*b4c3e9b5SBjoern A. Zeeb /* update RTS dur fields */
745*b4c3e9b5SBjoern A. Zeeb if (use_rts || use_cts) {
746*b4c3e9b5SBjoern A. Zeeb u16 durid;
747*b4c3e9b5SBjoern A. Zeeb if ((mch & TXC_PREAMBLE_RTS_MAIN_SHORT) ==
748*b4c3e9b5SBjoern A. Zeeb TXC_PREAMBLE_RTS_MAIN_SHORT)
749*b4c3e9b5SBjoern A. Zeeb rts_preamble_type = BRCMS_SHORT_PREAMBLE;
750*b4c3e9b5SBjoern A. Zeeb
751*b4c3e9b5SBjoern A. Zeeb if ((mch & TXC_PREAMBLE_RTS_FB_SHORT) ==
752*b4c3e9b5SBjoern A. Zeeb TXC_PREAMBLE_RTS_FB_SHORT)
753*b4c3e9b5SBjoern A. Zeeb rts_fbr_preamble_type = BRCMS_SHORT_PREAMBLE;
754*b4c3e9b5SBjoern A. Zeeb
755*b4c3e9b5SBjoern A. Zeeb durid = brcms_c_compute_rtscts_dur(wlc, use_cts, rts_rspec,
756*b4c3e9b5SBjoern A. Zeeb rspec, rts_preamble_type,
757*b4c3e9b5SBjoern A. Zeeb preamble_type,
758*b4c3e9b5SBjoern A. Zeeb session->ampdu_len, true);
759*b4c3e9b5SBjoern A. Zeeb rts->duration = cpu_to_le16(durid);
760*b4c3e9b5SBjoern A. Zeeb durid = brcms_c_compute_rtscts_dur(wlc, use_cts,
761*b4c3e9b5SBjoern A. Zeeb rts_rspec_fallback,
762*b4c3e9b5SBjoern A. Zeeb rspec_fallback,
763*b4c3e9b5SBjoern A. Zeeb rts_fbr_preamble_type,
764*b4c3e9b5SBjoern A. Zeeb fbr_preamble_type,
765*b4c3e9b5SBjoern A. Zeeb session->ampdu_len, true);
766*b4c3e9b5SBjoern A. Zeeb txh->RTSDurFallback = cpu_to_le16(durid);
767*b4c3e9b5SBjoern A. Zeeb /* set TxFesTimeNormal */
768*b4c3e9b5SBjoern A. Zeeb txh->TxFesTimeNormal = rts->duration;
769*b4c3e9b5SBjoern A. Zeeb /* set fallback rate version of TxFesTimeNormal */
770*b4c3e9b5SBjoern A. Zeeb txh->TxFesTimeFallback = txh->RTSDurFallback;
771*b4c3e9b5SBjoern A. Zeeb }
772*b4c3e9b5SBjoern A. Zeeb
773*b4c3e9b5SBjoern A. Zeeb /* set flag and plcp for fallback rate */
774*b4c3e9b5SBjoern A. Zeeb if (fbr) {
775*b4c3e9b5SBjoern A. Zeeb mch |= TXC_AMPDU_FBR;
776*b4c3e9b5SBjoern A. Zeeb txh->MacTxControlHigh = cpu_to_le16(mch);
777*b4c3e9b5SBjoern A. Zeeb BRCMS_SET_MIMO_PLCP_AMPDU(plcp);
778*b4c3e9b5SBjoern A. Zeeb BRCMS_SET_MIMO_PLCP_AMPDU(txh->FragPLCPFallback);
779*b4c3e9b5SBjoern A. Zeeb }
780*b4c3e9b5SBjoern A. Zeeb
781*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core, "wl%d: count %d ampdu_len %d\n",
782*b4c3e9b5SBjoern A. Zeeb wlc->pub->unit, skb_queue_len(&session->skb_list),
783*b4c3e9b5SBjoern A. Zeeb session->ampdu_len);
784*b4c3e9b5SBjoern A. Zeeb }
785*b4c3e9b5SBjoern A. Zeeb
786*b4c3e9b5SBjoern A. Zeeb static void
brcms_c_ampdu_rate_status(struct brcms_c_info * wlc,struct ieee80211_tx_info * tx_info,struct tx_status * txs,u8 mcs)787*b4c3e9b5SBjoern A. Zeeb brcms_c_ampdu_rate_status(struct brcms_c_info *wlc,
788*b4c3e9b5SBjoern A. Zeeb struct ieee80211_tx_info *tx_info,
789*b4c3e9b5SBjoern A. Zeeb struct tx_status *txs, u8 mcs)
790*b4c3e9b5SBjoern A. Zeeb {
791*b4c3e9b5SBjoern A. Zeeb struct ieee80211_tx_rate *txrate = tx_info->status.rates;
792*b4c3e9b5SBjoern A. Zeeb int i;
793*b4c3e9b5SBjoern A. Zeeb
794*b4c3e9b5SBjoern A. Zeeb /* clear the rest of the rates */
795*b4c3e9b5SBjoern A. Zeeb for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
796*b4c3e9b5SBjoern A. Zeeb txrate[i].idx = -1;
797*b4c3e9b5SBjoern A. Zeeb txrate[i].count = 0;
798*b4c3e9b5SBjoern A. Zeeb }
799*b4c3e9b5SBjoern A. Zeeb }
800*b4c3e9b5SBjoern A. Zeeb
801*b4c3e9b5SBjoern A. Zeeb static void
brcms_c_ampdu_dotxstatus_complete(struct ampdu_info * ampdu,struct scb * scb,struct sk_buff * p,struct tx_status * txs,u32 s1,u32 s2)802*b4c3e9b5SBjoern A. Zeeb brcms_c_ampdu_dotxstatus_complete(struct ampdu_info *ampdu, struct scb *scb,
803*b4c3e9b5SBjoern A. Zeeb struct sk_buff *p, struct tx_status *txs,
804*b4c3e9b5SBjoern A. Zeeb u32 s1, u32 s2)
805*b4c3e9b5SBjoern A. Zeeb {
806*b4c3e9b5SBjoern A. Zeeb struct scb_ampdu *scb_ampdu;
807*b4c3e9b5SBjoern A. Zeeb struct brcms_c_info *wlc = ampdu->wlc;
808*b4c3e9b5SBjoern A. Zeeb struct scb_ampdu_tid_ini *ini;
809*b4c3e9b5SBjoern A. Zeeb u8 bitmap[8], queue, tid;
810*b4c3e9b5SBjoern A. Zeeb struct d11txh *txh;
811*b4c3e9b5SBjoern A. Zeeb u8 *plcp;
812*b4c3e9b5SBjoern A. Zeeb struct ieee80211_hdr *h;
813*b4c3e9b5SBjoern A. Zeeb u16 seq, start_seq = 0, bindex, index, mcl;
814*b4c3e9b5SBjoern A. Zeeb u8 mcs = 0;
815*b4c3e9b5SBjoern A. Zeeb bool ba_recd = false, ack_recd = false;
816*b4c3e9b5SBjoern A. Zeeb u8 tot_mpdu = 0;
817*b4c3e9b5SBjoern A. Zeeb uint supr_status;
818*b4c3e9b5SBjoern A. Zeeb bool retry = true;
819*b4c3e9b5SBjoern A. Zeeb u16 mimoantsel = 0;
820*b4c3e9b5SBjoern A. Zeeb u8 retry_limit;
821*b4c3e9b5SBjoern A. Zeeb struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(p);
822*b4c3e9b5SBjoern A. Zeeb
823*b4c3e9b5SBjoern A. Zeeb #ifdef DEBUG
824*b4c3e9b5SBjoern A. Zeeb u8 hole[AMPDU_MAX_MPDU];
825*b4c3e9b5SBjoern A. Zeeb memset(hole, 0, sizeof(hole));
826*b4c3e9b5SBjoern A. Zeeb #endif
827*b4c3e9b5SBjoern A. Zeeb
828*b4c3e9b5SBjoern A. Zeeb scb_ampdu = &scb->scb_ampdu;
829*b4c3e9b5SBjoern A. Zeeb tid = (u8) (p->priority);
830*b4c3e9b5SBjoern A. Zeeb
831*b4c3e9b5SBjoern A. Zeeb ini = &scb_ampdu->ini[tid];
832*b4c3e9b5SBjoern A. Zeeb retry_limit = ampdu->retry_limit_tid[tid];
833*b4c3e9b5SBjoern A. Zeeb memset(bitmap, 0, sizeof(bitmap));
834*b4c3e9b5SBjoern A. Zeeb queue = txs->frameid & TXFID_QUEUE_MASK;
835*b4c3e9b5SBjoern A. Zeeb supr_status = txs->status & TX_STATUS_SUPR_MASK;
836*b4c3e9b5SBjoern A. Zeeb
837*b4c3e9b5SBjoern A. Zeeb if (txs->status & TX_STATUS_ACK_RCV) {
838*b4c3e9b5SBjoern A. Zeeb WARN_ON(!(txs->status & TX_STATUS_INTERMEDIATE));
839*b4c3e9b5SBjoern A. Zeeb start_seq = txs->sequence >> SEQNUM_SHIFT;
840*b4c3e9b5SBjoern A. Zeeb bitmap[0] = (txs->status & TX_STATUS_BA_BMAP03_MASK) >>
841*b4c3e9b5SBjoern A. Zeeb TX_STATUS_BA_BMAP03_SHIFT;
842*b4c3e9b5SBjoern A. Zeeb
843*b4c3e9b5SBjoern A. Zeeb WARN_ON(s1 & TX_STATUS_INTERMEDIATE);
844*b4c3e9b5SBjoern A. Zeeb WARN_ON(!(s1 & TX_STATUS_AMPDU));
845*b4c3e9b5SBjoern A. Zeeb
846*b4c3e9b5SBjoern A. Zeeb bitmap[0] |=
847*b4c3e9b5SBjoern A. Zeeb (s1 & TX_STATUS_BA_BMAP47_MASK) <<
848*b4c3e9b5SBjoern A. Zeeb TX_STATUS_BA_BMAP47_SHIFT;
849*b4c3e9b5SBjoern A. Zeeb bitmap[1] = (s1 >> 8) & 0xff;
850*b4c3e9b5SBjoern A. Zeeb bitmap[2] = (s1 >> 16) & 0xff;
851*b4c3e9b5SBjoern A. Zeeb bitmap[3] = (s1 >> 24) & 0xff;
852*b4c3e9b5SBjoern A. Zeeb
853*b4c3e9b5SBjoern A. Zeeb bitmap[4] = s2 & 0xff;
854*b4c3e9b5SBjoern A. Zeeb bitmap[5] = (s2 >> 8) & 0xff;
855*b4c3e9b5SBjoern A. Zeeb bitmap[6] = (s2 >> 16) & 0xff;
856*b4c3e9b5SBjoern A. Zeeb bitmap[7] = (s2 >> 24) & 0xff;
857*b4c3e9b5SBjoern A. Zeeb
858*b4c3e9b5SBjoern A. Zeeb ba_recd = true;
859*b4c3e9b5SBjoern A. Zeeb } else {
860*b4c3e9b5SBjoern A. Zeeb if (supr_status) {
861*b4c3e9b5SBjoern A. Zeeb if (supr_status == TX_STATUS_SUPR_BADCH) {
862*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core,
863*b4c3e9b5SBjoern A. Zeeb "%s: Pkt tx suppressed, illegal channel possibly %d\n",
864*b4c3e9b5SBjoern A. Zeeb __func__, CHSPEC_CHANNEL(
865*b4c3e9b5SBjoern A. Zeeb wlc->default_bss->chanspec));
866*b4c3e9b5SBjoern A. Zeeb } else {
867*b4c3e9b5SBjoern A. Zeeb if (supr_status != TX_STATUS_SUPR_FRAG)
868*b4c3e9b5SBjoern A. Zeeb brcms_err(wlc->hw->d11core,
869*b4c3e9b5SBjoern A. Zeeb "%s: supr_status 0x%x\n",
870*b4c3e9b5SBjoern A. Zeeb __func__, supr_status);
871*b4c3e9b5SBjoern A. Zeeb }
872*b4c3e9b5SBjoern A. Zeeb /* no need to retry for badch; will fail again */
873*b4c3e9b5SBjoern A. Zeeb if (supr_status == TX_STATUS_SUPR_BADCH ||
874*b4c3e9b5SBjoern A. Zeeb supr_status == TX_STATUS_SUPR_EXPTIME) {
875*b4c3e9b5SBjoern A. Zeeb retry = false;
876*b4c3e9b5SBjoern A. Zeeb } else if (supr_status == TX_STATUS_SUPR_EXPTIME) {
877*b4c3e9b5SBjoern A. Zeeb /* TX underflow:
878*b4c3e9b5SBjoern A. Zeeb * try tuning pre-loading or ampdu size
879*b4c3e9b5SBjoern A. Zeeb */
880*b4c3e9b5SBjoern A. Zeeb } else if (supr_status == TX_STATUS_SUPR_FRAG) {
881*b4c3e9b5SBjoern A. Zeeb /*
882*b4c3e9b5SBjoern A. Zeeb * if there were underflows, but pre-loading
883*b4c3e9b5SBjoern A. Zeeb * is not active, notify rate adaptation.
884*b4c3e9b5SBjoern A. Zeeb */
885*b4c3e9b5SBjoern A. Zeeb brcms_c_ffpld_check_txfunfl(wlc, queue);
886*b4c3e9b5SBjoern A. Zeeb }
887*b4c3e9b5SBjoern A. Zeeb } else if (txs->phyerr) {
888*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core,
889*b4c3e9b5SBjoern A. Zeeb "%s: ampdu tx phy error (0x%x)\n",
890*b4c3e9b5SBjoern A. Zeeb __func__, txs->phyerr);
891*b4c3e9b5SBjoern A. Zeeb }
892*b4c3e9b5SBjoern A. Zeeb }
893*b4c3e9b5SBjoern A. Zeeb
894*b4c3e9b5SBjoern A. Zeeb /* loop through all pkts and retry if not acked */
895*b4c3e9b5SBjoern A. Zeeb while (p) {
896*b4c3e9b5SBjoern A. Zeeb tx_info = IEEE80211_SKB_CB(p);
897*b4c3e9b5SBjoern A. Zeeb txh = (struct d11txh *) p->data;
898*b4c3e9b5SBjoern A. Zeeb mcl = le16_to_cpu(txh->MacTxControlLow);
899*b4c3e9b5SBjoern A. Zeeb plcp = (u8 *) (txh + 1);
900*b4c3e9b5SBjoern A. Zeeb h = (struct ieee80211_hdr *)(plcp + D11_PHY_HDR_LEN);
901*b4c3e9b5SBjoern A. Zeeb seq = le16_to_cpu(h->seq_ctrl) >> SEQNUM_SHIFT;
902*b4c3e9b5SBjoern A. Zeeb
903*b4c3e9b5SBjoern A. Zeeb trace_brcms_txdesc(&wlc->hw->d11core->dev, txh, sizeof(*txh));
904*b4c3e9b5SBjoern A. Zeeb
905*b4c3e9b5SBjoern A. Zeeb if (tot_mpdu == 0) {
906*b4c3e9b5SBjoern A. Zeeb mcs = plcp[0] & MIMO_PLCP_MCS_MASK;
907*b4c3e9b5SBjoern A. Zeeb mimoantsel = le16_to_cpu(txh->ABI_MimoAntSel);
908*b4c3e9b5SBjoern A. Zeeb }
909*b4c3e9b5SBjoern A. Zeeb
910*b4c3e9b5SBjoern A. Zeeb index = TX_SEQ_TO_INDEX(seq);
911*b4c3e9b5SBjoern A. Zeeb ack_recd = false;
912*b4c3e9b5SBjoern A. Zeeb if (ba_recd) {
913*b4c3e9b5SBjoern A. Zeeb int block_acked;
914*b4c3e9b5SBjoern A. Zeeb
915*b4c3e9b5SBjoern A. Zeeb bindex = MODSUB_POW2(seq, start_seq, SEQNUM_MAX);
916*b4c3e9b5SBjoern A. Zeeb if (bindex < AMPDU_TX_BA_MAX_WSIZE)
917*b4c3e9b5SBjoern A. Zeeb block_acked = isset(bitmap, bindex);
918*b4c3e9b5SBjoern A. Zeeb else
919*b4c3e9b5SBjoern A. Zeeb block_acked = 0;
920*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core,
921*b4c3e9b5SBjoern A. Zeeb "tid %d seq %d, start_seq %d, bindex %d set %d, index %d\n",
922*b4c3e9b5SBjoern A. Zeeb tid, seq, start_seq, bindex,
923*b4c3e9b5SBjoern A. Zeeb block_acked, index);
924*b4c3e9b5SBjoern A. Zeeb /* if acked then clear bit and free packet */
925*b4c3e9b5SBjoern A. Zeeb if (block_acked) {
926*b4c3e9b5SBjoern A. Zeeb ini->txretry[index] = 0;
927*b4c3e9b5SBjoern A. Zeeb
928*b4c3e9b5SBjoern A. Zeeb /*
929*b4c3e9b5SBjoern A. Zeeb * ampdu_ack_len:
930*b4c3e9b5SBjoern A. Zeeb * number of acked aggregated frames
931*b4c3e9b5SBjoern A. Zeeb */
932*b4c3e9b5SBjoern A. Zeeb /* ampdu_len: number of aggregated frames */
933*b4c3e9b5SBjoern A. Zeeb brcms_c_ampdu_rate_status(wlc, tx_info, txs,
934*b4c3e9b5SBjoern A. Zeeb mcs);
935*b4c3e9b5SBjoern A. Zeeb tx_info->flags |= IEEE80211_TX_STAT_ACK;
936*b4c3e9b5SBjoern A. Zeeb tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
937*b4c3e9b5SBjoern A. Zeeb tx_info->status.ampdu_ack_len =
938*b4c3e9b5SBjoern A. Zeeb tx_info->status.ampdu_len = 1;
939*b4c3e9b5SBjoern A. Zeeb
940*b4c3e9b5SBjoern A. Zeeb skb_pull(p, D11_PHY_HDR_LEN);
941*b4c3e9b5SBjoern A. Zeeb skb_pull(p, D11_TXH_LEN);
942*b4c3e9b5SBjoern A. Zeeb
943*b4c3e9b5SBjoern A. Zeeb ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw,
944*b4c3e9b5SBjoern A. Zeeb p);
945*b4c3e9b5SBjoern A. Zeeb ack_recd = true;
946*b4c3e9b5SBjoern A. Zeeb }
947*b4c3e9b5SBjoern A. Zeeb }
948*b4c3e9b5SBjoern A. Zeeb /* either retransmit or send bar if ack not recd */
949*b4c3e9b5SBjoern A. Zeeb if (!ack_recd) {
950*b4c3e9b5SBjoern A. Zeeb if (retry && (ini->txretry[index] < (int)retry_limit)) {
951*b4c3e9b5SBjoern A. Zeeb int ret;
952*b4c3e9b5SBjoern A. Zeeb ini->txretry[index]++;
953*b4c3e9b5SBjoern A. Zeeb ret = brcms_c_txfifo(wlc, queue, p);
954*b4c3e9b5SBjoern A. Zeeb /*
955*b4c3e9b5SBjoern A. Zeeb * We shouldn't be out of space in the DMA
956*b4c3e9b5SBjoern A. Zeeb * ring here since we're reinserting a frame
957*b4c3e9b5SBjoern A. Zeeb * that was just pulled out.
958*b4c3e9b5SBjoern A. Zeeb */
959*b4c3e9b5SBjoern A. Zeeb WARN_ONCE(ret, "queue %d out of txds\n", queue);
960*b4c3e9b5SBjoern A. Zeeb } else {
961*b4c3e9b5SBjoern A. Zeeb /* Retry timeout */
962*b4c3e9b5SBjoern A. Zeeb ieee80211_tx_info_clear_status(tx_info);
963*b4c3e9b5SBjoern A. Zeeb tx_info->status.ampdu_ack_len = 0;
964*b4c3e9b5SBjoern A. Zeeb tx_info->status.ampdu_len = 1;
965*b4c3e9b5SBjoern A. Zeeb tx_info->flags |=
966*b4c3e9b5SBjoern A. Zeeb IEEE80211_TX_STAT_AMPDU_NO_BACK;
967*b4c3e9b5SBjoern A. Zeeb skb_pull(p, D11_PHY_HDR_LEN);
968*b4c3e9b5SBjoern A. Zeeb skb_pull(p, D11_TXH_LEN);
969*b4c3e9b5SBjoern A. Zeeb brcms_dbg_ht(wlc->hw->d11core,
970*b4c3e9b5SBjoern A. Zeeb "BA Timeout, seq %d\n",
971*b4c3e9b5SBjoern A. Zeeb seq);
972*b4c3e9b5SBjoern A. Zeeb ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw,
973*b4c3e9b5SBjoern A. Zeeb p);
974*b4c3e9b5SBjoern A. Zeeb }
975*b4c3e9b5SBjoern A. Zeeb }
976*b4c3e9b5SBjoern A. Zeeb tot_mpdu++;
977*b4c3e9b5SBjoern A. Zeeb
978*b4c3e9b5SBjoern A. Zeeb /* break out if last packet of ampdu */
979*b4c3e9b5SBjoern A. Zeeb if (((mcl & TXC_AMPDU_MASK) >> TXC_AMPDU_SHIFT) ==
980*b4c3e9b5SBjoern A. Zeeb TXC_AMPDU_LAST)
981*b4c3e9b5SBjoern A. Zeeb break;
982*b4c3e9b5SBjoern A. Zeeb
983*b4c3e9b5SBjoern A. Zeeb p = dma_getnexttxp(wlc->hw->di[queue], DMA_RANGE_TRANSMITTED);
984*b4c3e9b5SBjoern A. Zeeb }
985*b4c3e9b5SBjoern A. Zeeb
986*b4c3e9b5SBjoern A. Zeeb /* update rate state */
987*b4c3e9b5SBjoern A. Zeeb brcms_c_antsel_antsel2id(wlc->asi, mimoantsel);
988*b4c3e9b5SBjoern A. Zeeb }
989*b4c3e9b5SBjoern A. Zeeb
990*b4c3e9b5SBjoern A. Zeeb void
brcms_c_ampdu_dotxstatus(struct ampdu_info * ampdu,struct scb * scb,struct sk_buff * p,struct tx_status * txs)991*b4c3e9b5SBjoern A. Zeeb brcms_c_ampdu_dotxstatus(struct ampdu_info *ampdu, struct scb *scb,
992*b4c3e9b5SBjoern A. Zeeb struct sk_buff *p, struct tx_status *txs)
993*b4c3e9b5SBjoern A. Zeeb {
994*b4c3e9b5SBjoern A. Zeeb struct brcms_c_info *wlc = ampdu->wlc;
995*b4c3e9b5SBjoern A. Zeeb u32 s1 = 0, s2 = 0;
996*b4c3e9b5SBjoern A. Zeeb
997*b4c3e9b5SBjoern A. Zeeb /* BMAC_NOTE: For the split driver, second level txstatus comes later
998*b4c3e9b5SBjoern A. Zeeb * So if the ACK was received then wait for the second level else just
999*b4c3e9b5SBjoern A. Zeeb * call the first one
1000*b4c3e9b5SBjoern A. Zeeb */
1001*b4c3e9b5SBjoern A. Zeeb if (txs->status & TX_STATUS_ACK_RCV) {
1002*b4c3e9b5SBjoern A. Zeeb u8 status_delay = 0;
1003*b4c3e9b5SBjoern A. Zeeb
1004*b4c3e9b5SBjoern A. Zeeb /* wait till the next 8 bytes of txstatus is available */
1005*b4c3e9b5SBjoern A. Zeeb s1 = bcma_read32(wlc->hw->d11core, D11REGOFFS(frmtxstatus));
1006*b4c3e9b5SBjoern A. Zeeb while ((s1 & TXS_V) == 0) {
1007*b4c3e9b5SBjoern A. Zeeb udelay(1);
1008*b4c3e9b5SBjoern A. Zeeb status_delay++;
1009*b4c3e9b5SBjoern A. Zeeb if (status_delay > 10)
1010*b4c3e9b5SBjoern A. Zeeb return; /* error condition */
1011*b4c3e9b5SBjoern A. Zeeb s1 = bcma_read32(wlc->hw->d11core,
1012*b4c3e9b5SBjoern A. Zeeb D11REGOFFS(frmtxstatus));
1013*b4c3e9b5SBjoern A. Zeeb }
1014*b4c3e9b5SBjoern A. Zeeb
1015*b4c3e9b5SBjoern A. Zeeb s2 = bcma_read32(wlc->hw->d11core, D11REGOFFS(frmtxstatus2));
1016*b4c3e9b5SBjoern A. Zeeb }
1017*b4c3e9b5SBjoern A. Zeeb
1018*b4c3e9b5SBjoern A. Zeeb if (scb) {
1019*b4c3e9b5SBjoern A. Zeeb brcms_c_ampdu_dotxstatus_complete(ampdu, scb, p, txs, s1, s2);
1020*b4c3e9b5SBjoern A. Zeeb } else {
1021*b4c3e9b5SBjoern A. Zeeb /* loop through all pkts and free */
1022*b4c3e9b5SBjoern A. Zeeb u8 queue = txs->frameid & TXFID_QUEUE_MASK;
1023*b4c3e9b5SBjoern A. Zeeb struct d11txh *txh;
1024*b4c3e9b5SBjoern A. Zeeb u16 mcl;
1025*b4c3e9b5SBjoern A. Zeeb while (p) {
1026*b4c3e9b5SBjoern A. Zeeb txh = (struct d11txh *) p->data;
1027*b4c3e9b5SBjoern A. Zeeb trace_brcms_txdesc(&wlc->hw->d11core->dev, txh,
1028*b4c3e9b5SBjoern A. Zeeb sizeof(*txh));
1029*b4c3e9b5SBjoern A. Zeeb mcl = le16_to_cpu(txh->MacTxControlLow);
1030*b4c3e9b5SBjoern A. Zeeb brcmu_pkt_buf_free_skb(p);
1031*b4c3e9b5SBjoern A. Zeeb /* break out if last packet of ampdu */
1032*b4c3e9b5SBjoern A. Zeeb if (((mcl & TXC_AMPDU_MASK) >> TXC_AMPDU_SHIFT) ==
1033*b4c3e9b5SBjoern A. Zeeb TXC_AMPDU_LAST)
1034*b4c3e9b5SBjoern A. Zeeb break;
1035*b4c3e9b5SBjoern A. Zeeb p = dma_getnexttxp(wlc->hw->di[queue],
1036*b4c3e9b5SBjoern A. Zeeb DMA_RANGE_TRANSMITTED);
1037*b4c3e9b5SBjoern A. Zeeb }
1038*b4c3e9b5SBjoern A. Zeeb }
1039*b4c3e9b5SBjoern A. Zeeb }
1040*b4c3e9b5SBjoern A. Zeeb
brcms_c_ampdu_macaddr_upd(struct brcms_c_info * wlc)1041*b4c3e9b5SBjoern A. Zeeb void brcms_c_ampdu_macaddr_upd(struct brcms_c_info *wlc)
1042*b4c3e9b5SBjoern A. Zeeb {
1043*b4c3e9b5SBjoern A. Zeeb char template[T_RAM_ACCESS_SZ * 2];
1044*b4c3e9b5SBjoern A. Zeeb
1045*b4c3e9b5SBjoern A. Zeeb /* driver needs to write the ta in the template; ta is at offset 16 */
1046*b4c3e9b5SBjoern A. Zeeb memset(template, 0, sizeof(template));
1047*b4c3e9b5SBjoern A. Zeeb memcpy(template, wlc->pub->cur_etheraddr, ETH_ALEN);
1048*b4c3e9b5SBjoern A. Zeeb brcms_b_write_template_ram(wlc->hw, (T_BA_TPL_BASE + 16),
1049*b4c3e9b5SBjoern A. Zeeb (T_RAM_ACCESS_SZ * 2),
1050*b4c3e9b5SBjoern A. Zeeb template);
1051*b4c3e9b5SBjoern A. Zeeb }
1052*b4c3e9b5SBjoern A. Zeeb
brcms_c_aggregatable(struct brcms_c_info * wlc,u8 tid)1053*b4c3e9b5SBjoern A. Zeeb bool brcms_c_aggregatable(struct brcms_c_info *wlc, u8 tid)
1054*b4c3e9b5SBjoern A. Zeeb {
1055*b4c3e9b5SBjoern A. Zeeb return wlc->ampdu->ini_enable[tid];
1056*b4c3e9b5SBjoern A. Zeeb }
1057*b4c3e9b5SBjoern A. Zeeb
brcms_c_ampdu_shm_upd(struct ampdu_info * ampdu)1058*b4c3e9b5SBjoern A. Zeeb void brcms_c_ampdu_shm_upd(struct ampdu_info *ampdu)
1059*b4c3e9b5SBjoern A. Zeeb {
1060*b4c3e9b5SBjoern A. Zeeb struct brcms_c_info *wlc = ampdu->wlc;
1061*b4c3e9b5SBjoern A. Zeeb
1062*b4c3e9b5SBjoern A. Zeeb /*
1063*b4c3e9b5SBjoern A. Zeeb * Extend ucode internal watchdog timer to
1064*b4c3e9b5SBjoern A. Zeeb * match larger received frames
1065*b4c3e9b5SBjoern A. Zeeb */
1066*b4c3e9b5SBjoern A. Zeeb if ((ampdu->rx_factor & IEEE80211_HT_AMPDU_PARM_FACTOR) ==
1067*b4c3e9b5SBjoern A. Zeeb IEEE80211_HT_MAX_AMPDU_64K) {
1068*b4c3e9b5SBjoern A. Zeeb brcms_b_write_shm(wlc->hw, M_MIMO_MAXSYM, MIMO_MAXSYM_MAX);
1069*b4c3e9b5SBjoern A. Zeeb brcms_b_write_shm(wlc->hw, M_WATCHDOG_8TU, WATCHDOG_8TU_MAX);
1070*b4c3e9b5SBjoern A. Zeeb } else {
1071*b4c3e9b5SBjoern A. Zeeb brcms_b_write_shm(wlc->hw, M_MIMO_MAXSYM, MIMO_MAXSYM_DEF);
1072*b4c3e9b5SBjoern A. Zeeb brcms_b_write_shm(wlc->hw, M_WATCHDOG_8TU, WATCHDOG_8TU_DEF);
1073*b4c3e9b5SBjoern A. Zeeb }
1074*b4c3e9b5SBjoern A. Zeeb }
1075*b4c3e9b5SBjoern A. Zeeb
1076*b4c3e9b5SBjoern A. Zeeb /*
1077*b4c3e9b5SBjoern A. Zeeb * callback function that helps invalidating ampdu packets in a DMA queue
1078*b4c3e9b5SBjoern A. Zeeb */
dma_cb_fn_ampdu(void * txi,void * arg_a)1079*b4c3e9b5SBjoern A. Zeeb static void dma_cb_fn_ampdu(void *txi, void *arg_a)
1080*b4c3e9b5SBjoern A. Zeeb {
1081*b4c3e9b5SBjoern A. Zeeb struct ieee80211_sta *sta = arg_a;
1082*b4c3e9b5SBjoern A. Zeeb struct ieee80211_tx_info *tx_info = (struct ieee80211_tx_info *)txi;
1083*b4c3e9b5SBjoern A. Zeeb
1084*b4c3e9b5SBjoern A. Zeeb if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) &&
1085*b4c3e9b5SBjoern A. Zeeb (tx_info->rate_driver_data[0] == sta || sta == NULL))
1086*b4c3e9b5SBjoern A. Zeeb tx_info->rate_driver_data[0] = NULL;
1087*b4c3e9b5SBjoern A. Zeeb }
1088*b4c3e9b5SBjoern A. Zeeb
1089*b4c3e9b5SBjoern A. Zeeb /*
1090*b4c3e9b5SBjoern A. Zeeb * When a remote party is no longer available for ampdu communication, any
1091*b4c3e9b5SBjoern A. Zeeb * pending tx ampdu packets in the driver have to be flushed.
1092*b4c3e9b5SBjoern A. Zeeb */
brcms_c_ampdu_flush(struct brcms_c_info * wlc,struct ieee80211_sta * sta,u16 tid)1093*b4c3e9b5SBjoern A. Zeeb void brcms_c_ampdu_flush(struct brcms_c_info *wlc,
1094*b4c3e9b5SBjoern A. Zeeb struct ieee80211_sta *sta, u16 tid)
1095*b4c3e9b5SBjoern A. Zeeb {
1096*b4c3e9b5SBjoern A. Zeeb brcms_c_inval_dma_pkts(wlc->hw, sta, dma_cb_fn_ampdu);
1097*b4c3e9b5SBjoern A. Zeeb }
1098