phy_common.h 11 KB

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