desc.c 19 KB

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