2 * Marvell Wireless LAN device driver: station TX data handling
4 * Copyright (C) 2011, Marvell International Ltd.
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.
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.
28 * This function fills the TxPD for tx packets.
30 * The Tx buffer received by this function should already have the
31 * header space allocated for TxPD.
33 * This function inserts the TxPD in between interface header and actual
34 * data and adjusts the buffer pointers accordingly.
36 * The following TxPD fields are set by this function, as required -
38 * - Tx packet length and offset
41 * - Priority specific Tx control
44 void *mwifiex_process_sta_txpd(struct mwifiex_private
*priv
,
47 struct mwifiex_adapter
*adapter
= priv
->adapter
;
48 struct txpd
*local_tx_pd
;
49 struct mwifiex_txinfo
*tx_info
= MWIFIEX_SKB_TXCB(skb
);
51 u16 pkt_type
, pkt_offset
;
54 dev_err(adapter
->dev
, "Tx: bad packet length: %d\n", skb
->len
);
55 tx_info
->status_code
= -1;
59 pkt_type
= mwifiex_is_skb_mgmt_frame(skb
) ? PKT_TYPE_MGMT
: 0;
61 /* If skb->data is not aligned; add padding */
62 pad
= (4 - (((void *)skb
->data
- NULL
) & 0x3)) % 4;
64 BUG_ON(skb_headroom(skb
) < (sizeof(*local_tx_pd
) + INTF_HEADER_LEN
66 skb_push(skb
, sizeof(*local_tx_pd
) + pad
);
68 local_tx_pd
= (struct txpd
*) skb
->data
;
69 memset(local_tx_pd
, 0, sizeof(struct txpd
));
70 local_tx_pd
->bss_num
= priv
->bss_num
;
71 local_tx_pd
->bss_type
= priv
->bss_type
;
72 local_tx_pd
->tx_pkt_length
= cpu_to_le16((u16
)(skb
->len
-
76 local_tx_pd
->priority
= (u8
) skb
->priority
;
77 local_tx_pd
->pkt_delay_2ms
=
78 mwifiex_wmm_compute_drv_pkt_delay(priv
, skb
);
80 if (local_tx_pd
->priority
<
81 ARRAY_SIZE(priv
->wmm
.user_pri_pkt_tx_ctrl
))
83 * Set the priority specific tx_control field, setting of 0 will
84 * cause the default value to be used later in this function
86 local_tx_pd
->tx_control
=
87 cpu_to_le32(priv
->wmm
.user_pri_pkt_tx_ctrl
[local_tx_pd
->
90 if (adapter
->pps_uapsd_mode
) {
91 if (mwifiex_check_last_packet_indication(priv
)) {
92 adapter
->tx_lock_flag
= true;
94 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
;
98 /* Offset of actual data */
99 pkt_offset
= sizeof(struct txpd
) + pad
;
100 if (pkt_type
== PKT_TYPE_MGMT
) {
101 /* Set the packet type and add header for management frame */
102 local_tx_pd
->tx_pkt_type
= cpu_to_le16(pkt_type
);
103 pkt_offset
+= MWIFIEX_MGMT_FRAME_HEADER_SIZE
;
106 local_tx_pd
->tx_pkt_offset
= cpu_to_le16(pkt_offset
);
108 /* make space for INTF_HEADER_LEN */
109 skb_push(skb
, INTF_HEADER_LEN
);
111 if (!local_tx_pd
->tx_control
)
112 /* TxCtrl set by user or default */
113 local_tx_pd
->tx_control
= cpu_to_le32(priv
->pkt_tx_ctrl
);
119 * This function tells firmware to send a NULL data packet.
121 * The function creates a NULL data packet with TxPD and sends to the
122 * firmware for transmission, with highest priority setting.
124 int mwifiex_send_null_packet(struct mwifiex_private
*priv
, u8 flags
)
126 struct mwifiex_adapter
*adapter
= priv
->adapter
;
127 struct txpd
*local_tx_pd
;
128 /* sizeof(struct txpd) + Interface specific header */
129 #define NULL_PACKET_HDR 64
130 u32 data_len
= NULL_PACKET_HDR
;
133 struct mwifiex_txinfo
*tx_info
= NULL
;
135 if (adapter
->surprise_removed
)
138 if (!priv
->media_connected
)
141 if (adapter
->data_sent
)
144 skb
= dev_alloc_skb(data_len
);
148 tx_info
= MWIFIEX_SKB_TXCB(skb
);
149 tx_info
->bss_num
= priv
->bss_num
;
150 tx_info
->bss_type
= priv
->bss_type
;
151 skb_reserve(skb
, sizeof(struct txpd
) + INTF_HEADER_LEN
);
152 skb_push(skb
, sizeof(struct txpd
));
154 local_tx_pd
= (struct txpd
*) skb
->data
;
155 local_tx_pd
->tx_control
= cpu_to_le32(priv
->pkt_tx_ctrl
);
156 local_tx_pd
->flags
= flags
;
157 local_tx_pd
->priority
= WMM_HIGHEST_PRIORITY
;
158 local_tx_pd
->tx_pkt_offset
= cpu_to_le16(sizeof(struct txpd
));
159 local_tx_pd
->bss_num
= priv
->bss_num
;
160 local_tx_pd
->bss_type
= priv
->bss_type
;
162 if (adapter
->iface_type
== MWIFIEX_USB
) {
163 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_USB_EP_DATA
,
166 skb_push(skb
, INTF_HEADER_LEN
);
167 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_DATA
,
172 adapter
->data_sent
= true;
173 /* Fall through FAILURE handling */
175 dev_kfree_skb_any(skb
);
176 dev_err(adapter
->dev
, "%s: host_to_card failed: ret=%d\n",
178 adapter
->dbg
.num_tx_host_to_card_failure
++;
181 dev_kfree_skb_any(skb
);
182 dev_dbg(adapter
->dev
, "data: %s: host_to_card succeeded\n",
184 adapter
->tx_lock_flag
= true;
196 * This function checks if we need to send last packet indication.
199 mwifiex_check_last_packet_indication(struct mwifiex_private
*priv
)
201 struct mwifiex_adapter
*adapter
= priv
->adapter
;
204 if (!adapter
->sleep_period
.period
)
206 if (mwifiex_wmm_lists_empty(adapter
))
209 if (ret
&& !adapter
->cmd_sent
&& !adapter
->curr_cmd
&&
210 !is_command_pending(adapter
)) {
211 adapter
->delay_null_pkt
= false;
215 adapter
->delay_null_pkt
= true;