1 #ifndef LINUX_B43_PHY_COMMON_H_
2 #define LINUX_B43_PHY_COMMON_H_
4 #include <linux/rfkill.h>
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 */
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)
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
36 * enum b43_interference_mitigation - Interference Mitigation mode
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
43 enum b43_interference_mitigation {
45 B43_INTERFMODE_NONWLAN,
46 B43_INTERFMODE_MANUALWLAN,
47 B43_INTERFMODE_AUTOWLAN,
50 /* Antenna identifiers */
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 */
59 B43_ANTENNA_AUTO = B43_ANTENNA_AUTO0,
60 B43_ANTENNA_DEFAULT = B43_ANTENNA_AUTO,
64 * enum b43_txpwr_result - Return value for the recalc_txpower PHY op.
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.
69 enum b43_txpwr_result {
70 B43_TXPWR_RES_NEED_ADJUST,
75 * struct b43_phy_operations - Function pointers for PHY ops.
77 * @prepare: Prepare the PHY. This is called before @init.
78 * Can be NULL, if not required.
79 * @init: Initialize the PHY.
81 * @exit: Shutdown the PHY and free all data structures.
82 * Can be NULL, if not required.
84 * @phy_read: Read from a PHY register.
86 * @phy_write: Write to a PHY register.
88 * @radio_read: Read from a Radio register.
90 * @radio_write: Write to a Radio register.
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
101 * @switch_channel: Switch the radio to another channel.
103 * @get_default_chan: Just returns the default channel number.
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.
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.
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.
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.
133 struct b43_phy_operations {
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);
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);
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);
155 /* Transmission power adjustment */
156 enum b43_txpwr_result (*recalc_txpower)(struct b43_wldev *dev,
158 void (*adjust_txpower)(struct b43_wldev *dev);
161 void (*pwork_15sec)(struct b43_wldev *dev);
162 void (*pwork_60sec)(struct b43_wldev *dev);
170 /* Hardware operation callbacks. */
171 const struct b43_phy_operations *ops;
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. */
182 /* A-PHY specific information */
184 /* G-PHY specific information */
186 /* N-PHY specific information */
190 /* Band support flags. */
194 /* GMODE bit enabled? */
201 /* PHY revision number. */
204 /* Radio versioning */
205 u16 radio_manuf; /* Radio manufacturer */
206 u16 radio_ver; /* Radio version */
207 u8 radio_rev; /* Radio revision */
209 /* Software state of the radio */
212 /* Desired TX power level (in dBm).
213 * This is set by the user and adjusted in b43_phy_xmitpower(). */
216 /* Hardware Power Control enabled? */
217 bool hardware_power_control;
219 /* The time (in absolute jiffies) when the next TX power output
220 * check is needed. */
221 unsigned long next_txpwr_check_time;
223 /* current channel */
224 unsigned int channel;
226 /* PHY TX errors counter. */
229 #ifdef CONFIG_B43_DEBUG
230 /* PHY registers locked by b43_phy_lock()? */
232 #endif /* B43_DEBUG */
237 * b43_phy_operations_setup - Initialize the PHY operations datastructure
238 * based on the current PHY type.
240 int b43_phy_operations_setup(struct b43_wldev *dev);
243 * b43_phy_init - Initialise the PHY
245 int b43_phy_init(struct b43_wldev *dev);
248 * b43_phy_exit - Cleanup PHY
250 void b43_phy_exit(struct b43_wldev *dev);
253 * b43_has_hardware_pctl - Hardware Power Control supported?
254 * Returns a boolean, whether hardware power control is supported.
256 bool b43_has_hardware_pctl(struct b43_wldev *dev);
259 * b43_phy_read - 16bit PHY register read access
261 u16 b43_phy_read(struct b43_wldev *dev, u16 reg);
264 * b43_phy_write - 16bit PHY register write access
266 void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value);
269 * b43_phy_mask - Mask a PHY register with a mask
271 void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask);
274 * b43_phy_set - OR a PHY register with a bitmap
276 void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set);
279 * b43_phy_maskset - Mask and OR a PHY register with a mask and bitmap
281 void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
284 * b43_radio_read - 16bit Radio register read access
286 u16 b43_radio_read(struct b43_wldev *dev, u16 reg);
287 #define b43_radio_read16 b43_radio_read /* DEPRECATED */
290 * b43_radio_write - 16bit Radio register write access
292 void b43_radio_write(struct b43_wldev *dev, u16 reg, u16 value);
293 #define b43_radio_write16 b43_radio_write /* DEPRECATED */
296 * b43_radio_mask - Mask a 16bit radio register with a mask
298 void b43_radio_mask(struct b43_wldev *dev, u16 offset, u16 mask);
301 * b43_radio_set - OR a 16bit radio register with a bitmap
303 void b43_radio_set(struct b43_wldev *dev, u16 offset, u16 set);
306 * b43_radio_maskset - Mask and OR a radio register with a mask and bitmap
308 void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
311 * b43_radio_lock - Lock firmware radio register access
313 void b43_radio_lock(struct b43_wldev *dev);
316 * b43_radio_unlock - Unlock firmware radio register access
318 void b43_radio_unlock(struct b43_wldev *dev);
321 * b43_phy_lock - Lock firmware PHY register access
323 void b43_phy_lock(struct b43_wldev *dev);
326 * b43_phy_unlock - Unlock firmware PHY register access
328 void b43_phy_unlock(struct b43_wldev *dev);
331 * b43_switch_channel - Switch to another channel
333 int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel);
335 * B43_DEFAULT_CHANNEL - Switch to the default channel.
337 #define B43_DEFAULT_CHANNEL UINT_MAX
340 * b43_software_rfkill - Turn the radio ON or OFF in software.
342 void b43_software_rfkill(struct b43_wldev *dev, enum rfkill_state state);
345 * b43_phy_txpower_check - Check TX power output.
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.
351 * @flags: OR'ed enum b43_phy_txpower_check_flags flags.
352 * See the docs below.
354 void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags);
356 * enum b43_phy_txpower_check_flags - Flags for b43_phy_txpower_check()
358 * @B43_TXPWR_IGNORE_TIME: Ignore the schedule time and force-redo
360 * @B43_TXPWR_IGNORE_TSSI: Redo the recalculation, even if the average
361 * TSSI did not change.
363 enum b43_phy_txpower_check_flags {
364 B43_TXPWR_IGNORE_TIME = (1 << 0),
365 B43_TXPWR_IGNORE_TSSI = (1 << 1),
369 void b43_phy_txpower_adjust_work(struct work_struct *work);
372 * b43_phy_shm_tssi_read - Read the average of the last 4 TSSI from SHM.
374 * @shm_offset: The SHM address to read the values from.
376 * Returns the average of the 4 TSSI values, or a negative error code.
378 int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset);
381 #endif /* LINUX_B43_PHY_COMMON_H_ */