1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * This file is part of wl1251
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (c) 1998-2007 Texas Instruments Incorporated
6*4882a593Smuzhiyun * Copyright (C) 2008 Nokia Corporation
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #ifndef __WL1251_TX_H__
10*4882a593Smuzhiyun #define __WL1251_TX_H__
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #include <linux/bitops.h>
13*4882a593Smuzhiyun #include "acx.h"
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun /*
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * TX PATH
18*4882a593Smuzhiyun *
19*4882a593Smuzhiyun * The Tx path uses a double buffer and a tx_control structure, each located
20*4882a593Smuzhiyun * at a fixed address in the device's memory. On startup, the host retrieves
21*4882a593Smuzhiyun * the pointers to these addresses. A double buffer allows for continuous data
22*4882a593Smuzhiyun * flow towards the device. The host keeps track of which buffer is available
23*4882a593Smuzhiyun * and alternates between these two buffers on a per packet basis.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * The size of each of the two buffers is large enough to hold the longest
26*4882a593Smuzhiyun * 802.3 packet - maximum size Ethernet packet + header + descriptor.
27*4882a593Smuzhiyun * TX complete indication will be received a-synchronously in a TX done cyclic
28*4882a593Smuzhiyun * buffer which is composed of 16 tx_result descriptors structures and is used
29*4882a593Smuzhiyun * in a cyclic manner.
30*4882a593Smuzhiyun *
31*4882a593Smuzhiyun * The TX (HOST) procedure is as follows:
32*4882a593Smuzhiyun * 1. Read the Tx path status, that will give the data_out_count.
33*4882a593Smuzhiyun * 2. goto 1, if not possible.
34*4882a593Smuzhiyun * i.e. if data_in_count - data_out_count >= HwBuffer size (2 for double
35*4882a593Smuzhiyun * buffer).
36*4882a593Smuzhiyun * 3. Copy the packet (preceded by double_buffer_desc), if possible.
37*4882a593Smuzhiyun * i.e. if data_in_count - data_out_count < HwBuffer size (2 for double
38*4882a593Smuzhiyun * buffer).
39*4882a593Smuzhiyun * 4. increment data_in_count.
40*4882a593Smuzhiyun * 5. Inform the firmware by generating a firmware internal interrupt.
41*4882a593Smuzhiyun * 6. FW will increment data_out_count after it reads the buffer.
42*4882a593Smuzhiyun *
43*4882a593Smuzhiyun * The TX Complete procedure:
44*4882a593Smuzhiyun * 1. To get a TX complete indication the host enables the tx_complete flag in
45*4882a593Smuzhiyun * the TX descriptor Structure.
46*4882a593Smuzhiyun * 2. For each packet with a Tx Complete field set, the firmware adds the
47*4882a593Smuzhiyun * transmit results to the cyclic buffer (txDoneRing) and sets both done_1
48*4882a593Smuzhiyun * and done_2 to 1 to indicate driver ownership.
49*4882a593Smuzhiyun * 3. The firmware sends a Tx Complete interrupt to the host to trigger the
50*4882a593Smuzhiyun * host to process the new data. Note: interrupt will be send per packet if
51*4882a593Smuzhiyun * TX complete indication was requested in tx_control or per crossing
52*4882a593Smuzhiyun * aggregation threshold.
53*4882a593Smuzhiyun * 4. After receiving the Tx Complete interrupt, the host reads the
54*4882a593Smuzhiyun * TxDescriptorDone information in a cyclic manner and clears both done_1
55*4882a593Smuzhiyun * and done_2 fields.
56*4882a593Smuzhiyun *
57*4882a593Smuzhiyun */
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun #define TX_COMPLETE_REQUIRED_BIT 0x80
60*4882a593Smuzhiyun #define TX_STATUS_DATA_OUT_COUNT_MASK 0xf
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun #define WL1251_TX_ALIGN_TO 4
63*4882a593Smuzhiyun #define WL1251_TX_ALIGN(len) (((len) + WL1251_TX_ALIGN_TO - 1) & \
64*4882a593Smuzhiyun ~(WL1251_TX_ALIGN_TO - 1))
65*4882a593Smuzhiyun #define WL1251_TKIP_IV_SPACE 4
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun struct tx_control {
68*4882a593Smuzhiyun /* Rate Policy (class) index */
69*4882a593Smuzhiyun unsigned rate_policy:3;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /* When set, no ack policy is expected */
72*4882a593Smuzhiyun unsigned ack_policy:1;
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun * Packet type:
76*4882a593Smuzhiyun * 0 -> 802.11
77*4882a593Smuzhiyun * 1 -> 802.3
78*4882a593Smuzhiyun * 2 -> IP
79*4882a593Smuzhiyun * 3 -> raw codec
80*4882a593Smuzhiyun */
81*4882a593Smuzhiyun unsigned packet_type:2;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /* If set, this is a QoS-Null or QoS-Data frame */
84*4882a593Smuzhiyun unsigned qos:1;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun /*
87*4882a593Smuzhiyun * If set, the target triggers the tx complete INT
88*4882a593Smuzhiyun * upon frame sending completion.
89*4882a593Smuzhiyun */
90*4882a593Smuzhiyun unsigned tx_complete:1;
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun /* 2 bytes padding before packet header */
93*4882a593Smuzhiyun unsigned xfer_pad:1;
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun unsigned reserved:7;
96*4882a593Smuzhiyun } __packed;
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun struct tx_double_buffer_desc {
100*4882a593Smuzhiyun /* Length of payload, including headers. */
101*4882a593Smuzhiyun __le16 length;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /*
104*4882a593Smuzhiyun * A bit mask that specifies the initial rate to be used
105*4882a593Smuzhiyun * Possible values are:
106*4882a593Smuzhiyun * 0x0001 - 1Mbits
107*4882a593Smuzhiyun * 0x0002 - 2Mbits
108*4882a593Smuzhiyun * 0x0004 - 5.5Mbits
109*4882a593Smuzhiyun * 0x0008 - 6Mbits
110*4882a593Smuzhiyun * 0x0010 - 9Mbits
111*4882a593Smuzhiyun * 0x0020 - 11Mbits
112*4882a593Smuzhiyun * 0x0040 - 12Mbits
113*4882a593Smuzhiyun * 0x0080 - 18Mbits
114*4882a593Smuzhiyun * 0x0100 - 22Mbits
115*4882a593Smuzhiyun * 0x0200 - 24Mbits
116*4882a593Smuzhiyun * 0x0400 - 36Mbits
117*4882a593Smuzhiyun * 0x0800 - 48Mbits
118*4882a593Smuzhiyun * 0x1000 - 54Mbits
119*4882a593Smuzhiyun */
120*4882a593Smuzhiyun __le16 rate;
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun /* Time in us that a packet can spend in the target */
123*4882a593Smuzhiyun __le32 expiry_time;
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /* index of the TX queue used for this packet */
126*4882a593Smuzhiyun u8 xmit_queue;
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun /* Used to identify a packet */
129*4882a593Smuzhiyun u8 id;
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun struct tx_control control;
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun /*
134*4882a593Smuzhiyun * The FW should cut the packet into fragments
135*4882a593Smuzhiyun * of this size.
136*4882a593Smuzhiyun */
137*4882a593Smuzhiyun __le16 frag_threshold;
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun /* Numbers of HW queue blocks to be allocated */
140*4882a593Smuzhiyun u8 num_mem_blocks;
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun u8 reserved;
143*4882a593Smuzhiyun } __packed;
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun enum {
146*4882a593Smuzhiyun TX_SUCCESS = 0,
147*4882a593Smuzhiyun TX_DMA_ERROR = BIT(7),
148*4882a593Smuzhiyun TX_DISABLED = BIT(6),
149*4882a593Smuzhiyun TX_RETRY_EXCEEDED = BIT(5),
150*4882a593Smuzhiyun TX_TIMEOUT = BIT(4),
151*4882a593Smuzhiyun TX_KEY_NOT_FOUND = BIT(3),
152*4882a593Smuzhiyun TX_ENCRYPT_FAIL = BIT(2),
153*4882a593Smuzhiyun TX_UNAVAILABLE_PRIORITY = BIT(1),
154*4882a593Smuzhiyun };
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun struct tx_result {
157*4882a593Smuzhiyun /*
158*4882a593Smuzhiyun * Ownership synchronization between the host and
159*4882a593Smuzhiyun * the firmware. If done_1 and done_2 are cleared,
160*4882a593Smuzhiyun * owned by the FW (no info ready).
161*4882a593Smuzhiyun */
162*4882a593Smuzhiyun u8 done_1;
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun /* same as double_buffer_desc->id */
165*4882a593Smuzhiyun u8 id;
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /*
168*4882a593Smuzhiyun * Total air access duration consumed by this
169*4882a593Smuzhiyun * packet, including all retries and overheads.
170*4882a593Smuzhiyun */
171*4882a593Smuzhiyun u16 medium_usage;
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun /* Total media delay (from 1st EDCA AIFS counter until TX Complete). */
174*4882a593Smuzhiyun u32 medium_delay;
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun /* Time between host xfer and tx complete */
177*4882a593Smuzhiyun u32 fw_hnadling_time;
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun /* The LS-byte of the last TKIP sequence number. */
180*4882a593Smuzhiyun u8 lsb_seq_num;
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun /* Retry count */
183*4882a593Smuzhiyun u8 ack_failures;
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun /* At which rate we got a ACK */
186*4882a593Smuzhiyun u16 rate;
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun u16 reserved;
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun /* TX_* */
191*4882a593Smuzhiyun u8 status;
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun /* See done_1 */
194*4882a593Smuzhiyun u8 done_2;
195*4882a593Smuzhiyun } __packed;
196*4882a593Smuzhiyun
wl1251_tx_get_queue(int queue)197*4882a593Smuzhiyun static inline int wl1251_tx_get_queue(int queue)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun switch (queue) {
200*4882a593Smuzhiyun case 0:
201*4882a593Smuzhiyun return QOS_AC_VO;
202*4882a593Smuzhiyun case 1:
203*4882a593Smuzhiyun return QOS_AC_VI;
204*4882a593Smuzhiyun case 2:
205*4882a593Smuzhiyun return QOS_AC_BE;
206*4882a593Smuzhiyun case 3:
207*4882a593Smuzhiyun return QOS_AC_BK;
208*4882a593Smuzhiyun default:
209*4882a593Smuzhiyun return QOS_AC_BE;
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun void wl1251_tx_work(struct work_struct *work);
214*4882a593Smuzhiyun void wl1251_tx_complete(struct wl1251 *wl);
215*4882a593Smuzhiyun void wl1251_tx_flush(struct wl1251 *wl);
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun #endif
218