pcu.c 29 KB

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