]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/wireless/libertas/tx.c
libertas: kill internal tx queue for PS mode
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / libertas / tx.c
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"
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 struct lbs_private structure
56  *  @param skb     A pointer to skb which includes TX packet
57  *  @return        0 or -1
58  */
59 static int SendSinglePacket(struct lbs_private *priv, struct sk_buff *skb)
60 {
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->tmptxbuf;
68
69         lbs_deb_enter(LBS_DEB_TX);
70
71         if (priv->surpriseremoved)
72                 return -1;
73
74         if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
75                 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
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
83         plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
84
85         /* offset of actual data */
86         plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
87
88         p802x_hdr = skb->data;
89         if (priv->monitormode != LBS_MONITOR_OFF) {
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) {
97                         /* use new tx_control[4:0] */
98                         plocaltxpd->tx_control = cpu_to_le32(new_rate);
99                 }
100
101                 /* skip the radiotap header */
102                 p802x_hdr += sizeof(struct tx_radiotap_hdr);
103                 plocaltxpd->tx_packet_length =
104                         cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
105                                     - sizeof(struct tx_radiotap_hdr));
106
107         }
108         /* copy destination address from 802.3 or 802.11 header */
109         if (priv->monitormode != LBS_MONITOR_OFF)
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
114         lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
115
116         if (IS_MESH_FRAME(skb)) {
117                 plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
118         }
119
120         memcpy(ptr, plocaltxpd, sizeof(struct txpd));
121
122         ptr += sizeof(struct txpd);
123
124         lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
125         memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
126         ret = priv->hw_host_to_card(priv, MVMS_DAT,
127                                     priv->tmptxbuf,
128                                     le16_to_cpu(plocaltxpd->tx_packet_length) +
129                                     sizeof(struct txpd));
130
131         if (ret) {
132                 lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
133                 goto done;
134         }
135
136         lbs_deb_tx("SendSinglePacket succeeds\n");
137
138 done:
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->monitormode != LBS_MONITOR_OFF) {
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 */
152                 netif_stop_queue(priv->dev);
153                 if (priv->mesh_dev)
154                         netif_stop_queue(priv->mesh_dev);
155
156                 /* Keep the skb around for when we get feedback */
157                 priv->currenttxskb = skb;
158         } else {
159                 dev_kfree_skb_any(skb);
160         }
161
162         lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
163         return ret;
164 }
165
166
167 /**
168  *  @brief This function checks the conditions and sends packet to IF
169  *  layer if everything is ok.
170  *
171  *  @param priv    A pointer to struct lbs_private structure
172  *  @return        n/a
173  */
174 int lbs_process_tx(struct lbs_private *priv, struct sk_buff *skb)
175 {
176         int ret = -1;
177
178         lbs_deb_enter(LBS_DEB_TX);
179         lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
180
181         if (priv->dnld_sent) {
182                 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
183                        priv->dnld_sent);
184                 goto done;
185         }
186
187         if ((priv->psstate == PS_STATE_SLEEP) ||
188             (priv->psstate == PS_STATE_PRE_SLEEP)) {
189                 lbs_pr_alert("TX error: packet xmit in %ssleep mode\n",
190                              priv->psstate == PS_STATE_SLEEP?"":"pre-");
191                 goto done;
192         }
193
194         ret = SendSinglePacket(priv, skb);
195 done:
196         lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
197         return ret;
198 }
199
200 /**
201  *  @brief This function sends to the host the last transmitted packet,
202  *  filling the radiotap headers with transmission information.
203  *
204  *  @param priv     A pointer to struct lbs_private structure
205  *  @param status   A 32 bit value containing transmission status.
206  *
207  *  @returns void
208  */
209 void lbs_send_tx_feedback(struct lbs_private *priv)
210 {
211         struct tx_radiotap_hdr *radiotap_hdr;
212         u32 status = priv->eventcause;
213         int txfail;
214         int try_count;
215
216         if (priv->monitormode == LBS_MONITOR_OFF ||
217             priv->currenttxskb == NULL)
218                 return;
219
220         radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
221
222         txfail = (status >> 24);
223
224 #if 0
225         /* The version of roofnet that we've tested does not use this yet
226          * But it may be used in the future.
227          */
228         if (txfail)
229                 radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
230 #endif
231         try_count = (status >> 16) & 0xff;
232         radiotap_hdr->data_retries = (try_count) ?
233             (1 + priv->txretrycount - try_count) : 0;
234         lbs_upload_rx_packet(priv, priv->currenttxskb);
235         priv->currenttxskb = NULL;
236
237         if (priv->connect_status == LBS_CONNECTED)
238                 netif_wake_queue(priv->dev);
239
240         if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED))
241                 netif_wake_queue(priv->mesh_dev);
242 }
243 EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);