desc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. /*
  268. * Proccess the tx status descriptor on 5210/5211
  269. */
  270. static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
  271. struct ath5k_desc *desc, struct ath5k_tx_status *ts)
  272. {
  273. struct ath5k_hw_2w_tx_ctl *tx_ctl;
  274. struct ath5k_hw_tx_status *tx_status;
  275. ATH5K_TRACE(ah->ah_sc);
  276. tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
  277. tx_status = &desc->ud.ds_tx5210.tx_stat;
  278. /* No frame has been send or error */
  279. if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
  280. return -EINPROGRESS;
  281. /*
  282. * Get descriptor status
  283. */
  284. ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
  285. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  286. ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
  287. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  288. ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
  289. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  290. /*TODO: ts->ts_virtcol + test*/
  291. ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
  292. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  293. ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
  294. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  295. ts->ts_antenna = 1;
  296. ts->ts_status = 0;
  297. ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_0,
  298. AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
  299. if (!(tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
  300. if (tx_status->tx_status_0 &
  301. AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  302. ts->ts_status |= AR5K_TXERR_XRETRY;
  303. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  304. ts->ts_status |= AR5K_TXERR_FIFO;
  305. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
  306. ts->ts_status |= AR5K_TXERR_FILT;
  307. }
  308. return 0;
  309. }
  310. /*
  311. * Proccess a tx status descriptor on 5212
  312. */
  313. static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
  314. struct ath5k_desc *desc, struct ath5k_tx_status *ts)
  315. {
  316. struct ath5k_hw_4w_tx_ctl *tx_ctl;
  317. struct ath5k_hw_tx_status *tx_status;
  318. ATH5K_TRACE(ah->ah_sc);
  319. tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
  320. tx_status = &desc->ud.ds_tx5212.tx_stat;
  321. /* No frame has been send or error */
  322. if (unlikely(!(tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE)))
  323. return -EINPROGRESS;
  324. /*
  325. * Get descriptor status
  326. */
  327. ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
  328. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  329. ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
  330. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  331. ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
  332. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  333. ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
  334. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  335. ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
  336. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  337. ts->ts_antenna = (tx_status->tx_status_1 &
  338. AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
  339. ts->ts_status = 0;
  340. switch (AR5K_REG_MS(tx_status->tx_status_1,
  341. AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
  342. case 0:
  343. ts->ts_rate = tx_ctl->tx_control_3 &
  344. AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
  345. break;
  346. case 1:
  347. ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
  348. AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
  349. ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
  350. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
  351. break;
  352. case 2:
  353. ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
  354. AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
  355. ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
  356. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
  357. break;
  358. case 3:
  359. ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
  360. AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
  361. ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
  362. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
  363. break;
  364. }
  365. /* TX error */
  366. if (!(tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK)) {
  367. if (tx_status->tx_status_0 &
  368. AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  369. ts->ts_status |= AR5K_TXERR_XRETRY;
  370. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  371. ts->ts_status |= AR5K_TXERR_FIFO;
  372. if (tx_status->tx_status_0 & 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. static 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. ATH5K_TRACE(ah->ah_sc);
  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. /* Setup descriptor */
  398. rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
  399. if (unlikely(rx_ctl->rx_control_1 != size))
  400. return -EINVAL;
  401. if (flags & AR5K_RXDESC_INTREQ)
  402. rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
  403. return 0;
  404. }
  405. /*
  406. * Proccess 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.u.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. /*
  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_antenna = rx_status->rx_status_0 &
  427. AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA;
  428. rs->rs_more = rx_status->rx_status_0 &
  429. AR5K_5210_RX_DESC_STATUS0_MORE;
  430. /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
  431. rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
  432. AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  433. rs->rs_status = 0;
  434. rs->rs_phyerr = 0;
  435. /*
  436. * Key table status
  437. */
  438. if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
  439. rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
  440. AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
  441. else
  442. rs->rs_keyix = AR5K_RXKEYIX_INVALID;
  443. /*
  444. * Receive/descriptor errors
  445. */
  446. if (!(rx_status->rx_status_1 &
  447. AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
  448. if (rx_status->rx_status_1 &
  449. AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
  450. rs->rs_status |= AR5K_RXERR_CRC;
  451. if (rx_status->rx_status_1 &
  452. AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN)
  453. rs->rs_status |= AR5K_RXERR_FIFO;
  454. if (rx_status->rx_status_1 &
  455. AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
  456. rs->rs_status |= AR5K_RXERR_PHY;
  457. rs->rs_phyerr |= AR5K_REG_MS(rx_status->rx_status_1,
  458. AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
  459. }
  460. if (rx_status->rx_status_1 &
  461. AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  462. rs->rs_status |= AR5K_RXERR_DECRYPT;
  463. }
  464. return 0;
  465. }
  466. /*
  467. * Proccess the rx status descriptor on 5212
  468. */
  469. static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
  470. struct ath5k_desc *desc, struct ath5k_rx_status *rs)
  471. {
  472. struct ath5k_hw_rx_status *rx_status;
  473. struct ath5k_hw_rx_error *rx_err;
  474. ATH5K_TRACE(ah->ah_sc);
  475. rx_status = &desc->ud.ds_rx.u.rx_stat;
  476. /* Overlay on error */
  477. rx_err = &desc->ud.ds_rx.u.rx_err;
  478. /* No frame received / not ready */
  479. if (unlikely(!(rx_status->rx_status_1 &
  480. AR5K_5212_RX_DESC_STATUS1_DONE)))
  481. return -EINPROGRESS;
  482. /*
  483. * Frame receive status
  484. */
  485. rs->rs_datalen = rx_status->rx_status_0 &
  486. AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
  487. rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
  488. AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
  489. rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
  490. AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
  491. rs->rs_antenna = rx_status->rx_status_0 &
  492. AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA;
  493. rs->rs_more = rx_status->rx_status_0 &
  494. AR5K_5212_RX_DESC_STATUS0_MORE;
  495. rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
  496. AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  497. rs->rs_status = 0;
  498. rs->rs_phyerr = 0;
  499. /*
  500. * Key table status
  501. */
  502. if (rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
  503. rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
  504. AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
  505. else
  506. rs->rs_keyix = AR5K_RXKEYIX_INVALID;
  507. /*
  508. * Receive/descriptor errors
  509. */
  510. if (!(rx_status->rx_status_1 &
  511. AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK)) {
  512. if (rx_status->rx_status_1 &
  513. AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
  514. rs->rs_status |= AR5K_RXERR_CRC;
  515. if (rx_status->rx_status_1 &
  516. AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
  517. rs->rs_status |= AR5K_RXERR_PHY;
  518. rs->rs_phyerr |= AR5K_REG_MS(rx_err->rx_error_1,
  519. AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
  520. }
  521. if (rx_status->rx_status_1 &
  522. AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  523. rs->rs_status |= AR5K_RXERR_DECRYPT;
  524. if (rx_status->rx_status_1 &
  525. AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
  526. rs->rs_status |= AR5K_RXERR_MIC;
  527. }
  528. return 0;
  529. }
  530. /*
  531. * Init function pointers inside ath5k_hw struct
  532. */
  533. int ath5k_hw_init_desc_functions(struct ath5k_hw *ah)
  534. {
  535. if (ah->ah_version != AR5K_AR5210 &&
  536. ah->ah_version != AR5K_AR5211 &&
  537. ah->ah_version != AR5K_AR5212)
  538. return -ENOTSUPP;
  539. /* XXX: What is this magic value and where is it used ? */
  540. if (ah->ah_version == AR5K_AR5212)
  541. ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
  542. else if (ah->ah_version == AR5K_AR5211)
  543. ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
  544. if (ah->ah_version == AR5K_AR5212) {
  545. ah->ah_setup_rx_desc = ath5k_hw_setup_rx_desc;
  546. ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
  547. ah->ah_setup_mrr_tx_desc = ath5k_hw_setup_mrr_tx_desc;
  548. ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
  549. } else {
  550. ah->ah_setup_rx_desc = ath5k_hw_setup_rx_desc;
  551. ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
  552. ah->ah_setup_mrr_tx_desc = ath5k_hw_setup_mrr_tx_desc;
  553. ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
  554. }
  555. if (ah->ah_version == AR5K_AR5212)
  556. ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
  557. else if (ah->ah_version <= AR5K_AR5211)
  558. ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
  559. return 0;
  560. }