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