desc.c 19 KB

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