4b81a9d422ffbf8845d77d0550fbe941524a840f
[librecmc/librecmc.git] / package / kernel / mac80211 / patches / 652-0002-rtl8xxxu-Pass-tx_info-to-fill_txdesc-in-order-to-hav.patch
1 From f958b1e0806c045830d78c4287fbcddf9e5fd9d0 Mon Sep 17 00:00:00 2001
2 From: Jes Sorensen <Jes.Sorensen@redhat.com>
3 Date: Thu, 6 Oct 2016 21:08:53 -0400
4 Subject: [PATCH] rtl8xxxu: Pass tx_info to fill_txdesc in order to have access
5  to retry count
6
7 In order to obtain retry count for a given rate we need to pass the
8 full struct ieee80211_tx_info to the function setting the rate in he
9 TX descriptor.
10
11 This uncovered a huge bug where the old code would use struct
12 ieee80211_rate.flags to test for rate parameters, which is always
13 zero, instead of the flags value from struct ieee80211_tx_rate.
14
15 Time to find a brown paper bag :(
16
17 Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
18 ---
19  drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h   | 27 ++++----
20  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c  | 71 ++++++++++++++--------
21  2 files changed, 60 insertions(+), 38 deletions(-)
22
23 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
24 +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
25 @@ -1337,10 +1337,11 @@ struct rtl8xxxu_fileops {
26                                   u32 ramask, int sgi);
27         void (*report_connect) (struct rtl8xxxu_priv *priv,
28                                 u8 macid, bool connect);
29 -       void (*fill_txdesc) (struct ieee80211_hdr *hdr,
30 -                            struct rtl8xxxu_txdesc32 *tx_desc, u32 rate,
31 -                            u16 rate_flag, bool sgi, bool short_preamble,
32 -                            bool ampdu_enable, u32 rts_rate);
33 +       void (*fill_txdesc) (struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
34 +                            struct ieee80211_tx_info *tx_info,
35 +                            struct rtl8xxxu_txdesc32 *tx_desc, bool sgi,
36 +                            bool short_preamble, bool ampdu_enable,
37 +                            u32 rts_rate);
38         int writeN_block_size;
39         int rx_agg_buf_size;
40         char tx_desc_size;
41 @@ -1434,14 +1435,16 @@ int rtl8xxxu_parse_rxdesc24(struct rtl8x
42  int rtl8xxxu_gen2_channel_to_group(int channel);
43  bool rtl8xxxu_gen2_simularity_compare(struct rtl8xxxu_priv *priv,
44                                       int result[][8], int c1, int c2);
45 -void rtl8xxxu_fill_txdesc_v1(struct ieee80211_hdr *hdr,
46 -                            struct rtl8xxxu_txdesc32 *tx_desc, u32 rate,
47 -                            u16 rate_flag, bool sgi, bool short_preamble,
48 -                            bool ampdu_enable, u32 rts_rate);
49 -void rtl8xxxu_fill_txdesc_v2(struct ieee80211_hdr *hdr,
50 -                            struct rtl8xxxu_txdesc32 *tx_desc32, u32 rate,
51 -                            u16 rate_flag, bool sgi, bool short_preamble,
52 -                            bool ampdu_enable, u32 rts_rate);
53 +void rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
54 +                            struct ieee80211_tx_info *tx_info,
55 +                            struct rtl8xxxu_txdesc32 *tx_desc, bool sgi,
56 +                            bool short_preamble, bool ampdu_enable,
57 +                            u32 rts_rate);
58 +void rtl8xxxu_fill_txdesc_v2(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
59 +                            struct ieee80211_tx_info *tx_info,
60 +                            struct rtl8xxxu_txdesc32 *tx_desc32, bool sgi,
61 +                            bool short_preamble, bool ampdu_enable,
62 +                            u32 rts_rate);
63  
64  extern struct rtl8xxxu_fileops rtl8192cu_fops;
65  extern struct rtl8xxxu_fileops rtl8192eu_fops;
66 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
67 +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
68 @@ -4759,13 +4759,28 @@ static void rtl8xxxu_dump_action(struct
69   * This format is used on 8188cu/8192cu/8723au
70   */
71  void
72 -rtl8xxxu_fill_txdesc_v1(struct ieee80211_hdr *hdr,
73 -                       struct rtl8xxxu_txdesc32 *tx_desc, u32 rate,
74 -                       u16 rate_flag, bool sgi, bool short_preamble,
75 -                       bool ampdu_enable, u32 rts_rate)
76 +rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
77 +                       struct ieee80211_tx_info *tx_info,
78 +                       struct rtl8xxxu_txdesc32 *tx_desc, bool sgi,
79 +                       bool short_preamble, bool ampdu_enable, u32 rts_rate)
80  {
81 +       struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info);
82 +       struct rtl8xxxu_priv *priv = hw->priv;
83 +       struct device *dev = &priv->udev->dev;
84 +       u32 rate;
85 +       u16 rate_flags = tx_info->control.rates[0].flags;
86         u16 seq_number;
87  
88 +       if (rate_flags & IEEE80211_TX_RC_MCS &&
89 +           !ieee80211_is_mgmt(hdr->frame_control))
90 +               rate = tx_info->control.rates[0].idx + DESC_RATE_MCS0;
91 +       else
92 +               rate = tx_rate->hw_value;
93 +
94 +       if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
95 +               dev_info(dev, "%s: TX rate: %d, pkt size %d\n",
96 +                        __func__, rate, cpu_to_le16(tx_desc->pkt_size));
97 +
98         seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
99  
100         tx_desc->txdw5 = cpu_to_le32(rate);
101 @@ -4800,10 +4815,10 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211
102          * rts_rate is zero if RTS/CTS or CTS to SELF are not enabled
103          */
104         tx_desc->txdw4 |= cpu_to_le32(rts_rate << TXDESC32_RTS_RATE_SHIFT);
105 -       if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
106 +       if (rate_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
107                 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_RTS_CTS_ENABLE);
108                 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_HW_RTS_ENABLE);
109 -       } else if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
110 +       } else if (rate_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
111                 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_CTS_SELF_ENABLE);
112                 tx_desc->txdw4 |= cpu_to_le32(TXDESC32_HW_RTS_ENABLE);
113         }
114 @@ -4814,16 +4829,31 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211
115   * This format is used on 8192eu/8723bu
116   */
117  void
118 -rtl8xxxu_fill_txdesc_v2(struct ieee80211_hdr *hdr,
119 -                       struct rtl8xxxu_txdesc32 *tx_desc32, u32 rate,
120 -                       u16 rate_flag, bool sgi, bool short_preamble,
121 -                       bool ampdu_enable, u32 rts_rate)
122 +rtl8xxxu_fill_txdesc_v2(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
123 +                       struct ieee80211_tx_info *tx_info,
124 +                       struct rtl8xxxu_txdesc32 *tx_desc32, bool sgi,
125 +                       bool short_preamble, bool ampdu_enable, u32 rts_rate)
126  {
127 +       struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info);
128 +       struct rtl8xxxu_priv *priv = hw->priv;
129 +       struct device *dev = &priv->udev->dev;
130         struct rtl8xxxu_txdesc40 *tx_desc40;
131 +       u32 rate;
132 +       u16 rate_flags = tx_info->control.rates[0].flags;
133         u16 seq_number;
134  
135         tx_desc40 = (struct rtl8xxxu_txdesc40 *)tx_desc32;
136  
137 +       if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
138 +               dev_info(dev, "%s: TX rate: %d, pkt size %d\n",
139 +                        __func__, rate, cpu_to_le16(tx_desc40->pkt_size));
140 +
141 +       if (rate_flags & IEEE80211_TX_RC_MCS &&
142 +           !ieee80211_is_mgmt(hdr->frame_control))
143 +               rate = tx_info->control.rates[0].idx + DESC_RATE_MCS0;
144 +       else
145 +               rate = tx_rate->hw_value;
146 +
147         seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
148  
149         tx_desc40->txdw4 = cpu_to_le32(rate);
150 @@ -4854,10 +4884,10 @@ rtl8xxxu_fill_txdesc_v2(struct ieee80211
151         /*
152          * rts_rate is zero if RTS/CTS or CTS to SELF are not enabled
153          */
154 -       if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
155 +       if (rate_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
156                 tx_desc40->txdw3 |= cpu_to_le32(TXDESC40_RTS_CTS_ENABLE);
157                 tx_desc40->txdw3 |= cpu_to_le32(TXDESC40_HW_RTS_ENABLE);
158 -       } else if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
159 +       } else if (rate_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
160                 /*
161                  * For some reason the vendor driver doesn't set
162                  * TXDESC40_HW_RTS_ENABLE for CTS to SELF
163 @@ -4872,14 +4902,13 @@ static void rtl8xxxu_tx(struct ieee80211
164  {
165         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
166         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
167 -       struct ieee80211_rate *tx_rate = ieee80211_get_tx_rate(hw, tx_info);
168         struct rtl8xxxu_priv *priv = hw->priv;
169         struct rtl8xxxu_txdesc32 *tx_desc;
170         struct rtl8xxxu_tx_urb *tx_urb;
171         struct ieee80211_sta *sta = NULL;
172         struct ieee80211_vif *vif = tx_info->control.vif;
173         struct device *dev = &priv->udev->dev;
174 -       u32 queue, rate, rts_rate;
175 +       u32 queue, rts_rate;
176         u16 pktlen = skb->len;
177         u16 seq_number;
178         u16 rate_flag = tx_info->control.rates[0].flags;
179 @@ -4906,10 +4935,6 @@ static void rtl8xxxu_tx(struct ieee80211
180                 goto error;
181         }
182  
183 -       if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
184 -               dev_info(dev, "%s: TX rate: %d (%d), pkt size %d\n",
185 -                        __func__, tx_rate->bitrate, tx_rate->hw_value, pktlen);
186 -
187         if (ieee80211_is_action(hdr->frame_control))
188                 rtl8xxxu_dump_action(dev, hdr);
189  
190 @@ -4963,12 +4988,6 @@ static void rtl8xxxu_tx(struct ieee80211
191                 }
192         }
193  
194 -       if (rate_flag & IEEE80211_TX_RC_MCS &&
195 -           !ieee80211_is_mgmt(hdr->frame_control))
196 -               rate = tx_info->control.rates[0].idx + DESC_RATE_MCS0;
197 -       else
198 -               rate = tx_rate->hw_value;
199 -
200         if (rate_flag & IEEE80211_TX_RC_SHORT_GI ||
201             (ieee80211_is_data_qos(hdr->frame_control) &&
202              sta && sta->ht_cap.cap &
203 @@ -4988,8 +5007,8 @@ static void rtl8xxxu_tx(struct ieee80211
204  
205         seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
206  
207 -       priv->fops->fill_txdesc(hdr, tx_desc, rate, rate_flag, sgi,
208 -                               short_preamble, ampdu_enable, rts_rate);
209 +       priv->fops->fill_txdesc(hw, hdr, tx_info, tx_desc, sgi, short_preamble,
210 +                               ampdu_enable, rts_rate);
211  
212         rtl8xxxu_calc_tx_desc_csum(tx_desc);
213