desc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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 Pavel Roskin <proski@gnu.org>
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. *
  18. */
  19. /******************************\
  20. Hardware Descriptor Functions
  21. \******************************/
  22. #include "ath5k.h"
  23. #include "reg.h"
  24. #include "debug.h"
  25. #include "base.h"
  26. /************************\
  27. * TX Control descriptors *
  28. \************************/
  29. /*
  30. * Initialize the 2-word tx control descriptor on 5210/5211
  31. */
  32. static int
  33. ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  34. unsigned int pkt_len, unsigned int hdr_len, int padsize,
  35. enum ath5k_pkt_type type,
  36. unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
  37. unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
  38. unsigned int rtscts_rate, unsigned int rtscts_duration)
  39. {
  40. u32 frame_type;
  41. struct ath5k_hw_2w_tx_ctl *tx_ctl;
  42. unsigned int frame_len;
  43. tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
  44. /*
  45. * Validate input
  46. * - Zero retries don't make sense.
  47. * - A zero rate will put the HW into a mode where it continuously sends
  48. * noise on the channel, so it is important to avoid this.
  49. */
  50. if (unlikely(tx_tries0 == 0)) {
  51. ATH5K_ERR(ah, "zero retries\n");
  52. WARN_ON(1);
  53. return -EINVAL;
  54. }
  55. if (unlikely(tx_rate0 == 0)) {
  56. ATH5K_ERR(ah, "zero rate\n");
  57. WARN_ON(1);
  58. return -EINVAL;
  59. }
  60. /* Clear descriptor */
  61. memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
  62. /* Setup control descriptor */
  63. /* Verify and set frame length */
  64. /* remove padding we might have added before */
  65. frame_len = pkt_len - padsize + FCS_LEN;
  66. if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
  67. return -EINVAL;
  68. tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
  69. /* Verify and set buffer length */
  70. /* NB: beacon's BufLen must be a multiple of 4 bytes */
  71. if (type == AR5K_PKT_TYPE_BEACON)
  72. pkt_len = roundup(pkt_len, 4);
  73. if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
  74. return -EINVAL;
  75. tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
  76. /*
  77. * Verify and set header length (only 5210)
  78. */
  79. if (ah->ah_version == AR5K_AR5210) {
  80. if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN_5210)
  81. return -EINVAL;
  82. tx_ctl->tx_control_0 |=
  83. AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN_5210);
  84. }
  85. /*Differences between 5210-5211*/
  86. if (ah->ah_version == AR5K_AR5210) {
  87. switch (type) {
  88. case AR5K_PKT_TYPE_BEACON:
  89. case AR5K_PKT_TYPE_PROBE_RESP:
  90. frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
  91. break;
  92. case AR5K_PKT_TYPE_PIFS:
  93. frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
  94. break;
  95. default:
  96. frame_type = type;
  97. break;
  98. }
  99. tx_ctl->tx_control_0 |=
  100. AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE_5210) |
  101. AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
  102. } else {
  103. tx_ctl->tx_control_0 |=
  104. AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
  105. AR5K_REG_SM(antenna_mode,
  106. AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
  107. tx_ctl->tx_control_1 |=
  108. AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE_5211);
  109. }
  110. #define _TX_FLAGS(_c, _flag) \
  111. if (flags & AR5K_TXDESC_##_flag) { \
  112. tx_ctl->tx_control_##_c |= \
  113. AR5K_2W_TX_DESC_CTL##_c##_##_flag; \
  114. }
  115. #define _TX_FLAGS_5211(_c, _flag) \
  116. if (flags & AR5K_TXDESC_##_flag) { \
  117. tx_ctl->tx_control_##_c |= \
  118. AR5K_2W_TX_DESC_CTL##_c##_##_flag##_5211; \
  119. }
  120. _TX_FLAGS(0, CLRDMASK);
  121. _TX_FLAGS(0, INTREQ);
  122. _TX_FLAGS(0, RTSENA);
  123. if (ah->ah_version == AR5K_AR5211) {
  124. _TX_FLAGS_5211(0, VEOL);
  125. _TX_FLAGS_5211(1, NOACK);
  126. }
  127. #undef _TX_FLAGS
  128. #undef _TX_FLAGS_5211
  129. /*
  130. * WEP crap
  131. */
  132. if (key_index != AR5K_TXKEYIX_INVALID) {
  133. tx_ctl->tx_control_0 |=
  134. AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
  135. tx_ctl->tx_control_1 |=
  136. AR5K_REG_SM(key_index,
  137. AR5K_2W_TX_DESC_CTL1_ENC_KEY_IDX);
  138. }
  139. /*
  140. * RTS/CTS Duration [5210 ?]
  141. */
  142. if ((ah->ah_version == AR5K_AR5210) &&
  143. (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
  144. tx_ctl->tx_control_1 |= rtscts_duration &
  145. AR5K_2W_TX_DESC_CTL1_RTS_DURATION_5210;
  146. return 0;
  147. }
  148. /*
  149. * Initialize the 4-word tx control descriptor on 5212
  150. */
  151. static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
  152. struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
  153. int padsize,
  154. enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
  155. unsigned int tx_tries0, unsigned int key_index,
  156. unsigned int antenna_mode, unsigned int flags,
  157. unsigned int rtscts_rate,
  158. unsigned int rtscts_duration)
  159. {
  160. struct ath5k_hw_4w_tx_ctl *tx_ctl;
  161. unsigned int frame_len;
  162. /*
  163. * Use local variables for these to reduce load/store access on
  164. * uncached memory
  165. */
  166. u32 txctl0 = 0, txctl1 = 0, txctl2 = 0, txctl3 = 0;
  167. tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
  168. /*
  169. * Validate input
  170. * - Zero retries don't make sense.
  171. * - A zero rate will put the HW into a mode where it continuously sends
  172. * noise on the channel, so it is important to avoid this.
  173. */
  174. if (unlikely(tx_tries0 == 0)) {
  175. ATH5K_ERR(ah, "zero retries\n");
  176. WARN_ON(1);
  177. return -EINVAL;
  178. }
  179. if (unlikely(tx_rate0 == 0)) {
  180. ATH5K_ERR(ah, "zero rate\n");
  181. WARN_ON(1);
  182. return -EINVAL;
  183. }
  184. tx_power += ah->ah_txpower.txp_offset;
  185. if (tx_power > AR5K_TUNE_MAX_TXPOWER)
  186. tx_power = AR5K_TUNE_MAX_TXPOWER;
  187. /* Clear descriptor status area */
  188. memset(&desc->ud.ds_tx5212.tx_stat, 0,
  189. sizeof(desc->ud.ds_tx5212.tx_stat));
  190. /* Setup control descriptor */
  191. /* Verify and set frame length */
  192. /* remove padding we might have added before */
  193. frame_len = pkt_len - padsize + FCS_LEN;
  194. if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
  195. return -EINVAL;
  196. txctl0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
  197. /* Verify and set buffer length */
  198. /* NB: beacon's BufLen must be a multiple of 4 bytes */
  199. if (type == AR5K_PKT_TYPE_BEACON)
  200. pkt_len = roundup(pkt_len, 4);
  201. if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
  202. return -EINVAL;
  203. txctl1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
  204. txctl0 |= AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
  205. AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
  206. txctl1 |= AR5K_REG_SM(type, AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
  207. txctl2 = AR5K_REG_SM(tx_tries0, AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
  208. txctl3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
  209. #define _TX_FLAGS(_c, _flag) \
  210. if (flags & AR5K_TXDESC_##_flag) { \
  211. txctl##_c |= AR5K_4W_TX_DESC_CTL##_c##_##_flag; \
  212. }
  213. _TX_FLAGS(0, CLRDMASK);
  214. _TX_FLAGS(0, VEOL);
  215. _TX_FLAGS(0, INTREQ);
  216. _TX_FLAGS(0, RTSENA);
  217. _TX_FLAGS(0, CTSENA);
  218. _TX_FLAGS(1, NOACK);
  219. #undef _TX_FLAGS
  220. /*
  221. * WEP crap
  222. */
  223. if (key_index != AR5K_TXKEYIX_INVALID) {
  224. txctl0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
  225. txctl1 |= AR5K_REG_SM(key_index,
  226. AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_IDX);
  227. }
  228. /*
  229. * RTS/CTS
  230. */
  231. if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
  232. if ((flags & AR5K_TXDESC_RTSENA) &&
  233. (flags & AR5K_TXDESC_CTSENA))
  234. return -EINVAL;
  235. txctl2 |= rtscts_duration & AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
  236. txctl3 |= AR5K_REG_SM(rtscts_rate,
  237. AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
  238. }
  239. tx_ctl->tx_control_0 = txctl0;
  240. tx_ctl->tx_control_1 = txctl1;
  241. tx_ctl->tx_control_2 = txctl2;
  242. tx_ctl->tx_control_3 = txctl3;
  243. return 0;
  244. }
  245. /*
  246. * Initialize a 4-word multi rate retry tx control descriptor on 5212
  247. */
  248. int
  249. ath5k_hw_setup_mrr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  250. unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2,
  251. u_int tx_tries2, unsigned int tx_rate3, u_int tx_tries3)
  252. {
  253. struct ath5k_hw_4w_tx_ctl *tx_ctl;
  254. /* no mrr support for cards older than 5212 */
  255. if (ah->ah_version < AR5K_AR5212)
  256. return 0;
  257. /*
  258. * Rates can be 0 as long as the retry count is 0 too.
  259. * A zero rate and nonzero retry count will put the HW into a mode where
  260. * it continuously sends noise on the channel, so it is important to
  261. * avoid this.
  262. */
  263. if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
  264. (tx_rate2 == 0 && tx_tries2 != 0) ||
  265. (tx_rate3 == 0 && tx_tries3 != 0))) {
  266. ATH5K_ERR(ah, "zero rate\n");
  267. WARN_ON(1);
  268. return -EINVAL;
  269. }
  270. if (ah->ah_version == AR5K_AR5212) {
  271. tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
  272. #define _XTX_TRIES(_n) \
  273. if (tx_tries##_n) { \
  274. tx_ctl->tx_control_2 |= \
  275. AR5K_REG_SM(tx_tries##_n, \
  276. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
  277. tx_ctl->tx_control_3 |= \
  278. AR5K_REG_SM(tx_rate##_n, \
  279. AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
  280. }
  281. _XTX_TRIES(1);
  282. _XTX_TRIES(2);
  283. _XTX_TRIES(3);
  284. #undef _XTX_TRIES
  285. return 1;
  286. }
  287. return 0;
  288. }
  289. /***********************\
  290. * TX Status descriptors *
  291. \***********************/
  292. /*
  293. * Process the tx status descriptor on 5210/5211
  294. */
  295. static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
  296. struct ath5k_desc *desc, struct ath5k_tx_status *ts)
  297. {
  298. struct ath5k_hw_2w_tx_ctl *tx_ctl;
  299. struct ath5k_hw_tx_status *tx_status;
  300. tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
  301. tx_status = &desc->ud.ds_tx5210.tx_stat;
  302. /* No frame has been send or error */
  303. if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
  304. return -EINPROGRESS;
  305. /*
  306. * Get descriptor status
  307. */
  308. ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
  309. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  310. ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
  311. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  312. ts->ts_final_retry = AR5K_REG_MS(tx_status->tx_status_0,
  313. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  314. /*TODO: ts->ts_virtcol + test*/
  315. ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
  316. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  317. ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
  318. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  319. ts->ts_antenna = 1;
  320. ts->ts_status = 0;
  321. ts->ts_final_idx = 0;
  322. if (!(tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
  323. if (tx_status->tx_status_0 &
  324. AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  325. ts->ts_status |= AR5K_TXERR_XRETRY;
  326. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  327. ts->ts_status |= AR5K_TXERR_FIFO;
  328. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
  329. ts->ts_status |= AR5K_TXERR_FILT;
  330. }
  331. return 0;
  332. }
  333. /*
  334. * Process a tx status descriptor on 5212
  335. */
  336. static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
  337. struct ath5k_desc *desc, struct ath5k_tx_status *ts)
  338. {
  339. struct ath5k_hw_4w_tx_ctl *tx_ctl;
  340. struct ath5k_hw_tx_status *tx_status;
  341. u32 txstat0, txstat1;
  342. tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
  343. tx_status = &desc->ud.ds_tx5212.tx_stat;
  344. txstat1 = ACCESS_ONCE(tx_status->tx_status_1);
  345. /* No frame has been send or error */
  346. if (unlikely(!(txstat1 & AR5K_DESC_TX_STATUS1_DONE)))
  347. return -EINPROGRESS;
  348. txstat0 = ACCESS_ONCE(tx_status->tx_status_0);
  349. /*
  350. * Get descriptor status
  351. */
  352. ts->ts_tstamp = AR5K_REG_MS(txstat0,
  353. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  354. ts->ts_shortretry = AR5K_REG_MS(txstat0,
  355. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  356. ts->ts_final_retry = AR5K_REG_MS(txstat0,
  357. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  358. ts->ts_seqnum = AR5K_REG_MS(txstat1,
  359. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  360. ts->ts_rssi = AR5K_REG_MS(txstat1,
  361. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  362. ts->ts_antenna = (txstat1 &
  363. AR5K_DESC_TX_STATUS1_XMIT_ANTENNA_5212) ? 2 : 1;
  364. ts->ts_status = 0;
  365. ts->ts_final_idx = AR5K_REG_MS(txstat1,
  366. AR5K_DESC_TX_STATUS1_FINAL_TS_IX_5212);
  367. /* TX error */
  368. if (!(txstat0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
  369. if (txstat0 & AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  370. ts->ts_status |= AR5K_TXERR_XRETRY;
  371. if (txstat0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  372. ts->ts_status |= AR5K_TXERR_FIFO;
  373. if (txstat0 & AR5K_DESC_TX_STATUS0_FILTERED)
  374. ts->ts_status |= AR5K_TXERR_FILT;
  375. }
  376. return 0;
  377. }
  378. /****************\
  379. * RX Descriptors *
  380. \****************/
  381. /*
  382. * Initialize an rx control descriptor
  383. */
  384. int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  385. u32 size, unsigned int flags)
  386. {
  387. struct ath5k_hw_rx_ctl *rx_ctl;
  388. rx_ctl = &desc->ud.ds_rx.rx_ctl;
  389. /*
  390. * Clear the descriptor
  391. * If we don't clean the status descriptor,
  392. * while scanning we get too many results,
  393. * most of them virtual, after some secs
  394. * of scanning system hangs. M.F.
  395. */
  396. memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
  397. if (unlikely(size & ~AR5K_DESC_RX_CTL1_BUF_LEN))
  398. return -EINVAL;
  399. /* Setup descriptor */
  400. rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
  401. if (flags & AR5K_RXDESC_INTREQ)
  402. rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
  403. return 0;
  404. }
  405. /*
  406. * Process the rx status descriptor on 5210/5211
  407. */
  408. static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
  409. struct ath5k_desc *desc, struct ath5k_rx_status *rs)
  410. {
  411. struct ath5k_hw_rx_status *rx_status;
  412. rx_status = &desc->ud.ds_rx.rx_stat;
  413. /* No frame received / not ready */
  414. if (unlikely(!(rx_status->rx_status_1 &
  415. AR5K_5210_RX_DESC_STATUS1_DONE)))
  416. return -EINPROGRESS;
  417. memset(rs, 0, sizeof(struct ath5k_rx_status));
  418. /*
  419. * Frame receive status
  420. */
  421. rs->rs_datalen = rx_status->rx_status_0 &
  422. AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
  423. rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
  424. AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
  425. rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
  426. AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
  427. rs->rs_more = !!(rx_status->rx_status_0 &
  428. AR5K_5210_RX_DESC_STATUS0_MORE);
  429. /* TODO: this timestamp is 13 bit, later on we assume 15 bit!
  430. * also the HAL code for 5210 says the timestamp is bits [10..22] of the
  431. * TSF, and extends the timestamp here to 15 bit.
  432. * we need to check on 5210...
  433. */
  434. rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
  435. AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  436. if (ah->ah_version == AR5K_AR5211)
  437. rs->rs_antenna = AR5K_REG_MS(rx_status->rx_status_0,
  438. AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANT_5211);
  439. else
  440. rs->rs_antenna = (rx_status->rx_status_0 &
  441. AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANT_5210)
  442. ? 2 : 1;
  443. /*
  444. * Key table status
  445. */
  446. if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
  447. rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
  448. AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
  449. else
  450. rs->rs_keyix = AR5K_RXKEYIX_INVALID;
  451. /*
  452. * Receive/descriptor errors
  453. */
  454. if (!(rx_status->rx_status_1 &
  455. AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
  456. if (rx_status->rx_status_1 &
  457. AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
  458. rs->rs_status |= AR5K_RXERR_CRC;
  459. /* only on 5210 */
  460. if ((ah->ah_version == AR5K_AR5210) &&
  461. (rx_status->rx_status_1 &
  462. AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN_5210))
  463. rs->rs_status |= AR5K_RXERR_FIFO;
  464. if (rx_status->rx_status_1 &
  465. AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
  466. rs->rs_status |= AR5K_RXERR_PHY;
  467. rs->rs_phyerr = AR5K_REG_MS(rx_status->rx_status_1,
  468. AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
  469. }
  470. if (rx_status->rx_status_1 &
  471. AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  472. rs->rs_status |= AR5K_RXERR_DECRYPT;
  473. }
  474. return 0;
  475. }
  476. /*
  477. * Process the rx status descriptor on 5212
  478. */
  479. static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
  480. struct ath5k_desc *desc,
  481. struct ath5k_rx_status *rs)
  482. {
  483. struct ath5k_hw_rx_status *rx_status;
  484. u32 rxstat0, rxstat1;
  485. rx_status = &desc->ud.ds_rx.rx_stat;
  486. rxstat1 = ACCESS_ONCE(rx_status->rx_status_1);
  487. /* No frame received / not ready */
  488. if (unlikely(!(rxstat1 & AR5K_5212_RX_DESC_STATUS1_DONE)))
  489. return -EINPROGRESS;
  490. memset(rs, 0, sizeof(struct ath5k_rx_status));
  491. rxstat0 = ACCESS_ONCE(rx_status->rx_status_0);
  492. /*
  493. * Frame receive status
  494. */
  495. rs->rs_datalen = rxstat0 & AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
  496. rs->rs_rssi = AR5K_REG_MS(rxstat0,
  497. AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
  498. rs->rs_rate = AR5K_REG_MS(rxstat0,
  499. AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
  500. rs->rs_antenna = AR5K_REG_MS(rxstat0,
  501. AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA);
  502. rs->rs_more = !!(rxstat0 & AR5K_5212_RX_DESC_STATUS0_MORE);
  503. rs->rs_tstamp = AR5K_REG_MS(rxstat1,
  504. AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  505. /*
  506. * Key table status
  507. */
  508. if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
  509. rs->rs_keyix = AR5K_REG_MS(rxstat1,
  510. AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
  511. else
  512. rs->rs_keyix = AR5K_RXKEYIX_INVALID;
  513. /*
  514. * Receive/descriptor errors
  515. */
  516. if (!(rxstat1 & AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
  517. if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
  518. rs->rs_status |= AR5K_RXERR_CRC;
  519. if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
  520. rs->rs_status |= AR5K_RXERR_PHY;
  521. rs->rs_phyerr = AR5K_REG_MS(rxstat1,
  522. AR5K_5212_RX_DESC_STATUS1_PHY_ERROR_CODE);
  523. if (!ah->ah_capabilities.cap_has_phyerr_counters)
  524. ath5k_ani_phy_error_report(ah, rs->rs_phyerr);
  525. }
  526. if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  527. rs->rs_status |= AR5K_RXERR_DECRYPT;
  528. if (rxstat1 & AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
  529. rs->rs_status |= AR5K_RXERR_MIC;
  530. }
  531. return 0;
  532. }
  533. /********\
  534. * Attach *
  535. \********/
  536. /*
  537. * Init function pointers inside ath5k_hw struct
  538. */
  539. int ath5k_hw_init_desc_functions(struct ath5k_hw *ah)
  540. {
  541. if (ah->ah_version == AR5K_AR5212) {
  542. ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
  543. ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
  544. ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
  545. } else if (ah->ah_version <= AR5K_AR5211) {
  546. ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
  547. ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
  548. ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
  549. } else
  550. return -ENOTSUPP;
  551. return 0;
  552. }