blob: a876e169cc87d5ecc3862ecf0e382b1d100e7008 [file] [log] [blame]
Michael Bueschef1a6282008-08-27 18:53:02 +02001#ifndef LINUX_B43_PHY_COMMON_H_
2#define LINUX_B43_PHY_COMMON_H_
3
4#include <linux/rfkill.h>
5
6struct 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 */
43enum b43_interference_mitigation {
44 B43_INTERFMODE_NONE,
45 B43_INTERFMODE_NONWLAN,
46 B43_INTERFMODE_MANUALWLAN,
47 B43_INTERFMODE_AUTOWLAN,
48};
49
50/* Antenna identifiers */
51enum {
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/**
Michael Buesch18c8ade2008-08-28 19:33:40 +020064 * 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 */
69enum b43_txpwr_result {
70 B43_TXPWR_RES_NEED_ADJUST,
71 B43_TXPWR_RES_DONE,
72};
73
74/**
Michael Bueschef1a6282008-08-27 18:53:02 +020075 * 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 *
Michael Buesch18c8ade2008-08-28 19:33:40 +0200110 * @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.
Michael Bueschef1a6282008-08-27 18:53:02 +0200121 * Must not be NULL.
Michael Buesch18c8ade2008-08-28 19:33:40 +0200122 * @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.
Michael Bueschef1a6282008-08-27 18:53:02 +0200127 *
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 */
133struct 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 */
Michael Buesch18c8ade2008-08-28 19:33:40 +0200156 enum b43_txpwr_result (*recalc_txpower)(struct b43_wldev *dev,
157 bool ignore_tssi);
158 void (*adjust_txpower)(struct b43_wldev *dev);
Michael Bueschef1a6282008-08-27 18:53:02 +0200159
160 /* Misc */
161 void (*pwork_15sec)(struct b43_wldev *dev);
162 void (*pwork_60sec)(struct b43_wldev *dev);
163};
164
165struct b43_phy_a;
166struct b43_phy_g;
167struct b43_phy_n;
Michael Buesche63e4362008-08-30 10:55:48 +0200168struct b43_phy_lp;
Michael Bueschef1a6282008-08-27 18:53:02 +0200169
170struct b43_phy {
171 /* Hardware operation callbacks. */
172 const struct b43_phy_operations *ops;
173
174 /* Most hardware context information is stored in the standard-
175 * specific data structures pointed to by the pointers below.
176 * Only one of them is valid (the currently enabled PHY). */
177#ifdef CONFIG_B43_DEBUG
178 /* No union for debug build to force NULL derefs in buggy code. */
179 struct {
180#else
181 union {
182#endif
183 /* A-PHY specific information */
184 struct b43_phy_a *a;
185 /* G-PHY specific information */
186 struct b43_phy_g *g;
187 /* N-PHY specific information */
188 struct b43_phy_n *n;
Michael Buesche63e4362008-08-30 10:55:48 +0200189 /* LP-PHY specific information */
190 struct b43_phy_lp *lp;
Michael Bueschef1a6282008-08-27 18:53:02 +0200191 };
192
193 /* Band support flags. */
194 bool supports_2ghz;
195 bool supports_5ghz;
196
197 /* GMODE bit enabled? */
198 bool gmode;
199
200 /* Analog Type */
201 u8 analog;
202 /* B43_PHYTYPE_ */
203 u8 type;
204 /* PHY revision number. */
205 u8 rev;
206
207 /* Radio versioning */
208 u16 radio_manuf; /* Radio manufacturer */
209 u16 radio_ver; /* Radio version */
210 u8 radio_rev; /* Radio revision */
211
212 /* Software state of the radio */
213 bool radio_on;
214
215 /* Desired TX power level (in dBm).
216 * This is set by the user and adjusted in b43_phy_xmitpower(). */
Michael Buesch18c8ade2008-08-28 19:33:40 +0200217 int desired_txpower;
Michael Bueschef1a6282008-08-27 18:53:02 +0200218
219 /* Hardware Power Control enabled? */
220 bool hardware_power_control;
221
Michael Buesch18c8ade2008-08-28 19:33:40 +0200222 /* The time (in absolute jiffies) when the next TX power output
223 * check is needed. */
224 unsigned long next_txpwr_check_time;
225
Michael Bueschef1a6282008-08-27 18:53:02 +0200226 /* current channel */
227 unsigned int channel;
228
229 /* PHY TX errors counter. */
230 atomic_t txerr_cnt;
231
232#ifdef CONFIG_B43_DEBUG
233 /* PHY registers locked by b43_phy_lock()? */
234 bool phy_locked;
235#endif /* B43_DEBUG */
236};
237
238
239/**
240 * b43_phy_operations_setup - Initialize the PHY operations datastructure
241 * based on the current PHY type.
242 */
243int b43_phy_operations_setup(struct b43_wldev *dev);
244
245/**
246 * b43_phy_init - Initialise the PHY
247 */
248int b43_phy_init(struct b43_wldev *dev);
249
250/**
251 * b43_phy_exit - Cleanup PHY
252 */
253void b43_phy_exit(struct b43_wldev *dev);
254
255/**
256 * b43_has_hardware_pctl - Hardware Power Control supported?
257 * Returns a boolean, whether hardware power control is supported.
258 */
259bool b43_has_hardware_pctl(struct b43_wldev *dev);
260
261/**
262 * b43_phy_read - 16bit PHY register read access
263 */
264u16 b43_phy_read(struct b43_wldev *dev, u16 reg);
265
266/**
267 * b43_phy_write - 16bit PHY register write access
268 */
269void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value);
270
271/**
272 * b43_phy_mask - Mask a PHY register with a mask
273 */
274void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask);
275
276/**
277 * b43_phy_set - OR a PHY register with a bitmap
278 */
279void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set);
280
281/**
282 * b43_phy_maskset - Mask and OR a PHY register with a mask and bitmap
283 */
284void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
285
286/**
287 * b43_radio_read - 16bit Radio register read access
288 */
289u16 b43_radio_read(struct b43_wldev *dev, u16 reg);
290#define b43_radio_read16 b43_radio_read /* DEPRECATED */
291
292/**
293 * b43_radio_write - 16bit Radio register write access
294 */
295void b43_radio_write(struct b43_wldev *dev, u16 reg, u16 value);
296#define b43_radio_write16 b43_radio_write /* DEPRECATED */
297
298/**
299 * b43_radio_mask - Mask a 16bit radio register with a mask
300 */
301void b43_radio_mask(struct b43_wldev *dev, u16 offset, u16 mask);
302
303/**
304 * b43_radio_set - OR a 16bit radio register with a bitmap
305 */
306void b43_radio_set(struct b43_wldev *dev, u16 offset, u16 set);
307
308/**
309 * b43_radio_maskset - Mask and OR a radio register with a mask and bitmap
310 */
311void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
312
313/**
314 * b43_radio_lock - Lock firmware radio register access
315 */
316void b43_radio_lock(struct b43_wldev *dev);
317
318/**
319 * b43_radio_unlock - Unlock firmware radio register access
320 */
321void b43_radio_unlock(struct b43_wldev *dev);
322
323/**
324 * b43_phy_lock - Lock firmware PHY register access
325 */
326void b43_phy_lock(struct b43_wldev *dev);
327
328/**
329 * b43_phy_unlock - Unlock firmware PHY register access
330 */
331void b43_phy_unlock(struct b43_wldev *dev);
332
333/**
334 * b43_switch_channel - Switch to another channel
335 */
336int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel);
337/**
338 * B43_DEFAULT_CHANNEL - Switch to the default channel.
339 */
340#define B43_DEFAULT_CHANNEL UINT_MAX
341
342/**
343 * b43_software_rfkill - Turn the radio ON or OFF in software.
344 */
345void b43_software_rfkill(struct b43_wldev *dev, enum rfkill_state state);
346
Michael Buesch18c8ade2008-08-28 19:33:40 +0200347/**
348 * b43_phy_txpower_check - Check TX power output.
349 *
350 * Compare the current TX power output to the desired power emission
351 * and schedule an adjustment in case it mismatches.
352 * Requires wl->irq_lock locked.
353 *
354 * @flags: OR'ed enum b43_phy_txpower_check_flags flags.
355 * See the docs below.
356 */
357void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags);
358/**
359 * enum b43_phy_txpower_check_flags - Flags for b43_phy_txpower_check()
360 *
361 * @B43_TXPWR_IGNORE_TIME: Ignore the schedule time and force-redo
362 * the check now.
363 * @B43_TXPWR_IGNORE_TSSI: Redo the recalculation, even if the average
364 * TSSI did not change.
365 */
366enum b43_phy_txpower_check_flags {
367 B43_TXPWR_IGNORE_TIME = (1 << 0),
368 B43_TXPWR_IGNORE_TSSI = (1 << 1),
369};
370
371struct work_struct;
372void b43_phy_txpower_adjust_work(struct work_struct *work);
373
374/**
375 * b43_phy_shm_tssi_read - Read the average of the last 4 TSSI from SHM.
376 *
377 * @shm_offset: The SHM address to read the values from.
378 *
379 * Returns the average of the 4 TSSI values, or a negative error code.
380 */
381int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset);
382
383
Michael Bueschef1a6282008-08-27 18:53:02 +0200384#endif /* LINUX_B43_PHY_COMMON_H_ */