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
);
53 dev_err(adapter
->dev
, "Tx: bad packet length: %d\n",
55 tx_info
->status_code
= -1;
59 /* If skb->data is not aligned; add padding */
60 pad
= (4 - (((void *)skb
->data
- NULL
) & 0x3)) % 4;
62 BUG_ON(skb_headroom(skb
) < (sizeof(*local_tx_pd
) + INTF_HEADER_LEN
64 skb_push(skb
, sizeof(*local_tx_pd
) + pad
);
66 local_tx_pd
= (struct txpd
*) skb
->data
;
67 memset(local_tx_pd
, 0, sizeof(struct txpd
));
68 local_tx_pd
->bss_num
= priv
->bss_num
;
69 local_tx_pd
->bss_type
= priv
->bss_type
;
70 local_tx_pd
->tx_pkt_length
= cpu_to_le16((u16
) (skb
->len
-
71 (sizeof(struct txpd
) + pad
)));
73 local_tx_pd
->priority
= (u8
) skb
->priority
;
74 local_tx_pd
->pkt_delay_2ms
=
75 mwifiex_wmm_compute_drv_pkt_delay(priv
, skb
);
77 if (local_tx_pd
->priority
<
78 ARRAY_SIZE(priv
->wmm
.user_pri_pkt_tx_ctrl
))
80 * Set the priority specific tx_control field, setting of 0 will
81 * cause the default value to be used later in this function
83 local_tx_pd
->tx_control
=
84 cpu_to_le32(priv
->wmm
.user_pri_pkt_tx_ctrl
[local_tx_pd
->
87 if (adapter
->pps_uapsd_mode
) {
88 if (mwifiex_check_last_packet_indication(priv
)) {
89 adapter
->tx_lock_flag
= true;
91 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
;
95 /* Offset of actual data */
96 local_tx_pd
->tx_pkt_offset
= cpu_to_le16(sizeof(struct txpd
) + pad
);
98 /* make space for INTF_HEADER_LEN */
99 skb_push(skb
, INTF_HEADER_LEN
);
101 if (!local_tx_pd
->tx_control
)
102 /* TxCtrl set by user or default */
103 local_tx_pd
->tx_control
= cpu_to_le32(priv
->pkt_tx_ctrl
);
109 * This function tells firmware to send a NULL data packet.
111 * The function creates a NULL data packet with TxPD and sends to the
112 * firmware for transmission, with highest priority setting.
114 int mwifiex_send_null_packet(struct mwifiex_private
*priv
, u8 flags
)
116 struct mwifiex_adapter
*adapter
= priv
->adapter
;
117 struct txpd
*local_tx_pd
;
118 /* sizeof(struct txpd) + Interface specific header */
119 #define NULL_PACKET_HDR 64
120 u32 data_len
= NULL_PACKET_HDR
;
123 struct mwifiex_txinfo
*tx_info
= NULL
;
125 if (adapter
->surprise_removed
)
128 if (!priv
->media_connected
)
131 if (adapter
->data_sent
)
134 skb
= dev_alloc_skb(data_len
);
138 tx_info
= MWIFIEX_SKB_TXCB(skb
);
139 tx_info
->bss_index
= priv
->bss_index
;
140 skb_reserve(skb
, sizeof(struct txpd
) + INTF_HEADER_LEN
);
141 skb_push(skb
, sizeof(struct txpd
));
143 local_tx_pd
= (struct txpd
*) skb
->data
;
144 local_tx_pd
->tx_control
= cpu_to_le32(priv
->pkt_tx_ctrl
);
145 local_tx_pd
->flags
= flags
;
146 local_tx_pd
->priority
= WMM_HIGHEST_PRIORITY
;
147 local_tx_pd
->tx_pkt_offset
= cpu_to_le16(sizeof(struct txpd
));
148 local_tx_pd
->bss_num
= priv
->bss_num
;
149 local_tx_pd
->bss_type
= priv
->bss_type
;
151 skb_push(skb
, INTF_HEADER_LEN
);
153 ret
= adapter
->if_ops
.host_to_card(adapter
, MWIFIEX_TYPE_DATA
,
154 skb
->data
, skb
->len
, NULL
);
157 adapter
->data_sent
= true;
158 /* Fall through FAILURE handling */
160 dev_kfree_skb_any(skb
);
161 dev_err(adapter
->dev
, "%s: host_to_card failed: ret=%d\n",
163 adapter
->dbg
.num_tx_host_to_card_failure
++;
166 dev_kfree_skb_any(skb
);
167 dev_dbg(adapter
->dev
, "data: %s: host_to_card succeeded\n",
169 adapter
->tx_lock_flag
= true;
181 * This function checks if we need to send last packet indication.
184 mwifiex_check_last_packet_indication(struct mwifiex_private
*priv
)
186 struct mwifiex_adapter
*adapter
= priv
->adapter
;
189 if (!adapter
->sleep_period
.period
)
191 if (mwifiex_wmm_lists_empty(adapter
))
194 if (ret
&& !adapter
->cmd_sent
&& !adapter
->curr_cmd
195 && !is_command_pending(adapter
)) {
196 adapter
->delay_null_pkt
= false;
200 adapter
->delay_null_pkt
= true;