Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: station TX data handling |
| 3 | * |
| 4 | * Copyright (C) 2011, 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 | |
| 27 | /* |
| 28 | * This function fills the TxPD for tx packets. |
| 29 | * |
| 30 | * The Tx buffer received by this function should already have the |
| 31 | * header space allocated for TxPD. |
| 32 | * |
| 33 | * This function inserts the TxPD in between interface header and actual |
| 34 | * data and adjusts the buffer pointers accordingly. |
| 35 | * |
| 36 | * The following TxPD fields are set by this function, as required - |
| 37 | * - BSS number |
| 38 | * - Tx packet length and offset |
| 39 | * - Priority |
| 40 | * - Packet delay |
| 41 | * - Priority specific Tx control |
| 42 | * - Flags |
| 43 | */ |
| 44 | void *mwifiex_process_sta_txpd(struct mwifiex_private *priv, |
| 45 | struct sk_buff *skb) |
| 46 | { |
| 47 | struct mwifiex_adapter *adapter = priv->adapter; |
| 48 | struct txpd *local_tx_pd; |
| 49 | struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb); |
Yogesh Ashok Powar | e156103 | 2011-07-07 17:37:09 -0700 | [diff] [blame] | 50 | u8 pad; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 51 | |
| 52 | if (!skb->len) { |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 53 | dev_err(adapter->dev, "Tx: bad packet length: %d\n", skb->len); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 54 | tx_info->status_code = -1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 55 | return skb->data; |
| 56 | } |
| 57 | |
Yogesh Ashok Powar | e156103 | 2011-07-07 17:37:09 -0700 | [diff] [blame] | 58 | /* If skb->data is not aligned; add padding */ |
| 59 | pad = (4 - (((void *)skb->data - NULL) & 0x3)) % 4; |
| 60 | |
| 61 | BUG_ON(skb_headroom(skb) < (sizeof(*local_tx_pd) + INTF_HEADER_LEN |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 62 | + pad)); |
Yogesh Ashok Powar | e156103 | 2011-07-07 17:37:09 -0700 | [diff] [blame] | 63 | skb_push(skb, sizeof(*local_tx_pd) + pad); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 64 | |
| 65 | local_tx_pd = (struct txpd *) skb->data; |
| 66 | memset(local_tx_pd, 0, sizeof(struct txpd)); |
| 67 | local_tx_pd->bss_num = priv->bss_num; |
| 68 | local_tx_pd->bss_type = priv->bss_type; |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 69 | local_tx_pd->tx_pkt_length = cpu_to_le16((u16)(skb->len - |
| 70 | (sizeof(struct txpd) |
| 71 | + pad))); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 72 | |
| 73 | local_tx_pd->priority = (u8) skb->priority; |
| 74 | local_tx_pd->pkt_delay_2ms = |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 75 | mwifiex_wmm_compute_drv_pkt_delay(priv, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 76 | |
| 77 | if (local_tx_pd->priority < |
| 78 | ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl)) |
| 79 | /* |
| 80 | * Set the priority specific tx_control field, setting of 0 will |
| 81 | * cause the default value to be used later in this function |
| 82 | */ |
| 83 | local_tx_pd->tx_control = |
| 84 | cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd-> |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 85 | priority]); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 86 | |
| 87 | if (adapter->pps_uapsd_mode) { |
| 88 | if (mwifiex_check_last_packet_indication(priv)) { |
| 89 | adapter->tx_lock_flag = true; |
| 90 | local_tx_pd->flags = |
| 91 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /* Offset of actual data */ |
Yogesh Ashok Powar | e156103 | 2011-07-07 17:37:09 -0700 | [diff] [blame] | 96 | local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd) + pad); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 97 | |
| 98 | /* make space for INTF_HEADER_LEN */ |
| 99 | skb_push(skb, INTF_HEADER_LEN); |
| 100 | |
| 101 | if (!local_tx_pd->tx_control) |
| 102 | /* TxCtrl set by user or default */ |
| 103 | local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl); |
| 104 | |
| 105 | return skb->data; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * This function tells firmware to send a NULL data packet. |
| 110 | * |
| 111 | * The function creates a NULL data packet with TxPD and sends to the |
| 112 | * firmware for transmission, with highest priority setting. |
| 113 | */ |
| 114 | int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags) |
| 115 | { |
| 116 | struct mwifiex_adapter *adapter = priv->adapter; |
| 117 | struct txpd *local_tx_pd; |
| 118 | /* sizeof(struct txpd) + Interface specific header */ |
| 119 | #define NULL_PACKET_HDR 64 |
| 120 | u32 data_len = NULL_PACKET_HDR; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 121 | struct sk_buff *skb; |
| 122 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 123 | struct mwifiex_txinfo *tx_info = NULL; |
| 124 | |
| 125 | if (adapter->surprise_removed) |
| 126 | return -1; |
| 127 | |
| 128 | if (!priv->media_connected) |
| 129 | return -1; |
| 130 | |
| 131 | if (adapter->data_sent) |
| 132 | return -1; |
| 133 | |
| 134 | skb = dev_alloc_skb(data_len); |
| 135 | if (!skb) |
| 136 | return -1; |
| 137 | |
| 138 | tx_info = MWIFIEX_SKB_TXCB(skb); |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 139 | tx_info->bss_num = priv->bss_num; |
| 140 | tx_info->bss_type = priv->bss_type; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 141 | skb_reserve(skb, sizeof(struct txpd) + INTF_HEADER_LEN); |
| 142 | skb_push(skb, sizeof(struct txpd)); |
| 143 | |
| 144 | local_tx_pd = (struct txpd *) skb->data; |
| 145 | local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl); |
| 146 | local_tx_pd->flags = flags; |
| 147 | local_tx_pd->priority = WMM_HIGHEST_PRIORITY; |
| 148 | local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd)); |
| 149 | local_tx_pd->bss_num = priv->bss_num; |
| 150 | local_tx_pd->bss_type = priv->bss_type; |
| 151 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 152 | if (adapter->iface_type == MWIFIEX_USB) { |
| 153 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_USB_EP_DATA, |
| 154 | skb, NULL); |
| 155 | } else { |
| 156 | skb_push(skb, INTF_HEADER_LEN); |
| 157 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA, |
| 158 | skb, NULL); |
| 159 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 160 | switch (ret) { |
| 161 | case -EBUSY: |
| 162 | adapter->data_sent = true; |
| 163 | /* Fall through FAILURE handling */ |
| 164 | case -1: |
| 165 | dev_kfree_skb_any(skb); |
| 166 | dev_err(adapter->dev, "%s: host_to_card failed: ret=%d\n", |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 167 | __func__, ret); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 168 | adapter->dbg.num_tx_host_to_card_failure++; |
| 169 | break; |
| 170 | case 0: |
| 171 | dev_kfree_skb_any(skb); |
| 172 | dev_dbg(adapter->dev, "data: %s: host_to_card succeeded\n", |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 173 | __func__); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 174 | adapter->tx_lock_flag = true; |
| 175 | break; |
| 176 | case -EINPROGRESS: |
| 177 | break; |
| 178 | default: |
| 179 | break; |
| 180 | } |
| 181 | |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | * This function checks if we need to send last packet indication. |
| 187 | */ |
| 188 | u8 |
| 189 | mwifiex_check_last_packet_indication(struct mwifiex_private *priv) |
| 190 | { |
| 191 | struct mwifiex_adapter *adapter = priv->adapter; |
| 192 | u8 ret = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 193 | |
| 194 | if (!adapter->sleep_period.period) |
| 195 | return ret; |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 196 | if (mwifiex_wmm_lists_empty(adapter)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 197 | ret = true; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 198 | |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 199 | if (ret && !adapter->cmd_sent && !adapter->curr_cmd && |
| 200 | !is_command_pending(adapter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 201 | adapter->delay_null_pkt = false; |
| 202 | ret = true; |
| 203 | } else { |
| 204 | ret = false; |
| 205 | adapter->delay_null_pkt = true; |
| 206 | } |
| 207 | return ret; |
| 208 | } |