linux/drivers/net/wireless/marvell/mwifiex/11n_aggr.c
<<
>>
Prefs
   1/*
   2 * Marvell Wireless LAN device driver: 802.11n Aggregation
   3 *
   4 * Copyright (C) 2011-2014, Marvell International Ltd.
   5 *
   6 * This software file (the "File") is distributed by Marvell International
   7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
   8 * (the "License").  You may use, redistribute and/or modify this File in
   9 * accordance with the terms and conditions of the License, a copy of which
  10 * is available by writing to the Free Software Foundation, Inc.,
  11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13 *
  14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16 * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
  17 * this warranty disclaimer.
  18 */
  19
  20#include "decl.h"
  21#include "ioctl.h"
  22#include "util.h"
  23#include "fw.h"
  24#include "main.h"
  25#include "wmm.h"
  26#include "11n.h"
  27#include "11n_aggr.h"
  28
  29/*
  30 * Creates an AMSDU subframe for aggregation into one AMSDU packet.
  31 *
  32 * The resultant AMSDU subframe format is -
  33 *
  34 * +---- ~ -----+---- ~ ------+---- ~ -----+----- ~ -----+---- ~ -----+
  35 * |     DA     |     SA      |   Length   | SNAP header |   MSDU     |
  36 * | data[0..5] | data[6..11] |            |             | data[14..] |
  37 * +---- ~ -----+---- ~ ------+---- ~ -----+----- ~ -----+---- ~ -----+
  38 * <--6-bytes--> <--6-bytes--> <--2-bytes--><--8-bytes--> <--n-bytes-->
  39 *
  40 * This function also computes the amount of padding required to make the
  41 * buffer length multiple of 4 bytes.
  42 *
  43 * Data => |DA|SA|SNAP-TYPE|........    .|
  44 * MSDU => |DA|SA|Length|SNAP|......   ..|
  45 */
  46static int
  47mwifiex_11n_form_amsdu_pkt(struct sk_buff *skb_aggr,
  48                           struct sk_buff *skb_src, int *pad)
  49
  50{
  51        int dt_offset;
  52        struct rfc_1042_hdr snap = {
  53                0xaa,           /* LLC DSAP */
  54                0xaa,           /* LLC SSAP */
  55                0x03,           /* LLC CTRL */
  56                {0x00, 0x00, 0x00},     /* SNAP OUI */
  57                0x0000          /* SNAP type */
  58                        /*
  59                         * This field will be overwritten
  60                         * later with ethertype
  61                         */
  62        };
  63        struct tx_packet_hdr *tx_header;
  64
  65        tx_header = (void *)skb_put(skb_aggr, sizeof(*tx_header));
  66
  67        /* Copy DA and SA */
  68        dt_offset = 2 * ETH_ALEN;
  69        memcpy(&tx_header->eth803_hdr, skb_src->data, dt_offset);
  70
  71        /* Copy SNAP header */
  72        snap.snap_type = ((struct ethhdr *)skb_src->data)->h_proto;
  73
  74        dt_offset += sizeof(__be16);
  75
  76        memcpy(&tx_header->rfc1042_hdr, &snap, sizeof(struct rfc_1042_hdr));
  77
  78        skb_pull(skb_src, dt_offset);
  79
  80        /* Update Length field */
  81        tx_header->eth803_hdr.h_proto = htons(skb_src->len + LLC_SNAP_LEN);
  82
  83        /* Add payload */
  84        memcpy(skb_put(skb_aggr, skb_src->len), skb_src->data, skb_src->len);
  85
  86        /* Add padding for new MSDU to start from 4 byte boundary */
  87        *pad = (4 - ((unsigned long)skb_aggr->tail & 0x3)) % 4;
  88
  89        return skb_aggr->len + *pad;
  90}
  91
  92/*
  93 * Adds TxPD to AMSDU header.
  94 *
  95 * Each AMSDU packet will contain one TxPD at the beginning,
  96 * followed by multiple AMSDU subframes.
  97 */
  98static void
  99mwifiex_11n_form_amsdu_txpd(struct mwifiex_private *priv,
 100                            struct sk_buff *skb)
 101{
 102        struct txpd *local_tx_pd;
 103        struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb);
 104        unsigned int pad;
 105        int headroom = (priv->adapter->iface_type ==
 106                        MWIFIEX_USB) ? 0 : INTF_HEADER_LEN;
 107
 108        pad = ((void *)skb->data - sizeof(*local_tx_pd) -
 109                headroom - NULL) & (MWIFIEX_DMA_ALIGN_SZ - 1);
 110        skb_push(skb, pad);
 111
 112        skb_push(skb, sizeof(*local_tx_pd));
 113
 114        local_tx_pd = (struct txpd *) skb->data;
 115        memset(local_tx_pd, 0, sizeof(struct txpd));
 116
 117        /* Original priority has been overwritten */
 118        local_tx_pd->priority = (u8) skb->priority;
 119        local_tx_pd->pkt_delay_2ms =
 120                mwifiex_wmm_compute_drv_pkt_delay(priv, skb);
 121        local_tx_pd->bss_num = priv->bss_num;
 122        local_tx_pd->bss_type = priv->bss_type;
 123        /* Always zero as the data is followed by struct txpd */
 124        local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd) +
 125                                                 pad);
 126        local_tx_pd->tx_pkt_type = cpu_to_le16(PKT_TYPE_AMSDU);
 127        local_tx_pd->tx_pkt_length = cpu_to_le16(skb->len -
 128                                                 sizeof(*local_tx_pd) -
 129                                                 pad);
 130
 131        if (tx_info->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
 132                local_tx_pd->flags |= MWIFIEX_TXPD_FLAGS_TDLS_PACKET;
 133
 134        if (local_tx_pd->tx_control == 0)
 135                /* TxCtrl set by user or default */
 136                local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl);
 137
 138        if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
 139            priv->adapter->pps_uapsd_mode) {
 140                if (true == mwifiex_check_last_packet_indication(priv)) {
 141                        priv->adapter->tx_lock_flag = true;
 142                        local_tx_pd->flags =
 143                                MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET;
 144                }
 145        }
 146}
 147
 148/*
 149 * Create aggregated packet.
 150 *
 151 * This function creates an aggregated MSDU packet, by combining buffers
 152 * from the RA list. Each individual buffer is encapsulated as an AMSDU
 153 * subframe and all such subframes are concatenated together to form the
 154 * AMSDU packet.
 155 *
 156 * A TxPD is also added to the front of the resultant AMSDU packets for
 157 * transmission. The resultant packets format is -
 158 *
 159 * +---- ~ ----+------ ~ ------+------ ~ ------+-..-+------ ~ ------+
 160 * |    TxPD   |AMSDU sub-frame|AMSDU sub-frame| .. |AMSDU sub-frame|
 161 * |           |       1       |       2       | .. |       n       |
 162 * +---- ~ ----+------ ~ ------+------ ~ ------+ .. +------ ~ ------+
 163 */
 164int
 165mwifiex_11n_aggregate_pkt(struct mwifiex_private *priv,
 166                          struct mwifiex_ra_list_tbl *pra_list,
 167                          int ptrindex, unsigned long ra_list_flags)
 168                          __releases(&priv->wmm.ra_list_spinlock)
 169{
 170        struct mwifiex_adapter *adapter = priv->adapter;
 171        struct sk_buff *skb_aggr, *skb_src;
 172        struct mwifiex_txinfo *tx_info_aggr, *tx_info_src;
 173        int pad = 0, aggr_num = 0, ret;
 174        struct mwifiex_tx_param tx_param;
 175        struct txpd *ptx_pd = NULL;
 176        int headroom = adapter->iface_type == MWIFIEX_USB ? 0 : INTF_HEADER_LEN;
 177
 178        skb_src = skb_peek(&pra_list->skb_head);
 179        if (!skb_src) {
 180                spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
 181                                       ra_list_flags);
 182                return 0;
 183        }
 184
 185        tx_info_src = MWIFIEX_SKB_TXCB(skb_src);
 186        skb_aggr = mwifiex_alloc_dma_align_buf(adapter->tx_buf_size,
 187                                               GFP_ATOMIC);
 188        if (!skb_aggr) {
 189                spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
 190                                       ra_list_flags);
 191                return -1;
 192        }
 193        skb_reserve(skb_aggr, MWIFIEX_MIN_DATA_HEADER_LEN);
 194        tx_info_aggr =  MWIFIEX_SKB_TXCB(skb_aggr);
 195
 196        memset(tx_info_aggr, 0, sizeof(*tx_info_aggr));
 197        tx_info_aggr->bss_type = tx_info_src->bss_type;
 198        tx_info_aggr->bss_num = tx_info_src->bss_num;
 199
 200        if (tx_info_src->flags & MWIFIEX_BUF_FLAG_TDLS_PKT)
 201                tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
 202        tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_AGGR_PKT;
 203        skb_aggr->priority = skb_src->priority;
 204        skb_aggr->tstamp = skb_src->tstamp;
 205
 206        do {
 207                /* Check if AMSDU can accommodate this MSDU */
 208                if ((skb_aggr->len + skb_src->len + LLC_SNAP_LEN) >
 209                    adapter->tx_buf_size)
 210                        break;
 211
 212                skb_src = skb_dequeue(&pra_list->skb_head);
 213                pra_list->total_pkt_count--;
 214                atomic_dec(&priv->wmm.tx_pkts_queued);
 215                aggr_num++;
 216                spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
 217                                       ra_list_flags);
 218                mwifiex_11n_form_amsdu_pkt(skb_aggr, skb_src, &pad);
 219
 220                mwifiex_write_data_complete(adapter, skb_src, 0, 0);
 221
 222                spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
 223
 224                if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
 225                        spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
 226                                               ra_list_flags);
 227                        return -1;
 228                }
 229
 230                if (skb_tailroom(skb_aggr) < pad) {
 231                        pad = 0;
 232                        break;
 233                }
 234                skb_put(skb_aggr, pad);
 235
 236                skb_src = skb_peek(&pra_list->skb_head);
 237
 238        } while (skb_src);
 239
 240        spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, ra_list_flags);
 241
 242        /* Last AMSDU packet does not need padding */
 243        skb_trim(skb_aggr, skb_aggr->len - pad);
 244
 245        /* Form AMSDU */
 246        mwifiex_11n_form_amsdu_txpd(priv, skb_aggr);
 247        if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA)
 248                ptx_pd = (struct txpd *)skb_aggr->data;
 249
 250        skb_push(skb_aggr, headroom);
 251        tx_info_aggr->aggr_num = aggr_num * 2;
 252        if (adapter->data_sent || adapter->tx_lock_flag) {
 253                atomic_add(aggr_num * 2, &adapter->tx_queued);
 254                skb_queue_tail(&adapter->tx_data_q, skb_aggr);
 255                return 0;
 256        }
 257
 258        if (adapter->iface_type == MWIFIEX_USB) {
 259                ret = adapter->if_ops.host_to_card(adapter, priv->usb_port,
 260                                                   skb_aggr, NULL);
 261        } else {
 262                if (skb_src)
 263                        tx_param.next_pkt_len =
 264                                        skb_src->len + sizeof(struct txpd);
 265                else
 266                        tx_param.next_pkt_len = 0;
 267
 268                ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA,
 269                                                   skb_aggr, &tx_param);
 270        }
 271        switch (ret) {
 272        case -EBUSY:
 273                spin_lock_irqsave(&priv->wmm.ra_list_spinlock, ra_list_flags);
 274                if (!mwifiex_is_ralist_valid(priv, pra_list, ptrindex)) {
 275                        spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
 276                                               ra_list_flags);
 277                        mwifiex_write_data_complete(adapter, skb_aggr, 1, -1);
 278                        return -1;
 279                }
 280                if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
 281                    adapter->pps_uapsd_mode && adapter->tx_lock_flag) {
 282                                priv->adapter->tx_lock_flag = false;
 283                                if (ptx_pd)
 284                                        ptx_pd->flags = 0;
 285                }
 286
 287                skb_queue_tail(&pra_list->skb_head, skb_aggr);
 288
 289                pra_list->total_pkt_count++;
 290
 291                atomic_inc(&priv->wmm.tx_pkts_queued);
 292
 293                tx_info_aggr->flags |= MWIFIEX_BUF_FLAG_REQUEUED_PKT;
 294                spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
 295                                       ra_list_flags);
 296                mwifiex_dbg(adapter, ERROR, "data: -EBUSY is returned\n");
 297                break;
 298        case -1:
 299                mwifiex_dbg(adapter, ERROR, "%s: host_to_card failed: %#x\n",
 300                            __func__, ret);
 301                adapter->dbg.num_tx_host_to_card_failure++;
 302                mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
 303                return 0;
 304        case -EINPROGRESS:
 305                break;
 306        case 0:
 307                mwifiex_write_data_complete(adapter, skb_aggr, 1, ret);
 308                break;
 309        default:
 310                break;
 311        }
 312        if (ret != -EBUSY) {
 313                mwifiex_rotate_priolists(priv, pra_list, ptrindex);
 314        }
 315
 316        return 0;
 317}
 318