phy_common.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. * struct b43_phy_operations - Function pointers for PHY ops.
  54. *
  55. * @prepare: Prepare the PHY. This is called before @init.
  56. * Can be NULL, if not required.
  57. * @init: Initialize the PHY.
  58. * Must not be NULL.
  59. * @exit: Shutdown the PHY and free all data structures.
  60. * Can be NULL, if not required.
  61. *
  62. * @phy_read: Read from a PHY register.
  63. * Must not be NULL.
  64. * @phy_write: Write to a PHY register.
  65. * Must not be NULL.
  66. * @radio_read: Read from a Radio register.
  67. * Must not be NULL.
  68. * @radio_write: Write to a Radio register.
  69. * Must not be NULL.
  70. *
  71. * @supports_hwpctl: Returns a boolean whether Hardware Power Control
  72. * is supported or not.
  73. * If NULL, hwpctl is assumed to be never supported.
  74. * @software_rfkill: Turn the radio ON or OFF.
  75. * Possible state values are
  76. * RFKILL_STATE_SOFT_BLOCKED or
  77. * RFKILL_STATE_UNBLOCKED
  78. * Must not be NULL.
  79. * @switch_channel: Switch the radio to another channel.
  80. * Must not be NULL.
  81. * @get_default_chan: Just returns the default channel number.
  82. * Must not be NULL.
  83. * @set_rx_antenna: Set the antenna used for RX.
  84. * Can be NULL, if not supported.
  85. * @interf_mitigation: Switch the Interference Mitigation mode.
  86. * Can be NULL, if not supported.
  87. *
  88. * @xmitpower: FIXME REMOVEME
  89. * Must not be NULL.
  90. *
  91. * @pwork_15sec: Periodic work. Called every 15 seconds.
  92. * Can be NULL, if not required.
  93. * @pwork_60sec: Periodic work. Called every 60 seconds.
  94. * Can be NULL, if not required.
  95. */
  96. struct b43_phy_operations {
  97. /* Initialisation */
  98. int (*allocate)(struct b43_wldev *dev);
  99. int (*prepare)(struct b43_wldev *dev);
  100. int (*init)(struct b43_wldev *dev);
  101. void (*exit)(struct b43_wldev *dev);
  102. /* Register access */
  103. u16 (*phy_read)(struct b43_wldev *dev, u16 reg);
  104. void (*phy_write)(struct b43_wldev *dev, u16 reg, u16 value);
  105. u16 (*radio_read)(struct b43_wldev *dev, u16 reg);
  106. void (*radio_write)(struct b43_wldev *dev, u16 reg, u16 value);
  107. /* Radio */
  108. bool (*supports_hwpctl)(struct b43_wldev *dev);
  109. void (*software_rfkill)(struct b43_wldev *dev, enum rfkill_state state);
  110. int (*switch_channel)(struct b43_wldev *dev, unsigned int new_channel);
  111. unsigned int (*get_default_chan)(struct b43_wldev *dev);
  112. void (*set_rx_antenna)(struct b43_wldev *dev, int antenna);
  113. int (*interf_mitigation)(struct b43_wldev *dev,
  114. enum b43_interference_mitigation new_mode);
  115. /* Transmission power adjustment */
  116. void (*xmitpower)(struct b43_wldev *dev);
  117. /* Misc */
  118. void (*pwork_15sec)(struct b43_wldev *dev);
  119. void (*pwork_60sec)(struct b43_wldev *dev);
  120. };
  121. struct b43_phy_a;
  122. struct b43_phy_g;
  123. struct b43_phy_n;
  124. struct b43_phy {
  125. /* Hardware operation callbacks. */
  126. const struct b43_phy_operations *ops;
  127. /* Most hardware context information is stored in the standard-
  128. * specific data structures pointed to by the pointers below.
  129. * Only one of them is valid (the currently enabled PHY). */
  130. #ifdef CONFIG_B43_DEBUG
  131. /* No union for debug build to force NULL derefs in buggy code. */
  132. struct {
  133. #else
  134. union {
  135. #endif
  136. /* A-PHY specific information */
  137. struct b43_phy_a *a;
  138. /* G-PHY specific information */
  139. struct b43_phy_g *g;
  140. /* N-PHY specific information */
  141. struct b43_phy_n *n;
  142. };
  143. /* Band support flags. */
  144. bool supports_2ghz;
  145. bool supports_5ghz;
  146. /* GMODE bit enabled? */
  147. bool gmode;
  148. /* Analog Type */
  149. u8 analog;
  150. /* B43_PHYTYPE_ */
  151. u8 type;
  152. /* PHY revision number. */
  153. u8 rev;
  154. /* Radio versioning */
  155. u16 radio_manuf; /* Radio manufacturer */
  156. u16 radio_ver; /* Radio version */
  157. u8 radio_rev; /* Radio revision */
  158. /* Software state of the radio */
  159. bool radio_on;
  160. /* Desired TX power level (in dBm).
  161. * This is set by the user and adjusted in b43_phy_xmitpower(). */
  162. u8 power_level;
  163. /* Hardware Power Control enabled? */
  164. bool hardware_power_control;
  165. /* current channel */
  166. unsigned int channel;
  167. /* PHY TX errors counter. */
  168. atomic_t txerr_cnt;
  169. #ifdef CONFIG_B43_DEBUG
  170. /* PHY registers locked by b43_phy_lock()? */
  171. bool phy_locked;
  172. #endif /* B43_DEBUG */
  173. };
  174. /**
  175. * b43_phy_operations_setup - Initialize the PHY operations datastructure
  176. * based on the current PHY type.
  177. */
  178. int b43_phy_operations_setup(struct b43_wldev *dev);
  179. /**
  180. * b43_phy_init - Initialise the PHY
  181. */
  182. int b43_phy_init(struct b43_wldev *dev);
  183. /**
  184. * b43_phy_exit - Cleanup PHY
  185. */
  186. void b43_phy_exit(struct b43_wldev *dev);
  187. /**
  188. * b43_has_hardware_pctl - Hardware Power Control supported?
  189. * Returns a boolean, whether hardware power control is supported.
  190. */
  191. bool b43_has_hardware_pctl(struct b43_wldev *dev);
  192. /**
  193. * b43_phy_read - 16bit PHY register read access
  194. */
  195. u16 b43_phy_read(struct b43_wldev *dev, u16 reg);
  196. /**
  197. * b43_phy_write - 16bit PHY register write access
  198. */
  199. void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value);
  200. /**
  201. * b43_phy_mask - Mask a PHY register with a mask
  202. */
  203. void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask);
  204. /**
  205. * b43_phy_set - OR a PHY register with a bitmap
  206. */
  207. void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set);
  208. /**
  209. * b43_phy_maskset - Mask and OR a PHY register with a mask and bitmap
  210. */
  211. void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
  212. /**
  213. * b43_radio_read - 16bit Radio register read access
  214. */
  215. u16 b43_radio_read(struct b43_wldev *dev, u16 reg);
  216. #define b43_radio_read16 b43_radio_read /* DEPRECATED */
  217. /**
  218. * b43_radio_write - 16bit Radio register write access
  219. */
  220. void b43_radio_write(struct b43_wldev *dev, u16 reg, u16 value);
  221. #define b43_radio_write16 b43_radio_write /* DEPRECATED */
  222. /**
  223. * b43_radio_mask - Mask a 16bit radio register with a mask
  224. */
  225. void b43_radio_mask(struct b43_wldev *dev, u16 offset, u16 mask);
  226. /**
  227. * b43_radio_set - OR a 16bit radio register with a bitmap
  228. */
  229. void b43_radio_set(struct b43_wldev *dev, u16 offset, u16 set);
  230. /**
  231. * b43_radio_maskset - Mask and OR a radio register with a mask and bitmap
  232. */
  233. void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set);
  234. /**
  235. * b43_radio_lock - Lock firmware radio register access
  236. */
  237. void b43_radio_lock(struct b43_wldev *dev);
  238. /**
  239. * b43_radio_unlock - Unlock firmware radio register access
  240. */
  241. void b43_radio_unlock(struct b43_wldev *dev);
  242. /**
  243. * b43_phy_lock - Lock firmware PHY register access
  244. */
  245. void b43_phy_lock(struct b43_wldev *dev);
  246. /**
  247. * b43_phy_unlock - Unlock firmware PHY register access
  248. */
  249. void b43_phy_unlock(struct b43_wldev *dev);
  250. /**
  251. * b43_switch_channel - Switch to another channel
  252. */
  253. int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel);
  254. /**
  255. * B43_DEFAULT_CHANNEL - Switch to the default channel.
  256. */
  257. #define B43_DEFAULT_CHANNEL UINT_MAX
  258. /**
  259. * b43_software_rfkill - Turn the radio ON or OFF in software.
  260. */
  261. void b43_software_rfkill(struct b43_wldev *dev, enum rfkill_state state);
  262. #endif /* LINUX_B43_PHY_COMMON_H_ */