Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
2 | * Marvell Wireless LAN device driver: station TX 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 fills the TxPD for tx packets. | |
29 | * | |
30 | * The Tx buffer received by this function should already have the | |
31 | * header space allocated for TxPD. | |
32 | * | |
33 | * This function inserts the TxPD in between interface header and actual | |
34 | * data and adjusts the buffer pointers accordingly. | |
35 | * | |
36 | * The following TxPD fields are set by this function, as required - | |
37 | * - BSS number | |
38 | * - Tx packet length and offset | |
39 | * - Priority | |
40 | * - Packet delay | |
41 | * - Priority specific Tx control | |
42 | * - Flags | |
43 | */ | |
44 | void *mwifiex_process_sta_txpd(struct mwifiex_private *priv, | |
45 | struct sk_buff *skb) | |
46 | { | |
47 | struct mwifiex_adapter *adapter = priv->adapter; | |
48 | struct txpd *local_tx_pd; | |
49 | struct mwifiex_txinfo *tx_info = MWIFIEX_SKB_TXCB(skb); | |
50 | ||
51 | if (!skb->len) { | |
52 | dev_err(adapter->dev, "Tx: bad packet length: %d\n", | |
53 | skb->len); | |
600f5d90 | 54 | tx_info->status_code = -1; |
5e6e3a92 BZ |
55 | return skb->data; |
56 | } | |
57 | ||
58 | BUG_ON(skb_headroom(skb) < (sizeof(*local_tx_pd) + INTF_HEADER_LEN)); | |
59 | skb_push(skb, sizeof(*local_tx_pd)); | |
60 | ||
61 | local_tx_pd = (struct txpd *) skb->data; | |
62 | memset(local_tx_pd, 0, sizeof(struct txpd)); | |
63 | local_tx_pd->bss_num = priv->bss_num; | |
64 | local_tx_pd->bss_type = priv->bss_type; | |
65 | local_tx_pd->tx_pkt_length = cpu_to_le16((u16) (skb->len - | |
66 | sizeof(struct txpd))); | |
67 | ||
68 | local_tx_pd->priority = (u8) skb->priority; | |
69 | local_tx_pd->pkt_delay_2ms = | |
70 | mwifiex_wmm_compute_drv_pkt_delay(priv, skb); | |
71 | ||
72 | if (local_tx_pd->priority < | |
73 | ARRAY_SIZE(priv->wmm.user_pri_pkt_tx_ctrl)) | |
74 | /* | |
75 | * Set the priority specific tx_control field, setting of 0 will | |
76 | * cause the default value to be used later in this function | |
77 | */ | |
78 | local_tx_pd->tx_control = | |
79 | cpu_to_le32(priv->wmm.user_pri_pkt_tx_ctrl[local_tx_pd-> | |
80 | priority]); | |
81 | ||
82 | if (adapter->pps_uapsd_mode) { | |
83 | if (mwifiex_check_last_packet_indication(priv)) { | |
84 | adapter->tx_lock_flag = true; | |
85 | local_tx_pd->flags = | |
86 | MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET; | |
87 | } | |
88 | } | |
89 | ||
90 | /* Offset of actual data */ | |
91 | local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd)); | |
92 | ||
93 | /* make space for INTF_HEADER_LEN */ | |
94 | skb_push(skb, INTF_HEADER_LEN); | |
95 | ||
96 | if (!local_tx_pd->tx_control) | |
97 | /* TxCtrl set by user or default */ | |
98 | local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl); | |
99 | ||
100 | return skb->data; | |
101 | } | |
102 | ||
103 | /* | |
104 | * This function tells firmware to send a NULL data packet. | |
105 | * | |
106 | * The function creates a NULL data packet with TxPD and sends to the | |
107 | * firmware for transmission, with highest priority setting. | |
108 | */ | |
109 | int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags) | |
110 | { | |
111 | struct mwifiex_adapter *adapter = priv->adapter; | |
112 | struct txpd *local_tx_pd; | |
113 | /* sizeof(struct txpd) + Interface specific header */ | |
114 | #define NULL_PACKET_HDR 64 | |
115 | u32 data_len = NULL_PACKET_HDR; | |
116 | struct sk_buff *skb = NULL; | |
117 | int ret = 0; | |
118 | struct mwifiex_txinfo *tx_info = NULL; | |
119 | ||
120 | if (adapter->surprise_removed) | |
121 | return -1; | |
122 | ||
123 | if (!priv->media_connected) | |
124 | return -1; | |
125 | ||
126 | if (adapter->data_sent) | |
127 | return -1; | |
128 | ||
129 | skb = dev_alloc_skb(data_len); | |
130 | if (!skb) | |
131 | return -1; | |
132 | ||
133 | tx_info = MWIFIEX_SKB_TXCB(skb); | |
134 | tx_info->bss_index = priv->bss_index; | |
135 | skb_reserve(skb, sizeof(struct txpd) + INTF_HEADER_LEN); | |
136 | skb_push(skb, sizeof(struct txpd)); | |
137 | ||
138 | local_tx_pd = (struct txpd *) skb->data; | |
139 | local_tx_pd->tx_control = cpu_to_le32(priv->pkt_tx_ctrl); | |
140 | local_tx_pd->flags = flags; | |
141 | local_tx_pd->priority = WMM_HIGHEST_PRIORITY; | |
142 | local_tx_pd->tx_pkt_offset = cpu_to_le16(sizeof(struct txpd)); | |
143 | local_tx_pd->bss_num = priv->bss_num; | |
144 | local_tx_pd->bss_type = priv->bss_type; | |
145 | ||
146 | skb_push(skb, INTF_HEADER_LEN); | |
147 | ||
148 | ret = adapter->if_ops.host_to_card(adapter, MWIFIEX_TYPE_DATA, | |
149 | skb->data, skb->len, NULL); | |
150 | switch (ret) { | |
151 | case -EBUSY: | |
152 | adapter->data_sent = true; | |
153 | /* Fall through FAILURE handling */ | |
154 | case -1: | |
155 | dev_kfree_skb_any(skb); | |
156 | dev_err(adapter->dev, "%s: host_to_card failed: ret=%d\n", | |
157 | __func__, ret); | |
158 | adapter->dbg.num_tx_host_to_card_failure++; | |
159 | break; | |
160 | case 0: | |
161 | dev_kfree_skb_any(skb); | |
162 | dev_dbg(adapter->dev, "data: %s: host_to_card succeeded\n", | |
163 | __func__); | |
164 | adapter->tx_lock_flag = true; | |
165 | break; | |
166 | case -EINPROGRESS: | |
167 | break; | |
168 | default: | |
169 | break; | |
170 | } | |
171 | ||
172 | return ret; | |
173 | } | |
174 | ||
175 | /* | |
176 | * This function checks if we need to send last packet indication. | |
177 | */ | |
178 | u8 | |
179 | mwifiex_check_last_packet_indication(struct mwifiex_private *priv) | |
180 | { | |
181 | struct mwifiex_adapter *adapter = priv->adapter; | |
182 | u8 ret = false; | |
183 | u8 prop_ps = true; | |
184 | ||
185 | if (!adapter->sleep_period.period) | |
186 | return ret; | |
187 | if (mwifiex_wmm_lists_empty(adapter)) { | |
188 | if ((priv->curr_bss_params.wmm_uapsd_enabled && | |
189 | priv->wmm_qosinfo) || prop_ps) | |
190 | ret = true; | |
191 | } | |
192 | ||
193 | if (ret && !adapter->cmd_sent && !adapter->curr_cmd | |
194 | && !is_command_pending(adapter)) { | |
195 | adapter->delay_null_pkt = false; | |
196 | ret = true; | |
197 | } else { | |
198 | ret = false; | |
199 | adapter->delay_null_pkt = true; | |
200 | } | |
201 | return ret; | |
202 | } |