desc.c 19 KB

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