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); |
| 43 | |
| 44 | local_rx_pd = (struct rxpd *) (skb->data); |
| 45 | /* Get the BSS number from rxpd, get corresponding priv */ |
| 46 | priv = mwifiex_get_priv_by_id(adapter, local_rx_pd->bss_num & |
| 47 | BSS_NUM_MASK, local_rx_pd->bss_type); |
| 48 | if (!priv) |
| 49 | priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); |
| 50 | |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 51 | rx_info->bss_num = priv->bss_num; |
| 52 | rx_info->bss_type = priv->bss_type; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 53 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 54 | return mwifiex_process_sta_rx_packet(adapter, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 55 | } |
| 56 | EXPORT_SYMBOL_GPL(mwifiex_handle_rx_packet); |
| 57 | |
| 58 | /* |
| 59 | * This function sends a packet to device. |
| 60 | * |
| 61 | * It processes the packet to add the TxPD, checks condition and |
| 62 | * sends the processed packet to firmware for transmission. |
| 63 | * |
| 64 | * On successful completion, the function calls the completion callback |
| 65 | * and logs the time. |
| 66 | */ |
| 67 | int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb, |
| 68 | struct mwifiex_tx_param *tx_param) |
| 69 | { |
| 70 | int ret = -1; |
| 71 | struct mwifiex_adapter *adapter = priv->adapter; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 72 | u8 *head_ptr; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 73 | struct txpd *local_tx_pd = NULL; |
| 74 | |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 75 | head_ptr = mwifiex_process_sta_txpd(priv, skb); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 76 | if (head_ptr) { |
| 77 | if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) |
| 78 | local_tx_pd = |
| 79 | (struct txpd *) (head_ptr + INTF_HEADER_LEN); |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 80 | if (adapter->iface_type == MWIFIEX_USB) { |
| 81 | adapter->data_sent = true; |
| 82 | skb_pull(skb, INTF_HEADER_LEN); |
| 83 | ret = adapter->if_ops.host_to_card(adapter, |
| 84 | MWIFIEX_USB_EP_DATA, |
| 85 | skb, NULL); |
| 86 | } else { |
| 87 | ret = adapter->if_ops.host_to_card(adapter, |
| 88 | MWIFIEX_TYPE_DATA, |
| 89 | skb, tx_param); |
| 90 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | switch (ret) { |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 94 | case -ENOSR: |
| 95 | dev_err(adapter->dev, "data: -ENOSR is returned\n"); |
| 96 | break; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 97 | case -EBUSY: |
| 98 | if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 99 | (adapter->pps_uapsd_mode) && (adapter->tx_lock_flag)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 100 | priv->adapter->tx_lock_flag = false; |
Yogesh Ashok Powar | 3d82de0 | 2011-10-05 14:58:24 -0700 | [diff] [blame] | 101 | if (local_tx_pd) |
| 102 | local_tx_pd->flags = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 103 | } |
| 104 | dev_dbg(adapter->dev, "data: -EBUSY is returned\n"); |
| 105 | break; |
| 106 | case -1: |
| 107 | adapter->data_sent = false; |
| 108 | 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] | 109 | ret); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 110 | adapter->dbg.num_tx_host_to_card_failure++; |
| 111 | mwifiex_write_data_complete(adapter, skb, ret); |
| 112 | break; |
| 113 | case -EINPROGRESS: |
| 114 | adapter->data_sent = false; |
| 115 | break; |
| 116 | case 0: |
| 117 | mwifiex_write_data_complete(adapter, skb, ret); |
| 118 | break; |
| 119 | default: |
| 120 | break; |
| 121 | } |
| 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Packet send completion callback handler. |
| 128 | * |
| 129 | * It either frees the buffer directly or forwards it to another |
| 130 | * completion callback which checks conditions, updates statistics, |
| 131 | * wakes up stalled traffic queue if required, and then frees the buffer. |
| 132 | */ |
| 133 | int mwifiex_write_data_complete(struct mwifiex_adapter *adapter, |
| 134 | struct sk_buff *skb, int status) |
| 135 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 136 | struct mwifiex_private *priv, *tpriv; |
| 137 | struct mwifiex_txinfo *tx_info; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 138 | int i; |
| 139 | |
| 140 | if (!skb) |
| 141 | return 0; |
| 142 | |
| 143 | tx_info = MWIFIEX_SKB_TXCB(skb); |
Yogesh Ashok Powar | 9da9a3b | 2012-01-11 20:06:11 -0800 | [diff] [blame] | 144 | priv = mwifiex_get_priv_by_id(adapter, tx_info->bss_num, |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 145 | tx_info->bss_type); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 146 | if (!priv) |
| 147 | goto done; |
| 148 | |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 149 | if (adapter->iface_type == MWIFIEX_USB) |
| 150 | adapter->data_sent = false; |
| 151 | |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 152 | mwifiex_set_trans_start(priv->netdev); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 153 | if (!status) { |
| 154 | priv->stats.tx_packets++; |
| 155 | priv->stats.tx_bytes += skb->len; |
| 156 | } else { |
| 157 | priv->stats.tx_errors++; |
| 158 | } |
Marc Yang | 62a5b7d | 2011-05-16 19:17:53 -0700 | [diff] [blame] | 159 | |
| 160 | if (atomic_dec_return(&adapter->tx_pending) >= LOW_TX_PENDING) |
| 161 | goto done; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 162 | |
| 163 | for (i = 0; i < adapter->priv_num; i++) { |
| 164 | |
| 165 | tpriv = adapter->priv[i]; |
| 166 | |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 167 | if ((GET_BSS_ROLE(tpriv) == MWIFIEX_BSS_ROLE_STA) && |
| 168 | (tpriv->media_connected)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 169 | if (netif_queue_stopped(tpriv->netdev)) |
Avinash Patil | bbea3bc | 2011-12-08 20:41:05 -0800 | [diff] [blame] | 170 | mwifiex_wake_up_net_dev_queue(tpriv->netdev, |
Yogesh Ashok Powar | c65a30f | 2012-03-13 19:22:42 -0700 | [diff] [blame] | 171 | adapter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | done: |
| 175 | dev_kfree_skb_any(skb); |
| 176 | |
| 177 | return 0; |
| 178 | } |
Amitkumar Karwar | 4daffe3 | 2012-04-18 20:08:28 -0700 | [diff] [blame] | 179 | EXPORT_SYMBOL_GPL(mwifiex_write_data_complete); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 180 | |