pcu.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. /*
  2. * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
  4. * Copyright (c) 2007-2008 Matthew W. S. Bell <mentor@madwifi.org>
  5. * Copyright (c) 2007-2008 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
  6. * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
  7. * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
  8. *
  9. * Permission to use, copy, modify, and distribute this software for any
  10. * purpose with or without fee is hereby granted, provided that the above
  11. * copyright notice and this permission notice appear in all copies.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20. *
  21. */
  22. /*********************************\
  23. * Protocol Control Unit Functions *
  24. \*********************************/
  25. #include <asm/unaligned.h>
  26. #include "ath5k.h"
  27. #include "reg.h"
  28. #include "debug.h"
  29. #include "base.h"
  30. /*******************\
  31. * Generic functions *
  32. \*******************/
  33. /**
  34. * ath5k_hw_set_opmode - Set PCU operating mode
  35. *
  36. * @ah: The &struct ath5k_hw
  37. *
  38. * Initialize PCU for the various operating modes (AP/STA etc)
  39. *
  40. * NOTE: ah->ah_op_mode must be set before calling this.
  41. */
  42. int ath5k_hw_set_opmode(struct ath5k_hw *ah)
  43. {
  44. struct ath_common *common = ath5k_hw_common(ah);
  45. u32 pcu_reg, beacon_reg, low_id, high_id;
  46. /* Preserve rest settings */
  47. pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000;
  48. pcu_reg &= ~(AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_AP
  49. | AR5K_STA_ID1_KEYSRCH_MODE
  50. | (ah->ah_version == AR5K_AR5210 ?
  51. (AR5K_STA_ID1_PWR_SV | AR5K_STA_ID1_NO_PSPOLL) : 0));
  52. beacon_reg = 0;
  53. ATH5K_TRACE(ah->ah_sc);
  54. switch (ah->ah_op_mode) {
  55. case NL80211_IFTYPE_ADHOC:
  56. pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_KEYSRCH_MODE;
  57. beacon_reg |= AR5K_BCR_ADHOC;
  58. if (ah->ah_version == AR5K_AR5210)
  59. pcu_reg |= AR5K_STA_ID1_NO_PSPOLL;
  60. else
  61. AR5K_REG_ENABLE_BITS(ah, AR5K_CFG, AR5K_CFG_IBSS);
  62. break;
  63. case NL80211_IFTYPE_AP:
  64. case NL80211_IFTYPE_MESH_POINT:
  65. pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_KEYSRCH_MODE;
  66. beacon_reg |= AR5K_BCR_AP;
  67. if (ah->ah_version == AR5K_AR5210)
  68. pcu_reg |= AR5K_STA_ID1_NO_PSPOLL;
  69. else
  70. AR5K_REG_DISABLE_BITS(ah, AR5K_CFG, AR5K_CFG_IBSS);
  71. break;
  72. case NL80211_IFTYPE_STATION:
  73. pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE
  74. | (ah->ah_version == AR5K_AR5210 ?
  75. AR5K_STA_ID1_PWR_SV : 0);
  76. case NL80211_IFTYPE_MONITOR:
  77. pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE
  78. | (ah->ah_version == AR5K_AR5210 ?
  79. AR5K_STA_ID1_NO_PSPOLL : 0);
  80. break;
  81. default:
  82. return -EINVAL;
  83. }
  84. /*
  85. * Set PCU registers
  86. */
  87. low_id = get_unaligned_le32(common->macaddr);
  88. high_id = get_unaligned_le16(common->macaddr + 4);
  89. ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
  90. ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
  91. /*
  92. * Set Beacon Control Register on 5210
  93. */
  94. if (ah->ah_version == AR5K_AR5210)
  95. ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
  96. return 0;
  97. }
  98. /**
  99. * ath5k_hw_update - Update mib counters (mac layer statistics)
  100. *
  101. * @ah: The &struct ath5k_hw
  102. * @stats: The &struct ieee80211_low_level_stats we use to track
  103. * statistics on the driver
  104. *
  105. * Reads MIB counters from PCU and updates sw statistics. Must be
  106. * called after a MIB interrupt.
  107. */
  108. void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
  109. struct ieee80211_low_level_stats *stats)
  110. {
  111. ATH5K_TRACE(ah->ah_sc);
  112. /* Read-And-Clear */
  113. stats->dot11ACKFailureCount += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
  114. stats->dot11RTSFailureCount += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
  115. stats->dot11RTSSuccessCount += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
  116. stats->dot11FCSErrorCount += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
  117. /* XXX: Should we use this to track beacon count ?
  118. * -we read it anyway to clear the register */
  119. ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
  120. /* Reset profile count registers on 5212*/
  121. if (ah->ah_version == AR5K_AR5212) {
  122. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
  123. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
  124. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
  125. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
  126. }
  127. /* TODO: Handle ANI stats */
  128. }
  129. /**
  130. * ath5k_hw_set_ack_bitrate - set bitrate for ACKs
  131. *
  132. * @ah: The &struct ath5k_hw
  133. * @high: Flag to determine if we want to use high transmition rate
  134. * for ACKs or not
  135. *
  136. * If high flag is set, we tell hw to use a set of control rates based on
  137. * the current transmition rate (check out control_rates array inside reset.c).
  138. * If not hw just uses the lowest rate available for the current modulation
  139. * scheme being used (1Mbit for CCK and 6Mbits for OFDM).
  140. */
  141. void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
  142. {
  143. if (ah->ah_version != AR5K_AR5212)
  144. return;
  145. else {
  146. u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
  147. if (high)
  148. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
  149. else
  150. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
  151. }
  152. }
  153. /******************\
  154. * ACK/CTS Timeouts *
  155. \******************/
  156. #if 0
  157. /**
  158. * ath5k_hw_het_ack_timeout - Get ACK timeout from PCU in usec
  159. *
  160. * @ah: The &struct ath5k_hw
  161. */
  162. unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
  163. {
  164. ATH5K_TRACE(ah->ah_sc);
  165. return ath5k_hw_clocktoh(ah, AR5K_REG_MS(ath5k_hw_reg_read(ah,
  166. AR5K_TIME_OUT), AR5K_TIME_OUT_ACK));
  167. }
  168. #endif
  169. /**
  170. * ath5k_hw_set_ack_timeout - Set ACK timeout on PCU
  171. *
  172. * @ah: The &struct ath5k_hw
  173. * @timeout: Timeout in usec
  174. */
  175. static int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
  176. {
  177. ATH5K_TRACE(ah->ah_sc);
  178. if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK))
  179. <= timeout)
  180. return -EINVAL;
  181. AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
  182. ath5k_hw_htoclock(ah, timeout));
  183. return 0;
  184. }
  185. #if 0
  186. /**
  187. * ath5k_hw_get_cts_timeout - Get CTS timeout from PCU in usec
  188. *
  189. * @ah: The &struct ath5k_hw
  190. */
  191. unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
  192. {
  193. ATH5K_TRACE(ah->ah_sc);
  194. return ath5k_hw_clocktoh(ah, AR5K_REG_MS(ath5k_hw_reg_read(ah,
  195. AR5K_TIME_OUT), AR5K_TIME_OUT_CTS));
  196. }
  197. #endif
  198. /**
  199. * ath5k_hw_set_cts_timeout - Set CTS timeout on PCU
  200. *
  201. * @ah: The &struct ath5k_hw
  202. * @timeout: Timeout in usec
  203. */
  204. static int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
  205. {
  206. ATH5K_TRACE(ah->ah_sc);
  207. if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS))
  208. <= timeout)
  209. return -EINVAL;
  210. AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
  211. ath5k_hw_htoclock(ah, timeout));
  212. return 0;
  213. }
  214. /**
  215. * ath5k_hw_htoclock - Translate usec to hw clock units
  216. *
  217. * @ah: The &struct ath5k_hw
  218. * @usec: value in microseconds
  219. */
  220. unsigned int ath5k_hw_htoclock(struct ath5k_hw *ah, unsigned int usec)
  221. {
  222. return usec * ath5k_hw_get_clockrate(ah);
  223. }
  224. /**
  225. * ath5k_hw_clocktoh - Translate hw clock units to usec
  226. * @clock: value in hw clock units
  227. */
  228. unsigned int ath5k_hw_clocktoh(struct ath5k_hw *ah, unsigned int clock)
  229. {
  230. return clock / ath5k_hw_get_clockrate(ah);
  231. }
  232. /**
  233. * ath5k_hw_get_clockrate - Get the clock rate for current mode
  234. *
  235. * @ah: The &struct ath5k_hw
  236. */
  237. unsigned int ath5k_hw_get_clockrate(struct ath5k_hw *ah)
  238. {
  239. struct ieee80211_channel *channel = ah->ah_current_channel;
  240. int clock;
  241. if (channel->hw_value & CHANNEL_5GHZ)
  242. clock = 40; /* 802.11a */
  243. else if (channel->hw_value & CHANNEL_CCK)
  244. clock = 22; /* 802.11b */
  245. else
  246. clock = 44; /* 802.11g */
  247. /* Clock rate in turbo modes is twice the normal rate */
  248. if (channel->hw_value & CHANNEL_TURBO)
  249. clock *= 2;
  250. return clock;
  251. }
  252. /**
  253. * ath5k_hw_get_default_slottime - Get the default slot time for current mode
  254. *
  255. * @ah: The &struct ath5k_hw
  256. */
  257. static unsigned int ath5k_hw_get_default_slottime(struct ath5k_hw *ah)
  258. {
  259. struct ieee80211_channel *channel = ah->ah_current_channel;
  260. if (channel->hw_value & CHANNEL_TURBO)
  261. return 6; /* both turbo modes */
  262. if (channel->hw_value & CHANNEL_CCK)
  263. return 20; /* 802.11b */
  264. return 9; /* 802.11 a/g */
  265. }
  266. /**
  267. * ath5k_hw_get_default_sifs - Get the default SIFS for current mode
  268. *
  269. * @ah: The &struct ath5k_hw
  270. */
  271. static unsigned int ath5k_hw_get_default_sifs(struct ath5k_hw *ah)
  272. {
  273. struct ieee80211_channel *channel = ah->ah_current_channel;
  274. if (channel->hw_value & CHANNEL_TURBO)
  275. return 8; /* both turbo modes */
  276. if (channel->hw_value & CHANNEL_5GHZ)
  277. return 16; /* 802.11a */
  278. return 10; /* 802.11 b/g */
  279. }
  280. /**
  281. * ath5k_hw_set_lladdr - Set station id
  282. *
  283. * @ah: The &struct ath5k_hw
  284. * @mac: The card's mac address
  285. *
  286. * Set station id on hw using the provided mac address
  287. */
  288. int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
  289. {
  290. struct ath_common *common = ath5k_hw_common(ah);
  291. u32 low_id, high_id;
  292. u32 pcu_reg;
  293. ATH5K_TRACE(ah->ah_sc);
  294. /* Set new station ID */
  295. memcpy(common->macaddr, mac, ETH_ALEN);
  296. pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000;
  297. low_id = get_unaligned_le32(mac);
  298. high_id = get_unaligned_le16(mac + 4);
  299. ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
  300. ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
  301. return 0;
  302. }
  303. /**
  304. * ath5k_hw_set_associd - Set BSSID for association
  305. *
  306. * @ah: The &struct ath5k_hw
  307. * @bssid: BSSID
  308. * @assoc_id: Assoc id
  309. *
  310. * Sets the BSSID which trigers the "SME Join" operation
  311. */
  312. void ath5k_hw_set_associd(struct ath5k_hw *ah)
  313. {
  314. struct ath_common *common = ath5k_hw_common(ah);
  315. u16 tim_offset = 0;
  316. /*
  317. * Set simple BSSID mask on 5212
  318. */
  319. if (ah->ah_version == AR5K_AR5212)
  320. ath_hw_setbssidmask(common);
  321. /*
  322. * Set BSSID which triggers the "SME Join" operation
  323. */
  324. ath5k_hw_reg_write(ah,
  325. get_unaligned_le32(common->curbssid),
  326. AR5K_BSS_ID0);
  327. ath5k_hw_reg_write(ah,
  328. get_unaligned_le16(common->curbssid + 4) |
  329. ((common->curaid & 0x3fff) << AR5K_BSS_ID1_AID_S),
  330. AR5K_BSS_ID1);
  331. if (common->curaid == 0) {
  332. ath5k_hw_disable_pspoll(ah);
  333. return;
  334. }
  335. AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
  336. tim_offset ? tim_offset + 4 : 0);
  337. ath5k_hw_enable_pspoll(ah, NULL, 0);
  338. }
  339. void ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
  340. {
  341. struct ath_common *common = ath5k_hw_common(ah);
  342. ATH5K_TRACE(ah->ah_sc);
  343. /* Cache bssid mask so that we can restore it
  344. * on reset */
  345. memcpy(common->bssidmask, mask, ETH_ALEN);
  346. if (ah->ah_version == AR5K_AR5212)
  347. ath_hw_setbssidmask(common);
  348. }
  349. /************\
  350. * RX Control *
  351. \************/
  352. /**
  353. * ath5k_hw_start_rx_pcu - Start RX engine
  354. *
  355. * @ah: The &struct ath5k_hw
  356. *
  357. * Starts RX engine on PCU so that hw can process RXed frames
  358. * (ACK etc).
  359. *
  360. * NOTE: RX DMA should be already enabled using ath5k_hw_start_rx_dma
  361. * TODO: Init ANI here
  362. */
  363. void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
  364. {
  365. ATH5K_TRACE(ah->ah_sc);
  366. AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
  367. }
  368. /**
  369. * at5k_hw_stop_rx_pcu - Stop RX engine
  370. *
  371. * @ah: The &struct ath5k_hw
  372. *
  373. * Stops RX engine on PCU
  374. *
  375. * TODO: Detach ANI here
  376. */
  377. void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah)
  378. {
  379. ATH5K_TRACE(ah->ah_sc);
  380. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
  381. }
  382. /*
  383. * Set multicast filter
  384. */
  385. void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
  386. {
  387. ATH5K_TRACE(ah->ah_sc);
  388. /* Set the multicat filter */
  389. ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
  390. ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
  391. }
  392. #if 0
  393. /*
  394. * Set multicast filter by index
  395. */
  396. int ath5k_hw_set_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
  397. {
  398. ATH5K_TRACE(ah->ah_sc);
  399. if (index >= 64)
  400. return -EINVAL;
  401. else if (index >= 32)
  402. AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
  403. (1 << (index - 32)));
  404. else
  405. AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
  406. return 0;
  407. }
  408. /*
  409. * Clear Multicast filter by index
  410. */
  411. int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
  412. {
  413. ATH5K_TRACE(ah->ah_sc);
  414. if (index >= 64)
  415. return -EINVAL;
  416. else if (index >= 32)
  417. AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
  418. (1 << (index - 32)));
  419. else
  420. AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
  421. return 0;
  422. }
  423. #endif
  424. /**
  425. * ath5k_hw_get_rx_filter - Get current rx filter
  426. *
  427. * @ah: The &struct ath5k_hw
  428. *
  429. * Returns the RX filter by reading rx filter and
  430. * phy error filter registers. RX filter is used
  431. * to set the allowed frame types that PCU will accept
  432. * and pass to the driver. For a list of frame types
  433. * check out reg.h.
  434. */
  435. u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
  436. {
  437. u32 data, filter = 0;
  438. ATH5K_TRACE(ah->ah_sc);
  439. filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
  440. /*Radar detection for 5212*/
  441. if (ah->ah_version == AR5K_AR5212) {
  442. data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
  443. if (data & AR5K_PHY_ERR_FIL_RADAR)
  444. filter |= AR5K_RX_FILTER_RADARERR;
  445. if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
  446. filter |= AR5K_RX_FILTER_PHYERR;
  447. }
  448. return filter;
  449. }
  450. /**
  451. * ath5k_hw_set_rx_filter - Set rx filter
  452. *
  453. * @ah: The &struct ath5k_hw
  454. * @filter: RX filter mask (see reg.h)
  455. *
  456. * Sets RX filter register and also handles PHY error filter
  457. * register on 5212 and newer chips so that we have proper PHY
  458. * error reporting.
  459. */
  460. void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
  461. {
  462. u32 data = 0;
  463. ATH5K_TRACE(ah->ah_sc);
  464. /* Set PHY error filter register on 5212*/
  465. if (ah->ah_version == AR5K_AR5212) {
  466. if (filter & AR5K_RX_FILTER_RADARERR)
  467. data |= AR5K_PHY_ERR_FIL_RADAR;
  468. if (filter & AR5K_RX_FILTER_PHYERR)
  469. data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
  470. }
  471. /*
  472. * The AR5210 uses promiscous mode to detect radar activity
  473. */
  474. if (ah->ah_version == AR5K_AR5210 &&
  475. (filter & AR5K_RX_FILTER_RADARERR)) {
  476. filter &= ~AR5K_RX_FILTER_RADARERR;
  477. filter |= AR5K_RX_FILTER_PROM;
  478. }
  479. /*Zero length DMA (phy error reporting) */
  480. if (data)
  481. AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
  482. else
  483. AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
  484. /*Write RX Filter register*/
  485. ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
  486. /*Write PHY error filter register on 5212*/
  487. if (ah->ah_version == AR5K_AR5212)
  488. ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
  489. }
  490. /****************\
  491. * Beacon control *
  492. \****************/
  493. /**
  494. * ath5k_hw_get_tsf64 - Get the full 64bit TSF
  495. *
  496. * @ah: The &struct ath5k_hw
  497. *
  498. * Returns the current TSF
  499. */
  500. u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
  501. {
  502. u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
  503. ATH5K_TRACE(ah->ah_sc);
  504. return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
  505. }
  506. /**
  507. * ath5k_hw_set_tsf64 - Set a new 64bit TSF
  508. *
  509. * @ah: The &struct ath5k_hw
  510. * @tsf64: The new 64bit TSF
  511. *
  512. * Sets the new TSF
  513. */
  514. void ath5k_hw_set_tsf64(struct ath5k_hw *ah, u64 tsf64)
  515. {
  516. ATH5K_TRACE(ah->ah_sc);
  517. ath5k_hw_reg_write(ah, tsf64 & 0xffffffff, AR5K_TSF_L32);
  518. ath5k_hw_reg_write(ah, (tsf64 >> 32) & 0xffffffff, AR5K_TSF_U32);
  519. }
  520. /**
  521. * ath5k_hw_reset_tsf - Force a TSF reset
  522. *
  523. * @ah: The &struct ath5k_hw
  524. *
  525. * Forces a TSF reset on PCU
  526. */
  527. void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
  528. {
  529. u32 val;
  530. ATH5K_TRACE(ah->ah_sc);
  531. val = ath5k_hw_reg_read(ah, AR5K_BEACON) | AR5K_BEACON_RESET_TSF;
  532. /*
  533. * Each write to the RESET_TSF bit toggles a hardware internal
  534. * signal to reset TSF, but if left high it will cause a TSF reset
  535. * on the next chip reset as well. Thus we always write the value
  536. * twice to clear the signal.
  537. */
  538. ath5k_hw_reg_write(ah, val, AR5K_BEACON);
  539. ath5k_hw_reg_write(ah, val, AR5K_BEACON);
  540. }
  541. /*
  542. * Initialize beacon timers
  543. */
  544. void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
  545. {
  546. u32 timer1, timer2, timer3;
  547. ATH5K_TRACE(ah->ah_sc);
  548. /*
  549. * Set the additional timers by mode
  550. */
  551. switch (ah->ah_op_mode) {
  552. case NL80211_IFTYPE_MONITOR:
  553. case NL80211_IFTYPE_STATION:
  554. /* In STA mode timer1 is used as next wakeup
  555. * timer and timer2 as next CFP duration start
  556. * timer. Both in 1/8TUs. */
  557. /* TODO: PCF handling */
  558. if (ah->ah_version == AR5K_AR5210) {
  559. timer1 = 0xffffffff;
  560. timer2 = 0xffffffff;
  561. } else {
  562. timer1 = 0x0000ffff;
  563. timer2 = 0x0007ffff;
  564. }
  565. /* Mark associated AP as PCF incapable for now */
  566. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PCF);
  567. break;
  568. case NL80211_IFTYPE_ADHOC:
  569. AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_ADHOC_BCN_ATIM);
  570. default:
  571. /* On non-STA modes timer1 is used as next DMA
  572. * beacon alert (DBA) timer and timer2 as next
  573. * software beacon alert. Both in 1/8TUs. */
  574. timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
  575. timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
  576. break;
  577. }
  578. /* Timer3 marks the end of our ATIM window
  579. * a zero length window is not allowed because
  580. * we 'll get no beacons */
  581. timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
  582. /*
  583. * Set the beacon register and enable all timers.
  584. */
  585. /* When in AP or Mesh Point mode zero timer0 to start TSF */
  586. if (ah->ah_op_mode == NL80211_IFTYPE_AP ||
  587. ah->ah_op_mode == NL80211_IFTYPE_MESH_POINT)
  588. ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
  589. ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
  590. ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
  591. ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
  592. ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
  593. /* Force a TSF reset if requested and enable beacons */
  594. if (interval & AR5K_BEACON_RESET_TSF)
  595. ath5k_hw_reset_tsf(ah);
  596. ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
  597. AR5K_BEACON_ENABLE),
  598. AR5K_BEACON);
  599. /* Flush any pending BMISS interrupts on ISR by
  600. * performing a clear-on-write operation on PISR
  601. * register for the BMISS bit (writing a bit on
  602. * ISR togles a reset for that bit and leaves
  603. * the rest bits intact) */
  604. if (ah->ah_version == AR5K_AR5210)
  605. ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_ISR);
  606. else
  607. ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_PISR);
  608. /* TODO: Set enchanced sleep registers on AR5212
  609. * based on vif->bss_conf params, until then
  610. * disable power save reporting.*/
  611. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PWR_SV);
  612. }
  613. #if 0
  614. /*
  615. * Set beacon timers
  616. */
  617. int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
  618. const struct ath5k_beacon_state *state)
  619. {
  620. u32 cfp_period, next_cfp, dtim, interval, next_beacon;
  621. /*
  622. * TODO: should be changed through *state
  623. * review struct ath5k_beacon_state struct
  624. *
  625. * XXX: These are used for cfp period bellow, are they
  626. * ok ? Is it O.K. for tsf here to be 0 or should we use
  627. * get_tsf ?
  628. */
  629. u32 dtim_count = 0; /* XXX */
  630. u32 cfp_count = 0; /* XXX */
  631. u32 tsf = 0; /* XXX */
  632. ATH5K_TRACE(ah->ah_sc);
  633. /* Return on an invalid beacon state */
  634. if (state->bs_interval < 1)
  635. return -EINVAL;
  636. interval = state->bs_interval;
  637. dtim = state->bs_dtim_period;
  638. /*
  639. * PCF support?
  640. */
  641. if (state->bs_cfp_period > 0) {
  642. /*
  643. * Enable PCF mode and set the CFP
  644. * (Contention Free Period) and timer registers
  645. */
  646. cfp_period = state->bs_cfp_period * state->bs_dtim_period *
  647. state->bs_interval;
  648. next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
  649. state->bs_interval;
  650. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
  651. AR5K_STA_ID1_DEFAULT_ANTENNA |
  652. AR5K_STA_ID1_PCF);
  653. ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
  654. ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
  655. AR5K_CFP_DUR);
  656. ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
  657. next_cfp)) << 3, AR5K_TIMER2);
  658. } else {
  659. /* Disable PCF mode */
  660. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  661. AR5K_STA_ID1_DEFAULT_ANTENNA |
  662. AR5K_STA_ID1_PCF);
  663. }
  664. /*
  665. * Enable the beacon timer register
  666. */
  667. ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
  668. /*
  669. * Start the beacon timers
  670. */
  671. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &
  672. ~(AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
  673. AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
  674. AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
  675. AR5K_BEACON_PERIOD), AR5K_BEACON);
  676. /*
  677. * Write new beacon miss threshold, if it appears to be valid
  678. * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
  679. * and return if its not in range. We can test this by reading value and
  680. * setting value to a largest value and seeing which values register.
  681. */
  682. AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
  683. state->bs_bmiss_threshold);
  684. /*
  685. * Set sleep control register
  686. * XXX: Didn't find this in 5210 code but since this register
  687. * exists also in ar5k's 5210 headers i leave it as common code.
  688. */
  689. AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
  690. (state->bs_sleep_duration - 3) << 3);
  691. /*
  692. * Set enhanced sleep registers on 5212
  693. */
  694. if (ah->ah_version == AR5K_AR5212) {
  695. if (state->bs_sleep_duration > state->bs_interval &&
  696. roundup(state->bs_sleep_duration, interval) ==
  697. state->bs_sleep_duration)
  698. interval = state->bs_sleep_duration;
  699. if (state->bs_sleep_duration > dtim && (dtim == 0 ||
  700. roundup(state->bs_sleep_duration, dtim) ==
  701. state->bs_sleep_duration))
  702. dtim = state->bs_sleep_duration;
  703. if (interval > dtim)
  704. return -EINVAL;
  705. next_beacon = interval == dtim ? state->bs_next_dtim :
  706. state->bs_next_beacon;
  707. ath5k_hw_reg_write(ah,
  708. AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
  709. AR5K_SLEEP0_NEXT_DTIM) |
  710. AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
  711. AR5K_SLEEP0_ENH_SLEEP_EN |
  712. AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
  713. ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
  714. AR5K_SLEEP1_NEXT_TIM) |
  715. AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
  716. ath5k_hw_reg_write(ah,
  717. AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
  718. AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
  719. }
  720. return 0;
  721. }
  722. /*
  723. * Reset beacon timers
  724. */
  725. void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
  726. {
  727. ATH5K_TRACE(ah->ah_sc);
  728. /*
  729. * Disable beacon timer
  730. */
  731. ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
  732. /*
  733. * Disable some beacon register values
  734. */
  735. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  736. AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
  737. ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
  738. }
  739. /*
  740. * Wait for beacon queue to finish
  741. */
  742. int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
  743. {
  744. unsigned int i;
  745. int ret;
  746. ATH5K_TRACE(ah->ah_sc);
  747. /* 5210 doesn't have QCU*/
  748. if (ah->ah_version == AR5K_AR5210) {
  749. /*
  750. * Wait for beaconn queue to finish by checking
  751. * Control Register and Beacon Status Register.
  752. */
  753. for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
  754. if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
  755. ||
  756. !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
  757. break;
  758. udelay(10);
  759. }
  760. /* Timeout... */
  761. if (i <= 0) {
  762. /*
  763. * Re-schedule the beacon queue
  764. */
  765. ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
  766. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
  767. AR5K_BCR);
  768. return -EIO;
  769. }
  770. ret = 0;
  771. } else {
  772. /*5211/5212*/
  773. ret = ath5k_hw_register_timeout(ah,
  774. AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
  775. AR5K_QCU_STS_FRMPENDCNT, 0, false);
  776. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
  777. return -EIO;
  778. }
  779. return ret;
  780. }
  781. #endif
  782. /*********************\
  783. * Key table functions *
  784. \*********************/
  785. /*
  786. * Reset a key entry on the table
  787. */
  788. int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
  789. {
  790. unsigned int i, type;
  791. u16 micentry = entry + AR5K_KEYTABLE_MIC_OFFSET;
  792. ATH5K_TRACE(ah->ah_sc);
  793. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  794. type = ath5k_hw_reg_read(ah, AR5K_KEYTABLE_TYPE(entry));
  795. for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
  796. ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
  797. /* Reset associated MIC entry if TKIP
  798. * is enabled located at offset (entry + 64) */
  799. if (type == AR5K_KEYTABLE_TYPE_TKIP) {
  800. AR5K_ASSERT_ENTRY(micentry, AR5K_KEYTABLE_SIZE);
  801. for (i = 0; i < AR5K_KEYCACHE_SIZE / 2 ; i++)
  802. ath5k_hw_reg_write(ah, 0,
  803. AR5K_KEYTABLE_OFF(micentry, i));
  804. }
  805. /*
  806. * Set NULL encryption on AR5212+
  807. *
  808. * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5)
  809. * AR5K_KEYTABLE_TYPE_NULL -> 0x00000007
  810. *
  811. * Note2: Windows driver (ndiswrapper) sets this to
  812. * 0x00000714 instead of 0x00000007
  813. */
  814. if (ah->ah_version >= AR5K_AR5211) {
  815. ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
  816. AR5K_KEYTABLE_TYPE(entry));
  817. if (type == AR5K_KEYTABLE_TYPE_TKIP) {
  818. ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
  819. AR5K_KEYTABLE_TYPE(micentry));
  820. }
  821. }
  822. return 0;
  823. }
  824. #if 0
  825. /*
  826. * Check if a table entry is valid
  827. */
  828. int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
  829. {
  830. ATH5K_TRACE(ah->ah_sc);
  831. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  832. /* Check the validation flag at the end of the entry */
  833. return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
  834. AR5K_KEYTABLE_VALID;
  835. }
  836. #endif
  837. static
  838. int ath5k_keycache_type(const struct ieee80211_key_conf *key)
  839. {
  840. switch (key->alg) {
  841. case ALG_TKIP:
  842. return AR5K_KEYTABLE_TYPE_TKIP;
  843. case ALG_CCMP:
  844. return AR5K_KEYTABLE_TYPE_CCM;
  845. case ALG_WEP:
  846. if (key->keylen == WLAN_KEY_LEN_WEP40)
  847. return AR5K_KEYTABLE_TYPE_40;
  848. else if (key->keylen == WLAN_KEY_LEN_WEP104)
  849. return AR5K_KEYTABLE_TYPE_104;
  850. return -EINVAL;
  851. default:
  852. return -EINVAL;
  853. }
  854. return -EINVAL;
  855. }
  856. /*
  857. * Set a key entry on the table
  858. */
  859. int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
  860. const struct ieee80211_key_conf *key, const u8 *mac)
  861. {
  862. unsigned int i;
  863. int keylen;
  864. __le32 key_v[5] = {};
  865. __le32 key0 = 0, key1 = 0;
  866. __le32 *rxmic, *txmic;
  867. int keytype;
  868. u16 micentry = entry + AR5K_KEYTABLE_MIC_OFFSET;
  869. bool is_tkip;
  870. const u8 *key_ptr;
  871. ATH5K_TRACE(ah->ah_sc);
  872. is_tkip = (key->alg == ALG_TKIP);
  873. /*
  874. * key->keylen comes in from mac80211 in bytes.
  875. * TKIP is 128 bit + 128 bit mic
  876. */
  877. keylen = (is_tkip) ? (128 / 8) : key->keylen;
  878. if (entry > AR5K_KEYTABLE_SIZE ||
  879. (is_tkip && micentry > AR5K_KEYTABLE_SIZE))
  880. return -EOPNOTSUPP;
  881. if (unlikely(keylen > 16))
  882. return -EOPNOTSUPP;
  883. keytype = ath5k_keycache_type(key);
  884. if (keytype < 0)
  885. return keytype;
  886. /*
  887. * each key block is 6 bytes wide, written as pairs of
  888. * alternating 32 and 16 bit le values.
  889. */
  890. key_ptr = key->key;
  891. for (i = 0; keylen >= 6; keylen -= 6) {
  892. memcpy(&key_v[i], key_ptr, 6);
  893. i += 2;
  894. key_ptr += 6;
  895. }
  896. if (keylen)
  897. memcpy(&key_v[i], key_ptr, keylen);
  898. /* intentionally corrupt key until mic is installed */
  899. if (is_tkip) {
  900. key0 = key_v[0] = ~key_v[0];
  901. key1 = key_v[1] = ~key_v[1];
  902. }
  903. for (i = 0; i < ARRAY_SIZE(key_v); i++)
  904. ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
  905. AR5K_KEYTABLE_OFF(entry, i));
  906. ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
  907. if (is_tkip) {
  908. /* Install rx/tx MIC */
  909. rxmic = (__le32 *) &key->key[16];
  910. txmic = (__le32 *) &key->key[24];
  911. if (ah->ah_combined_mic) {
  912. key_v[0] = rxmic[0];
  913. key_v[1] = cpu_to_le32(le32_to_cpu(txmic[0]) >> 16);
  914. key_v[2] = rxmic[1];
  915. key_v[3] = cpu_to_le32(le32_to_cpu(txmic[0]) & 0xffff);
  916. key_v[4] = txmic[1];
  917. } else {
  918. key_v[0] = rxmic[0];
  919. key_v[1] = 0;
  920. key_v[2] = rxmic[1];
  921. key_v[3] = 0;
  922. key_v[4] = 0;
  923. }
  924. for (i = 0; i < ARRAY_SIZE(key_v); i++)
  925. ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
  926. AR5K_KEYTABLE_OFF(micentry, i));
  927. ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
  928. AR5K_KEYTABLE_TYPE(micentry));
  929. ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_MAC0(micentry));
  930. ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_MAC1(micentry));
  931. /* restore first 2 words of key */
  932. ath5k_hw_reg_write(ah, le32_to_cpu(~key0),
  933. AR5K_KEYTABLE_OFF(entry, 0));
  934. ath5k_hw_reg_write(ah, le32_to_cpu(~key1),
  935. AR5K_KEYTABLE_OFF(entry, 1));
  936. }
  937. return ath5k_hw_set_key_lladdr(ah, entry, mac);
  938. }
  939. int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
  940. {
  941. u32 low_id, high_id;
  942. ATH5K_TRACE(ah->ah_sc);
  943. /* Invalid entry (key table overflow) */
  944. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  945. /*
  946. * MAC may be NULL if it's a broadcast key. In this case no need to
  947. * to compute get_unaligned_le32 and get_unaligned_le16 as we
  948. * already know it.
  949. */
  950. if (!mac) {
  951. low_id = 0xffffffff;
  952. high_id = 0xffff | AR5K_KEYTABLE_VALID;
  953. } else {
  954. low_id = get_unaligned_le32(mac);
  955. high_id = get_unaligned_le16(mac + 4) | AR5K_KEYTABLE_VALID;
  956. }
  957. ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
  958. ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
  959. return 0;
  960. }
  961. /**
  962. * ath5k_hw_set_coverage_class - Set IEEE 802.11 coverage class
  963. *
  964. * @ah: The &struct ath5k_hw
  965. * @coverage_class: IEEE 802.11 coverage class number
  966. *
  967. * Sets slot time, ACK timeout and CTS timeout for given coverage class.
  968. */
  969. void ath5k_hw_set_coverage_class(struct ath5k_hw *ah, u8 coverage_class)
  970. {
  971. /* As defined by IEEE 802.11-2007 17.3.8.6 */
  972. int slot_time = ath5k_hw_get_default_slottime(ah) + 3 * coverage_class;
  973. int ack_timeout = ath5k_hw_get_default_sifs(ah) + slot_time;
  974. int cts_timeout = ack_timeout;
  975. ath5k_hw_set_slot_time(ah, slot_time);
  976. ath5k_hw_set_ack_timeout(ah, ack_timeout);
  977. ath5k_hw_set_cts_timeout(ah, cts_timeout);
  978. ah->ah_coverage_class = coverage_class;
  979. }