Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: generic TX/RX 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 processes the received buffer. |
| 29 | * |
| 30 | * Main responsibility of this function is to parse the RxPD to |
| 31 | * identify the correct interface this packet is headed for and |
| 32 | * forwarding it to the associated handling function, where the |
| 33 | * packet will be further processed and sent to kernel/upper layer |
| 34 | * if required. |
| 35 | */ |
| 36 | int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter, |
| 37 | struct sk_buff *skb) |
| 38 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 39 | struct mwifiex_private *priv = |
| 40 | mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 41 | struct rxpd *local_rx_pd; |
| 42 | struct mwifiex_rxinfo *rx_info = MWIFIEX_SKB_RXCB(skb); |
Ujjal Roy | ca8d6df | 2013-12-02 23:17:53 -0800 | [diff] [blame] | 43 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 44 | |
| 45 | local_rx_pd = (struct rxpd *) (skb->data); |
| 46 | /* Get the BSS number from rxpd, get corresponding priv */ |
| 47 | priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num & |
| 48 | BSS_NUM_MASK, local_rx_pd->bss_type); |
| 49 | if (!priv) |
| 50 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 51 | |
Avinash Patil | f3b369e | 2012-10-19 19:19:21 -0700 | [diff] [blame] | 52 | if (!priv) { |
| 53 | dev_err(adapter->dev, "data: priv not found. Drop RX packet\n"); |
| 54 | dev_kfree_skb_any(skb); |
| 55 | return -1; |
| 56 | } |
| 57 | |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 58 | rx_info->bss_num = priv->bss_num; |
| 59 | rx_info->bss_type = priv->bss_type; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 60 | |
Avinash Patil | 838e4f4 | 2012-08-03 18:06:08 -0700 | [diff] [blame] | 61 | if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) |
Ujjal Roy | ca8d6df | 2013-12-02 23:17:53 -0800 | [diff] [blame] | 62 | ret = mwifiex_process_uap_rx_packet(priv, skb); |
| 63 | else |
| 64 | ret = mwifiex_process_sta_rx_packet(priv, skb); |
Avinash Patil | 838e4f4 | 2012-08-03 18:06:08 -0700 | [diff] [blame] | 65 | |
Ujjal Roy | ca8d6df | 2013-12-02 23:17:53 -0800 | [diff] [blame] | 66 | /* Decrement RX pending counter for each packet */ |
| 67 | if (adapter->if_ops.data_complete) |
| 68 | adapter->if_ops.data_complete(adapter); |
| 69 | |
| 70 | return ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 71 | } |
| 72 | EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet); |
| 73 | |
| 74 | /* |
| 75 | * This function sends a packet to device. |
| 76 | * |
| 77 | * It processes the packet to add the TxPD, checks condition and |
| 78 | * sends the processed packet to firmware for transmission. |
| 79 | * |
| 80 | * On successful completion, the function calls the completion callback |
| 81 | * and logs the time. |
| 82 | */ |
| 83 | int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb, |
| 84 | struct mwifiex_tx_param *tx_param) |
| 85 | { |
| 86 | int ret = -1; |
| 87 | struct mwifiex_adapter *adapter = priv->adapter; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 88 | u8 *head_ptr; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 89 | struct txpd *local_tx_pd = NULL; |
| 90 | |
Avinash Patil | 4ac8764 | 2012-09-10 18:30:49 -0700 | [diff] [blame] | 91 | if (priv->bss_role == MWIFIEX_BSS_ROLE_UAP) |
| 92 | head_ptr = mwifiex_process_uap_txpd(priv, skb); |
| 93 | else |
| 94 | head_ptr = mwifiex_process_sta_txpd(priv, skb); |
| 95 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 96 | if (head_ptr) { |
| 97 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) |
| 98 | local_tx_pd = |
| 99 | (struct txpd *) (head_ptr + INTF_HEADER_LEN); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 100 | if (adapter->iface_type == MWIFIEX_USB) { |
| 101 | adapter->data_sent = true; |
| 102 | skb_pull(skb, INTF_HEADER_LEN); |
| 103 | ret = adapter->if_ops.host_to_card(adapter, |
| 104 | MWIFIEX_USB_EP_DATA, |
| 105 | skb, NULL); |
| 106 | } else { |
| 107 | ret = adapter->if_ops.host_to_card(adapter, |
| 108 | MWIFIEX_TYPE_DATA, |
| 109 | skb, tx_param); |
| 110 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | switch (ret) { |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 114 | case -ENOSR: |
| 115 | dev_err(adapter->dev, "data: -ENOSR is returned\n"); |
| 116 | break; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 117 | case -EBUSY: |
| 118 | if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 119 | (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 120 | priv->adapter->tx_lock_flag = false; |
Yogesh Ashok Powar | 3d82de0 | 2011-10-05 14:58:24 -0700 | [diff] [blame] | 121 | if (local_tx_pd) |
| 122 | local_tx_pd->flags = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 123 | } |
| 124 | dev_dbg(adapter->dev, "data: -EBUSY is returned\n"); |
| 125 | break; |
| 126 | case -1: |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 127 | if (adapter->iface_type != MWIFIEX_PCIE) |
| 128 | adapter->data_sent = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 129 | dev_err(adapter->dev, "mwifiex_write_data_async failed: 0x%X\n", |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 130 | ret); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 131 | adapter->dbg.num_tx_host_to_card_failure++; |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 132 | mwifiex_write_data_complete(adapter, skb, 0, ret); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 133 | break; |
| 134 | case -EINPROGRESS: |
Avinash Patil | e7f767a | 2013-01-03 21:21:32 -0800 | [diff] [blame] | 135 | if (adapter->iface_type != MWIFIEX_PCIE) |
| 136 | adapter->data_sent = false; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 137 | break; |
| 138 | case 0: |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 139 | mwifiex_write_data_complete(adapter, skb, 0, ret); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 140 | break; |
| 141 | default: |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | return ret; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Packet send completion callback handler. |
| 150 | * |
| 151 | * It either frees the buffer directly or forwards it to another |
| 152 | * completion callback which checks conditions, updates statistics, |
| 153 | * wakes up stalled traffic queue if required, and then frees the buffer. |
| 154 | */ |
| 155 | int mwifiex_write_data_complete(struct mwifiex_adapter *adapter, |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 156 | struct sk_buff *skb, int aggr, int status) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 157 | { |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 158 | struct mwifiex_private *priv; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 159 | struct mwifiex_txinfo *tx_info; |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 160 | struct netdev_queue *txq; |
| 161 | int index; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 162 | |
| 163 | if (!skb) |
| 164 | return 0; |
| 165 | |
| 166 | tx_info = MWIFIEX_SKB_TXCB(skb); |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 167 | priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num, |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 168 | tx_info->bss_type); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 169 | if (!priv) |
| 170 | goto done; |
| 171 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 172 | if (adapter->iface_type == MWIFIEX_USB) |
| 173 | adapter->data_sent = false; |
| 174 | |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 175 | mwifiex_set_trans_start(priv->netdev); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 176 | if (!status) { |
| 177 | priv->stats.tx_packets++; |
Ujjal Roy | a1ed484 | 2013-12-02 23:17:55 -0800 | [diff] [blame^] | 178 | priv->stats.tx_bytes += tx_info->pkt_len; |
Ashok Nagarajan | 8908c7d | 2013-03-08 10:58:45 -0800 | [diff] [blame] | 179 | if (priv->tx_timeout_cnt) |
| 180 | priv->tx_timeout_cnt = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 181 | } else { |
| 182 | priv->stats.tx_errors++; |
| 183 | } |
Marc Yang | 62a5b7d | 2011-05-16 19:17:53 -0700 | [diff] [blame] | 184 | |
Avinash Patil | 838e4f4 | 2012-08-03 18:06:08 -0700 | [diff] [blame] | 185 | if (tx_info->flags & MWIFIEX_BUF_FLAG_BRIDGED_PKT) |
| 186 | atomic_dec_return(&adapter->pending_bridged_pkts); |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 187 | |
| 188 | if (aggr) |
| 189 | /* For skb_aggr, do not wake up tx queue */ |
Marc Yang | 62a5b7d | 2011-05-16 19:17:53 -0700 | [diff] [blame] | 190 | goto done; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 191 | |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 192 | atomic_dec(&adapter->tx_pending); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 193 | |
Avinash Patil | 47411a0 | 2012-11-01 18:44:16 -0700 | [diff] [blame] | 194 | index = mwifiex_1d_to_wmm_queue[skb->priority]; |
| 195 | if (atomic_dec_return(&priv->wmm_tx_pending[index]) < LOW_TX_PENDING) { |
| 196 | txq = netdev_get_tx_queue(priv->netdev, index); |
| 197 | if (netif_tx_queue_stopped(txq)) { |
| 198 | netif_tx_wake_queue(txq); |
| 199 | dev_dbg(adapter->dev, "wake queue: %d\n", index); |
| 200 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 201 | } |
| 202 | done: |
| 203 | dev_kfree_skb_any(skb); |
| 204 | |
| 205 | return 0; |
| 206 | } |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 207 | EXPORT_SYMBOL_GPL(mwifiex_write_data_complete); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 208 | |