Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /** |
| 2 | * This file contains the handling of TX in wlan driver. |
| 3 | */ |
| 4 | #include <linux/netdevice.h> |
| 5 | |
| 6 | #include "hostcmd.h" |
| 7 | #include "radiotap.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 8 | #include "decl.h" |
| 9 | #include "defs.h" |
| 10 | #include "dev.h" |
| 11 | #include "wext.h" |
| 12 | |
| 13 | /** |
| 14 | * @brief This function converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE |
| 15 | * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1) |
| 16 | * |
| 17 | * @param rate Input rate |
| 18 | * @return Output Rate (0 if invalid) |
| 19 | */ |
| 20 | static u32 convert_radiotap_rate_to_mv(u8 rate) |
| 21 | { |
| 22 | switch (rate) { |
| 23 | case 2: /* 1 Mbps */ |
| 24 | return 0 | (1 << 4); |
| 25 | case 4: /* 2 Mbps */ |
| 26 | return 1 | (1 << 4); |
| 27 | case 11: /* 5.5 Mbps */ |
| 28 | return 2 | (1 << 4); |
| 29 | case 22: /* 11 Mbps */ |
| 30 | return 3 | (1 << 4); |
| 31 | case 12: /* 6 Mbps */ |
| 32 | return 4 | (1 << 4); |
| 33 | case 18: /* 9 Mbps */ |
| 34 | return 5 | (1 << 4); |
| 35 | case 24: /* 12 Mbps */ |
| 36 | return 6 | (1 << 4); |
| 37 | case 36: /* 18 Mbps */ |
| 38 | return 7 | (1 << 4); |
| 39 | case 48: /* 24 Mbps */ |
| 40 | return 8 | (1 << 4); |
| 41 | case 72: /* 36 Mbps */ |
| 42 | return 9 | (1 << 4); |
| 43 | case 96: /* 48 Mbps */ |
| 44 | return 10 | (1 << 4); |
| 45 | case 108: /* 54 Mbps */ |
| 46 | return 11 | (1 << 4); |
| 47 | } |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @brief This function processes a single packet and sends |
| 53 | * to IF layer |
| 54 | * |
| 55 | * @param priv A pointer to wlan_private structure |
| 56 | * @param skb A pointer to skb which includes TX packet |
| 57 | * @return 0 or -1 |
| 58 | */ |
| 59 | static int SendSinglePacket(wlan_private * priv, struct sk_buff *skb) |
| 60 | { |
| 61 | wlan_adapter *adapter = priv->adapter; |
| 62 | int ret = 0; |
| 63 | struct txpd localtxpd; |
| 64 | struct txpd *plocaltxpd = &localtxpd; |
| 65 | u8 *p802x_hdr; |
| 66 | struct tx_radiotap_hdr *pradiotap_hdr; |
| 67 | u32 new_rate; |
| 68 | u8 *ptr = priv->adapter->tmptxbuf; |
| 69 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 70 | lbs_deb_enter(LBS_DEB_TX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 71 | |
| 72 | if (priv->adapter->surpriseremoved) |
| 73 | return -1; |
| 74 | |
| 75 | if ((priv->adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0) |
| 76 | lbs_dbg_hex("TX packet: ", skb->data, |
| 77 | min_t(unsigned int, skb->len, 100)); |
| 78 | |
| 79 | if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 80 | lbs_deb_tx("tx err: skb length %d 0 or > %zd\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 81 | skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE); |
| 82 | ret = -1; |
| 83 | goto done; |
| 84 | } |
| 85 | |
| 86 | memset(plocaltxpd, 0, sizeof(struct txpd)); |
| 87 | |
| 88 | plocaltxpd->tx_packet_length = skb->len; |
| 89 | |
| 90 | /* offset of actual data */ |
| 91 | plocaltxpd->tx_packet_location = sizeof(struct txpd); |
| 92 | |
| 93 | /* TxCtrl set by user or default */ |
| 94 | plocaltxpd->tx_control = adapter->pkttxctrl; |
| 95 | |
| 96 | p802x_hdr = skb->data; |
| 97 | if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) { |
| 98 | |
| 99 | /* locate radiotap header */ |
| 100 | pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data; |
| 101 | |
| 102 | /* set txpd fields from the radiotap header */ |
| 103 | new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate); |
| 104 | if (new_rate != 0) { |
| 105 | /* erase tx_control[4:0] */ |
| 106 | plocaltxpd->tx_control &= ~0x1f; |
| 107 | /* write new tx_control[4:0] */ |
| 108 | plocaltxpd->tx_control |= new_rate; |
| 109 | } |
| 110 | |
| 111 | /* skip the radiotap header */ |
| 112 | p802x_hdr += sizeof(struct tx_radiotap_hdr); |
| 113 | plocaltxpd->tx_packet_length -= sizeof(struct tx_radiotap_hdr); |
| 114 | |
| 115 | } |
| 116 | /* copy destination address from 802.3 or 802.11 header */ |
| 117 | if (priv->adapter->linkmode == WLAN_LINKMODE_802_11) |
| 118 | memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN); |
| 119 | else |
| 120 | memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN); |
| 121 | |
| 122 | lbs_dbg_hex("txpd", (u8 *) plocaltxpd, sizeof(struct txpd)); |
| 123 | |
| 124 | if (IS_MESH_FRAME(skb)) { |
| 125 | plocaltxpd->tx_control |= TxPD_MESH_FRAME; |
| 126 | } |
| 127 | |
| 128 | memcpy(ptr, plocaltxpd, sizeof(struct txpd)); |
| 129 | |
| 130 | ptr += sizeof(struct txpd); |
| 131 | |
| 132 | lbs_dbg_hex("Tx Data", (u8 *) p802x_hdr, plocaltxpd->tx_packet_length); |
| 133 | memcpy(ptr, p802x_hdr, plocaltxpd->tx_packet_length); |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 134 | ret = priv->hw_host_to_card(priv, MVMS_DAT, |
| 135 | priv->adapter->tmptxbuf, |
| 136 | plocaltxpd->tx_packet_length + |
| 137 | sizeof(struct txpd)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 138 | |
| 139 | if (ret) { |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 140 | lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 141 | goto done; |
| 142 | } |
| 143 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 144 | lbs_deb_tx("SendSinglePacket succeeds\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 145 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 146 | done: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 147 | if (!ret) { |
| 148 | priv->stats.tx_packets++; |
| 149 | priv->stats.tx_bytes += skb->len; |
| 150 | } else { |
| 151 | priv->stats.tx_dropped++; |
| 152 | priv->stats.tx_errors++; |
| 153 | } |
| 154 | |
| 155 | if (!ret && priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) { |
| 156 | /* Keep the skb to echo it back once Tx feedback is |
| 157 | received from FW */ |
| 158 | skb_orphan(skb); |
| 159 | /* stop processing outgoing pkts */ |
| 160 | netif_stop_queue(priv->wlan_dev.netdev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 161 | netif_stop_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 162 | /* freeze any packets already in our queues */ |
| 163 | priv->adapter->TxLockFlag = 1; |
| 164 | } else { |
| 165 | dev_kfree_skb_any(skb); |
| 166 | priv->adapter->currenttxskb = NULL; |
| 167 | } |
| 168 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 169 | lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | void libertas_tx_runqueue(wlan_private *priv) |
| 175 | { |
| 176 | wlan_adapter *adapter = priv->adapter; |
| 177 | int i; |
| 178 | |
| 179 | spin_lock(&adapter->txqueue_lock); |
| 180 | for (i = 0; i < adapter->tx_queue_idx; i++) { |
| 181 | struct sk_buff *skb = adapter->tx_queue_ps[i]; |
| 182 | spin_unlock(&adapter->txqueue_lock); |
| 183 | SendSinglePacket(priv, skb); |
| 184 | spin_lock(&adapter->txqueue_lock); |
| 185 | } |
| 186 | adapter->tx_queue_idx = 0; |
| 187 | spin_unlock(&adapter->txqueue_lock); |
| 188 | } |
| 189 | |
| 190 | static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb) |
| 191 | { |
| 192 | wlan_adapter *adapter = priv->adapter; |
| 193 | |
| 194 | spin_lock(&adapter->txqueue_lock); |
| 195 | |
| 196 | WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE); |
| 197 | adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb; |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 198 | if (adapter->tx_queue_idx == NR_TX_QUEUE) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 199 | netif_stop_queue(priv->wlan_dev.netdev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 200 | netif_stop_queue(priv->mesh_dev); |
| 201 | } else { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 202 | netif_start_queue(priv->wlan_dev.netdev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 203 | netif_start_queue(priv->mesh_dev); |
| 204 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 205 | |
| 206 | spin_unlock(&adapter->txqueue_lock); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * @brief This function checks the conditions and sends packet to IF |
| 211 | * layer if everything is ok. |
| 212 | * |
| 213 | * @param priv A pointer to wlan_private structure |
| 214 | * @return n/a |
| 215 | */ |
| 216 | int libertas_process_tx(wlan_private * priv, struct sk_buff *skb) |
| 217 | { |
| 218 | int ret = -1; |
| 219 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 220 | lbs_deb_enter(LBS_DEB_TX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 221 | lbs_dbg_hex("TX Data", skb->data, min_t(unsigned int, skb->len, 100)); |
| 222 | |
| 223 | if (priv->wlan_dev.dnld_sent) { |
| 224 | lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n", |
| 225 | priv->wlan_dev.dnld_sent); |
| 226 | goto done; |
| 227 | } |
| 228 | |
| 229 | if ((priv->adapter->psstate == PS_STATE_SLEEP) || |
| 230 | (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) { |
| 231 | wlan_tx_queue(priv, skb); |
| 232 | return ret; |
| 233 | } |
| 234 | |
| 235 | priv->adapter->currenttxskb = skb; |
| 236 | |
| 237 | ret = SendSinglePacket(priv, skb); |
| 238 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 239 | lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 240 | return ret; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * @brief This function sends to the host the last transmitted packet, |
| 245 | * filling the radiotap headers with transmission information. |
| 246 | * |
| 247 | * @param priv A pointer to wlan_private structure |
| 248 | * @param status A 32 bit value containing transmission status. |
| 249 | * |
| 250 | * @returns void |
| 251 | */ |
| 252 | void libertas_send_tx_feedback(wlan_private * priv) |
| 253 | { |
| 254 | wlan_adapter *adapter = priv->adapter; |
| 255 | struct tx_radiotap_hdr *radiotap_hdr; |
| 256 | u32 status = adapter->eventcause; |
| 257 | int txfail; |
| 258 | int try_count; |
| 259 | |
| 260 | if (adapter->radiomode != WLAN_RADIOMODE_RADIOTAP || |
| 261 | adapter->currenttxskb == NULL) |
| 262 | return; |
| 263 | |
| 264 | radiotap_hdr = (struct tx_radiotap_hdr *)adapter->currenttxskb->data; |
| 265 | |
| 266 | if ((adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0) |
| 267 | lbs_dbg_hex("TX feedback: ", (u8 *) radiotap_hdr, |
| 268 | min_t(unsigned int, adapter->currenttxskb->len, 100)); |
| 269 | |
| 270 | txfail = (status >> 24); |
| 271 | |
| 272 | #if 0 |
| 273 | /* The version of roofnet that we've tested does not use this yet |
| 274 | * But it may be used in the future. |
| 275 | */ |
| 276 | if (txfail) |
| 277 | radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL; |
| 278 | #endif |
| 279 | try_count = (status >> 16) & 0xff; |
| 280 | radiotap_hdr->data_retries = (try_count) ? |
| 281 | (1 + adapter->txretrycount - try_count) : 0; |
| 282 | libertas_upload_rx_packet(priv, adapter->currenttxskb); |
| 283 | adapter->currenttxskb = NULL; |
| 284 | priv->adapter->TxLockFlag = 0; |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 285 | if (priv->adapter->connect_status == libertas_connected) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 286 | netif_wake_queue(priv->wlan_dev.netdev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 287 | netif_wake_queue(priv->mesh_dev); |
| 288 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 289 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 290 | EXPORT_SYMBOL_GPL(libertas_send_tx_feedback); |