desc.c 18 KB

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