OSDN Git Service

b43: Rewrite TX power adjustment
[uclinux-h8/linux.git] / drivers / net / wireless / b43 / phy_common.h
1 #ifndef LINUX_B43_PHY_COMMON_H_
2 #define LINUX_B43_PHY_COMMON_H_
3
4 #include <linux/rfkill.h>
5
6 struct b43_wldev;
7
8
9 /* PHY register routing bits */
10 #define B43_PHYROUTE                    0x0C00 /* PHY register routing bits mask */
11 #define  B43_PHYROUTE_BASE              0x0000 /* Base registers */
12 #define  B43_PHYROUTE_OFDM_GPHY         0x0400 /* OFDM register routing for G-PHYs */
13 #define  B43_PHYROUTE_EXT_GPHY          0x0800 /* Extended G-PHY registers */
14 #define  B43_PHYROUTE_N_BMODE           0x0C00 /* N-PHY BMODE registers */
15
16 /* CCK (B-PHY) registers. */
17 #define B43_PHY_CCK(reg)                ((reg) | B43_PHYROUTE_BASE)
18 /* N-PHY registers. */
19 #define B43_PHY_N(reg)                  ((reg) | B43_PHYROUTE_BASE)
20 /* N-PHY BMODE registers. */
21 #define B43_PHY_N_BMODE(reg)            ((reg) | B43_PHYROUTE_N_BMODE)
22 /* OFDM (A-PHY) registers. */
23 #define B43_PHY_OFDM(reg)               ((reg) | B43_PHYROUTE_OFDM_GPHY)
24 /* Extended G-PHY registers. */
25 #define B43_PHY_EXTG(reg)               ((reg) | B43_PHYROUTE_EXT_GPHY)
26
27
28 /* Masks for the PHY versioning registers. */
29 #define B43_PHYVER_ANALOG               0xF000
30 #define B43_PHYVER_ANALOG_SHIFT         12
31 #define B43_PHYVER_TYPE                 0x0F00
32 #define B43_PHYVER_TYPE_SHIFT           8
33 #define B43_PHYVER_VERSION              0x00FF
34
35 /**
36  * enum b43_interference_mitigation - Interference Mitigation mode
37  *
38  * @B43_INTERFMODE_NONE:        Disabled
39  * @B43_INTERFMODE_NONWLAN:     Non-WLAN Interference Mitigation
40  * @B43_INTERFMODE_MANUALWLAN:  WLAN Interference Mitigation
41  * @B43_INTERFMODE_AUTOWLAN:    Automatic WLAN Interference Mitigation
42  */
43 enum b43_interference_mitigation {
44         B43_INTERFMODE_NONE,
45         B43_INTERFMODE_NONWLAN,
46         B43_INTERFMODE_MANUALWLAN,
47         B43_INTERFMODE_AUTOWLAN,
48 };
49
50 /* Antenna identifiers */
51 enum {
52         B43_ANTENNA0,           /* Antenna 0 */
53         B43_ANTENNA1,           /* Antenna 0 */
54         B43_ANTENNA_AUTO1,      /* Automatic, starting with antenna 1 */
55         B43_ANTENNA_AUTO0,      /* Automatic, starting with antenna 0 */
56         B43_ANTENNA2,
57         B43_ANTENNA3 = 8,
58
59         B43_ANTENNA_AUTO = B43_ANTENNA_AUTO0,
60         B43_ANTENNA_DEFAULT = B43_ANTENNA_AUTO,
61 };
62
63 /**
64  * enum b43_txpwr_result - Return value for the recalc_txpower PHY op.
65  *
66  * @B43_TXPWR_RES_NEED_ADJUST:  Values changed. Hardware adjustment is needed.
67  * @B43_TXPWR_RES_DONE:         No more work to do. Everything is done.
68  */
69 enum b43_txpwr_result {
70         B43_TXPWR_RES_NEED_ADJUST,
71         B43_TXPWR_RES_DONE,
72 };
73
74 /**
75  * struct b43_phy_operations - Function pointers for PHY ops.
76  *
77  * @prepare:            Prepare the PHY. This is called before @init.
78  *                      Can be NULL, if not required.
79  * @init:               Initialize the PHY.
80  *                      Must not be NULL.
81  * @exit:               Shutdown the PHY and free all data structures.
82  *                      Can be NULL, if not required.
83  *
84  * @phy_read:           Read from a PHY register.
85  *                      Must not be NULL.
86  * @phy_write:          Write to a PHY register.
87  *                      Must not be NULL.
88  * @radio_read:         Read from a Radio register.
89  *                      Must not be NULL.
90  * @radio_write:        Write to a Radio register.
91  *                      Must not be NULL.
92  *
93  * @supports_hwpctl:    Returns a boolean whether Hardware Power Control
94  *                      is supported or not.
95  *                      If NULL, hwpctl is assumed to be never supported.
96  * @software_rfkill:    Turn the radio ON or OFF.
97  *                      Possible state values are
98  *                      RFKILL_STATE_SOFT_BLOCKED or
99  *                      RFKILL_STATE_UNBLOCKED
100  *                      Must not be NULL.
101  * @switch_channel:     Switch the radio to another channel.
102  *                      Must not be NULL.
103  * @get_default_chan:   Just returns the default channel number.
104  *                      Must not be NULL.
105  * @set_rx_antenna:     Set the antenna used for RX.
106  *                      Can be NULL, if not supported.
107  * @interf_mitigation:  Switch the Interference Mitigation mode.
108  *                      Can be NULL, if not supported.
109  *
110  * @recalc_txpower:     Recalculate the transmission power parameters.
111  *                      This callback has to recalculate the TX power settings,
112  *                      but does not need to write them to the hardware, yet.
113  *                      Returns enum b43_txpwr_result to indicate whether the hardware
114  *                      needs to be adjusted.
115  *                      If B43_TXPWR_NEED_ADJUST is returned, @adjust_txpower
116  *                      will be called later.
117  *                      If the parameter "ignore_tssi" is true, the TSSI values should
118  *                      be ignored and a recalculation of the power settings should be
119  *                      done even if the TSSI values did not change.
120  *                      This callback is called with wl->irq_lock held and must not sleep.
121  *                      Must not be NULL.
122  * @adjust_txpower:     Write the previously calculated TX power settings
123  *                      (from @recalc_txpower) to the hardware.
124  *                      This function may sleep.
125  *                      Can be NULL, if (and ONLY if) @recalc_txpower _always_
126  *                      returns B43_TXPWR_RES_DONE.
127  *
128  * @pwork_15sec:        Periodic work. Called every 15 seconds.
129  *                      Can be NULL, if not required.
130  * @pwork_60sec:        Periodic work. Called every 60 seconds.
131  *                      Can be NULL, if not required.
132  */
133 struct b43_phy_operations {
134         /* Initialisation */
135         int (*allocate)(struct b43_wldev *dev);
136         int (*prepare)(struct b43_wldev *dev);
137         int (*init)(struct b43_wldev *dev);
138         void (*exit)(struct b43_wldev *dev);
139
140         /* Register access */
141         u16 (*phy_read)(struct b43_wldev *dev, u16 reg);
142         void (*phy_write)(struct b43_wldev *dev, u16 reg, u16 value);
143         u16 (*radio_read)(struct b43_wldev *dev, u16 reg);
144         void (*radio_write)(struct b43_wldev *dev, u16 reg, u16 value);
145
146         /* Radio */
147         bool (*supports_hwpctl)(struct b43_wldev *dev);
148         void (*software_rfkill)(struct b43_wldev *dev, enum rfkill_state state);
149         int (*switch_channel)(struct b43_wldev *dev, unsigned int new_channel);
150         unsigned int (*get_default_chan)(struct b43_wldev *dev);
151         void (*set_rx_antenna)(struct b43_wldev *dev, int antenna);
152         int (*interf_mitigation)(struct b43_wldev *dev,
153                                  enum b43_interference_mitigation new_mode);
154
155         /* Transmission power adjustment */
156         enum b43_txpwr_result (*recalc_txpower)(struct b43_wldev *dev,
157                                                 bool ignore_tssi);
158         void (*adjust_txpower)(struct b43_wldev *dev);
159
160         /* Misc */
161         void (*pwork_15sec)(struct b43_wldev *dev);
162         void (*pwork_60sec)(struct b43_wldev *dev);
163 };
164
165 struct b43_phy_a;
166 struct b43_phy_g;
167 struct b43_phy_n;
168
169 struct b43_phy {
170         /* Hardware operation callbacks. */
171         const struct b43_phy_operations *ops;
172
173         /* Most hardware context information is stored in the standard-
174          * specific data structures pointed to by the pointers below.
175          * Only one of them is valid (the currently enabled PHY). */
176 #ifdef CONFIG_B43_DEBUG
177         /* No union for debug build to force NULL derefs in buggy code. */
178         struct {
179 #else
180         union {
181 #endif
182                 /* A-PHY specific information */
183                 struct b43_phy_a *a;
184                 /* G-PHY specific information */
185                 struct b43_phy_g *g;
186                 /* N-PHY specific information */
187                 struct b43_phy_n *n;
188         };
189
190         /* Band support flags. */
191         bool supports_2ghz;
192         bool supports_5ghz;
193
194         /* GMODE bit enabled? */
195         bool gmode;
196
197         /* Analog Type */
198         u8 analog;
199         /* B43_PHYTYPE_ */
200         u8 type;
201         /* PHY revision number. */
202         u8 rev;
203
204         /* Radio versioning */
205         u16 radio_manuf;        /* Radio manufacturer */
206         u16 radio_ver;          /* Radio version */
207         u8 radio_rev;           /* Radio revision */
208
209         /* Software state of the radio */
210         bool radio_on;
211
212         /* Desired TX power level (in dBm).
213          * This is set by the user and adjusted in b43_phy_xmitpower(). */
214         int desired_txpower;
215
216         /* Hardware Power Control enabled? */
217         bool hardware_power_control;
218
219         /* The time (in absolute jiffies) when the next TX power output
220          * check is needed. */
221         unsigned long next_txpwr_check_time;
222
223         /* current channel */
224         unsigned int channel;
225
226         /* PHY TX errors counter. */
227         atomic_t txerr_cnt;
228
229 #ifdef CONFIG_B43_DEBUG
230         /* PHY registers locked by b43_phy_lock()? */
231         bool phy_locked;
232 #endif /* B43_DEBUG */
233 };
234
235
236 /**
237  * b43_phy_operations_setup - Initialize the PHY operations datastructure
238  * based on the current PHY type.
239  */
240 int b43_phy_operations_setup(struct b43_wldev *dev);
241
242 /**
243  * b43_phy_init - Initialise the PHY
244  */
245 int b43_phy_init(struct b43_wldev *dev);
246
247 /**
248  * b43_phy_exit - Cleanup PHY
249  */
250 void b43_phy_exit(struct b43_wldev *dev);
251
252 /**
253  * b43_has_hardware_pctl - Hardware Power Control supported?
254  * Returns a boolean, whether hardware power control is supported.
255  */
256 bool b43_has_hardware_pctl(struct b43_wldev *dev);
257
258 /**
259  * b43_phy_read - 16bit PHY register read access
260  */
261 u16 b43_phy_read(struct b43_wldev *dev, u16 reg);
262
263 /**
264  * b43_phy_write - 16bit PHY register write access
265  */
266 void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value);
267
268 /**
269  * b43_phy_mask - Mask a PHY register with a mask
270  */
271 void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask);
272
273 /**
274  * b43_phy_set - OR a PHY register with a bitmap
275  */
276 void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set);
277
278 /**
279  * b43_phy_maskset - Mask and OR a PHY register with a mask and bitmap
280  */
281 void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
282
283 /**
284  * b43_radio_read - 16bit Radio register read access
285  */
286 u16 b43_radio_read(struct b43_wldev *dev, u16 reg);
287 #define b43_radio_read16        b43_radio_read /* DEPRECATED */
288
289 /**
290  * b43_radio_write - 16bit Radio register write access
291  */
292 void b43_radio_write(struct b43_wldev *dev, u16 reg, u16 value);
293 #define b43_radio_write16       b43_radio_write /* DEPRECATED */
294
295 /**
296  * b43_radio_mask - Mask a 16bit radio register with a mask
297  */
298 void b43_radio_mask(struct b43_wldev *dev, u16 offset, u16 mask);
299
300 /**
301  * b43_radio_set - OR a 16bit radio register with a bitmap
302  */
303 void b43_radio_set(struct b43_wldev *dev, u16 offset, u16 set);
304
305 /**
306  * b43_radio_maskset - Mask and OR a radio register with a mask and bitmap
307  */
308 void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
309
310 /**
311  * b43_radio_lock - Lock firmware radio register access
312  */
313 void b43_radio_lock(struct b43_wldev *dev);
314
315 /**
316  * b43_radio_unlock - Unlock firmware radio register access
317  */
318 void b43_radio_unlock(struct b43_wldev *dev);
319
320 /**
321  * b43_phy_lock - Lock firmware PHY register access
322  */
323 void b43_phy_lock(struct b43_wldev *dev);
324
325 /**
326  * b43_phy_unlock - Unlock firmware PHY register access
327  */
328 void b43_phy_unlock(struct b43_wldev *dev);
329
330 /**
331  * b43_switch_channel - Switch to another channel
332  */
333 int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel);
334 /**
335  * B43_DEFAULT_CHANNEL - Switch to the default channel.
336  */
337 #define B43_DEFAULT_CHANNEL     UINT_MAX
338
339 /**
340  * b43_software_rfkill - Turn the radio ON or OFF in software.
341  */
342 void b43_software_rfkill(struct b43_wldev *dev, enum rfkill_state state);
343
344 /**
345  * b43_phy_txpower_check - Check TX power output.
346  *
347  * Compare the current TX power output to the desired power emission
348  * and schedule an adjustment in case it mismatches.
349  * Requires wl->irq_lock locked.
350  *
351  * @flags:      OR'ed enum b43_phy_txpower_check_flags flags.
352  *              See the docs below.
353  */
354 void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags);
355 /**
356  * enum b43_phy_txpower_check_flags - Flags for b43_phy_txpower_check()
357  *
358  * @B43_TXPWR_IGNORE_TIME: Ignore the schedule time and force-redo
359  *                         the check now.
360  * @B43_TXPWR_IGNORE_TSSI: Redo the recalculation, even if the average
361  *                         TSSI did not change.
362  */
363 enum b43_phy_txpower_check_flags {
364         B43_TXPWR_IGNORE_TIME           = (1 << 0),
365         B43_TXPWR_IGNORE_TSSI           = (1 << 1),
366 };
367
368 struct work_struct;
369 void b43_phy_txpower_adjust_work(struct work_struct *work);
370
371 /**
372  * b43_phy_shm_tssi_read - Read the average of the last 4 TSSI from SHM.
373  *
374  * @shm_offset:         The SHM address to read the values from.
375  *
376  * Returns the average of the 4 TSSI values, or a negative error code.
377  */
378 int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset);
379
380
381 #endif /* LINUX_B43_PHY_COMMON_H_ */