• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * tx/rx interfaces for XRadio drivers
3  *
4  * Copyright (c) 2013
5  * Xradio Technology Co., Ltd. <www.xradiotech.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 
12 #ifndef XRADIO_TXRX_H
13 #define XRADIO_TXRX_H
14 
15 #include <linux/list.h>
16 #include "wsm.h"
17 
18 /* extern */ struct ieee80211_hw;
19 /* extern */ struct sk_buff;
20 /* extern */ struct xradio_txpriv;
21 /* extern */ struct xradio_vif;
22 
23 #ifdef SUPPORT_HT40
24 
25 #ifdef CONFIG_XRADIO_DEBUGFS
26 /*for tx rates debug.*/
27 extern u8  rates_dbg_en;
28 extern u16 rates_debug[6];
29 extern u8  Ratecnt_dbg;
30 extern u8  retry_dbg;
31 #endif
32 
33 #else
34 
35 #ifdef CONFIG_XRADIO_DEBUGFS
36 /*for tx rates debug.*/
37 extern u8 rates_dbg_en;
38 extern u32 rates_debug[3];
39 extern u8 maxRate_dbg;
40 extern u8 retry_dbg;
41 #endif
42 
43 #endif
44 
45 #ifdef SUPPORT_HT40
46 
47 /* ModemType in RateEntry */
48 #define MODEMTYPE_SHIFT     14
49 #define MODEMTYPE_MASK      0x03
50 #define RATE_MODEM_LEGACY   0x00
51 #define RATE_MODEM_HTOFDM   0x01
52 #define RATE_MODEM_VHTOFDM  0x02
53 
54 /* Bandwidth in RateEntry */
55 #define BANDWIDTH_SHIFT     12
56 #define BANDWIDTH_MASK      0x03
57 #define RATE_BANDWIDTH_20M  0x00
58 #define RATE_BANDWIDTH_40M  0x01
59 #define RATE_BANDWIDTH_80M  0x02
60 
61 /* FormatFlag in RateEntry flags */
62 #define RATE_F_MASK         0x0F00
63 #define RATE_F_PREAMBLE_S   0x0100
64 #define RATE_F_SGI          0x0200
65 #define RATE_F_GF           0x0400
66 #define RATE_F_STBC         0x0800
67 
68 #define MAKE_PREAMBLE_S(b)   ((!!(b))<<8)
69 #define MAKE_SGI(b)          ((!!(b))<<9)
70 #define MAKE_GF(b)           ((!!(b))<<10)
71 #define MAKE_STBC(b)         ((!!(b))<<11)
72 
73 #define RATEINDEX_SHIFT     4
74 #define RATEINDEX_MASK      0xf
75 
76 #define MCS_RATES_OFF  14
77 #define MAX_RATES_IDX  21
78 #define A_RATES_OFF    6
79 #define B_RATE_INDEX   0
80 #define AG_RATE_INDEX  A_RATES_OFF
81 
82 #define XRADIO_INVALID_RATE_ID     (0xFF)
83 #define XRADIO_INVALID_RATE_ENTRY   0x00F0
84 
85 /* ModemType in RateEntry */
86 #define FW_RATE_MODEM_SHIFT     14
87 #define FW_RATE_MODEM_MASK      0xC000
88 #define FW_RATE_MODEM_LEGACY    0x00
89 #define FW_RATE_MODEM_HTOFDM    0x01
90 #define FW_RATE_MODEM_VHTOFDM   0x02
91 
92 /* Bandwidth in RateEntry */
93 #define FW_RATE_BW_SHIFT        12
94 #define FW_RATE_BW_MASK         0x3000
95 #define FW_RATE_BW_20M          0x00
96 #define FW_RATE_BW_40M          0x01
97 #define FW_RATE_BW_80M          0x02
98 
99 /* FormatFlag in RateEntry flags */
100 #define FW_RATE_F_SHIFT         8
101 #define FW_RATE_F_MASK          0x0F00
102 #define FW_RATE_F_SPRE          0x1
103 #define FW_RATE_F_SGI           0x2
104 #define FW_RATE_F_GF            0x4
105 #define FW_RATE_F_STBC          0x8
106 
107 /* RateIndex */
108 #define FW_RATE_INDEX_SHIFT     4
109 #define FW_RATE_INDEX_MASK      0x00F0
110 #define FW_RATE_USE_DEFAULT     0xF
111 
112 /* MaxRetry */
113 #define FW_RATE_MAXRETRY_SHIFT  0
114 #define FW_RATE_MAXRETRY_MASK   0x000F
115 
116 #define GET_RATE_ENTRY_MODEM(_RateEntry)	(((_RateEntry)&FW_RATE_MODEM_MASK)>>FW_RATE_MODEM_SHIFT)
117 #define GET_RATE_ENTRY_BANDWIDTH(_RateEntry)	(((_RateEntry)&FW_RATE_BW_MASK)>>FW_RATE_BW_SHIFT)
118 #define GET_RATE_ENTRY_FLAGS(_RateEntry)	(((_RateEntry)&FW_RATE_F_MASK)>>FW_RATE_F_SHIFT)
119 #define GET_RATE_ENTRY_RATEINDEX(_RateEntry)	(((_RateEntry)&FW_RATE_INDEX_MASK)>>FW_RATE_INDEX_SHIFT)
120 #define GET_RATE_ENTRY_MAXRETRY(_RateEntry)	(((_RateEntry)&FW_RATE_MAXRETRY_MASK)>>FW_RATE_MAXRETRY_SHIFT)
121 
122 #define PUT_RATE_ENTRY_MODEM(_Value)		(((_Value)<<FW_RATE_MODEM_SHIFT)&FW_RATE_MODEM_MASK)
123 #define PUT_RATE_ENTRY_BANDWIDTH(_Value)	(((_Value)<<FW_RATE_BW_SHIFT)&FW_RATE_BW_MASK)
124 #define PUT_RATE_ENTRY_FLAGS(_Value)		(((_Value)<<FW_RATE_F_SHIFT)&FW_RATE_F_MASK)
125 #define PUT_RATE_ENTRY_RATEINDEX(_Value)	(((_Value)<<FW_RATE_INDEX_SHIFT)&FW_RATE_INDEX_MASK)
126 #define PUT_RATE_ENTRY_MAXRETRY(_Value)		(((_Value)<<FW_RATE_MAXRETRY_SHIFT)&FW_RATE_MAXRETRY_MASK)
127 
128 #endif
129 struct tx_policy {
130 	union {
131 
132 #ifdef SUPPORT_HT40
133 
134 		__le16 rate_entrys[MAX_RATES_STAGE];
135 
136 #else
137 
138 		__le32 tbl[3];
139 
140 #endif
141 		u8 raw[12];
142 	};
143 	u8  defined;		/* TODO: u32 or u8, profile and select best */
144 	u8  usage_count;	/* --// -- */
145 	u8  retry_count;	/* --// -- */
146 	u8  uploaded;
147 };
148 
149 struct tx_policy_cache_entry {
150 	struct tx_policy policy;
151 	struct list_head link;
152 };
153 
154 struct tx_policy_cache {
155 	struct tx_policy_cache_entry cache[TX_POLICY_CACHE_SIZE];
156 	struct list_head used;
157 	struct list_head free;
158 	spinlock_t lock;
159 	bool   queue_locked;
160 };
161 
162 /* ******************************************************************** */
163 /* TX policy cache							*/
164 /* Intention of TX policy cache is an overcomplicated WSM API.
165  * Device does not accept per-PDU tx retry sequence.
166  * It uses "tx retry policy id" instead, so driver code has to sync
167  * linux tx retry sequences with a retry policy table in the device.
168  */
169 void tx_policy_init(struct xradio_common *hw_priv);
170 void tx_policy_upload_work(struct work_struct *work);
171 
172 /* ******************************************************************** */
173 /* TX implementation							*/
174 
175 u32 xradio_rate_mask_to_wsm(struct xradio_common *hw_priv,
176 			       u32 rates);
177 void xradio_tx(struct ieee80211_hw *dev, struct ieee80211_tx_control *control, struct sk_buff *skb);
178 
179 void xradio_skb_dtor(struct xradio_common *hw_priv,
180 		     struct sk_buff *skb,
181 		     const struct xradio_txpriv *txpriv);
182 
183 /* ******************************************************************** */
184 
185 #ifdef SUPPORT_HT40
186 
187 /* Convert hw_value to rate entry */
188 u16 xradio_get_rate_entry(const struct xradio_common *hw_priv,
189 			u8 Bandwidth, u16 FormatFlag, u8 hw_value);
190 
191 #endif
192 
193 /* WSM callbacks							*/
194 
195 void xradio_tx_confirm_cb(struct xradio_common *hw_priv,
196 			  struct wsm_tx_confirm *arg);
197 void xradio_rx_cb(struct xradio_vif *priv,
198 		  struct wsm_rx *arg,
199 		  struct sk_buff **skb_p);
200 
201 /* ******************************************************************** */
202 /* Timeout								*/
203 
204 void xradio_tx_timeout(struct work_struct *work);
205 
206 /* ******************************************************************** */
207 /* Security								*/
208 int xradio_alloc_key(struct xradio_common *hw_priv);
209 void xradio_free_key(struct xradio_common *hw_priv, int idx);
210 void xradio_free_keys(struct xradio_common *hw_priv);
211 int xradio_upload_keys(struct xradio_vif *priv);
212 
213 /* ******************************************************************** */
214 /* Workaround for WFD test case 6.1.10					*/
215 #if defined(CONFIG_XRADIO_USE_EXTENSIONS)
216 void xradio_link_id_reset(struct work_struct *work);
217 #endif
218 
219 #endif /* XRADIO_TXRX_H */
220