desc.c 19 KB

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