phy_common.h 13 KB

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