iwl-helpers.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #ifndef __il_helpers_h__
  30. #define __il_helpers_h__
  31. #include <linux/ctype.h>
  32. #include <net/mac80211.h>
  33. #include "iwl-io.h"
  34. /**
  35. * il_queue_inc_wrap - increment queue idx, wrap back to beginning
  36. * @idx -- current idx
  37. * @n_bd -- total number of entries in queue (must be power of 2)
  38. */
  39. static inline int il_queue_inc_wrap(int idx, int n_bd)
  40. {
  41. return ++idx & (n_bd - 1);
  42. }
  43. /**
  44. * il_queue_dec_wrap - decrement queue idx, wrap back to end
  45. * @idx -- current idx
  46. * @n_bd -- total number of entries in queue (must be power of 2)
  47. */
  48. static inline int il_queue_dec_wrap(int idx, int n_bd)
  49. {
  50. return --idx & (n_bd - 1);
  51. }
  52. /* TODO: Move fw_desc functions to iwl-pci.ko */
  53. static inline void il_free_fw_desc(struct pci_dev *pci_dev,
  54. struct fw_desc *desc)
  55. {
  56. if (desc->v_addr)
  57. dma_free_coherent(&pci_dev->dev, desc->len,
  58. desc->v_addr, desc->p_addr);
  59. desc->v_addr = NULL;
  60. desc->len = 0;
  61. }
  62. static inline int il_alloc_fw_desc(struct pci_dev *pci_dev,
  63. struct fw_desc *desc)
  64. {
  65. if (!desc->len) {
  66. desc->v_addr = NULL;
  67. return -EINVAL;
  68. }
  69. desc->v_addr = dma_alloc_coherent(&pci_dev->dev, desc->len,
  70. &desc->p_addr, GFP_KERNEL);
  71. return (desc->v_addr != NULL) ? 0 : -ENOMEM;
  72. }
  73. /*
  74. * we have 8 bits used like this:
  75. *
  76. * 7 6 5 4 3 2 1 0
  77. * | | | | | | | |
  78. * | | | | | | +-+-------- AC queue (0-3)
  79. * | | | | | |
  80. * | +-+-+-+-+------------ HW queue ID
  81. * |
  82. * +---------------------- unused
  83. */
  84. static inline void
  85. il_set_swq_id(struct il_tx_queue *txq, u8 ac, u8 hwq)
  86. {
  87. BUG_ON(ac > 3); /* only have 2 bits */
  88. BUG_ON(hwq > 31); /* only use 5 bits */
  89. txq->swq_id = (hwq << 2) | ac;
  90. }
  91. static inline void il_wake_queue(struct il_priv *il,
  92. struct il_tx_queue *txq)
  93. {
  94. u8 queue = txq->swq_id;
  95. u8 ac = queue & 3;
  96. u8 hwq = (queue >> 2) & 0x1f;
  97. if (test_and_clear_bit(hwq, il->queue_stopped))
  98. if (atomic_dec_return(&il->queue_stop_count[ac]) <= 0)
  99. ieee80211_wake_queue(il->hw, ac);
  100. }
  101. static inline void il_stop_queue(struct il_priv *il,
  102. struct il_tx_queue *txq)
  103. {
  104. u8 queue = txq->swq_id;
  105. u8 ac = queue & 3;
  106. u8 hwq = (queue >> 2) & 0x1f;
  107. if (!test_and_set_bit(hwq, il->queue_stopped))
  108. if (atomic_inc_return(&il->queue_stop_count[ac]) > 0)
  109. ieee80211_stop_queue(il->hw, ac);
  110. }
  111. #ifdef ieee80211_stop_queue
  112. #undef ieee80211_stop_queue
  113. #endif
  114. #define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue
  115. #ifdef ieee80211_wake_queue
  116. #undef ieee80211_wake_queue
  117. #endif
  118. #define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue
  119. static inline void il_disable_interrupts(struct il_priv *il)
  120. {
  121. clear_bit(S_INT_ENABLED, &il->status);
  122. /* disable interrupts from uCode/NIC to host */
  123. _il_wr(il, CSR_INT_MASK, 0x00000000);
  124. /* acknowledge/clear/reset any interrupts still pending
  125. * from uCode or flow handler (Rx/Tx DMA) */
  126. _il_wr(il, CSR_INT, 0xffffffff);
  127. _il_wr(il, CSR_FH_INT_STATUS, 0xffffffff);
  128. D_ISR("Disabled interrupts\n");
  129. }
  130. static inline void il_enable_rfkill_int(struct il_priv *il)
  131. {
  132. D_ISR("Enabling rfkill interrupt\n");
  133. _il_wr(il, CSR_INT_MASK, CSR_INT_BIT_RF_KILL);
  134. }
  135. static inline void il_enable_interrupts(struct il_priv *il)
  136. {
  137. D_ISR("Enabling interrupts\n");
  138. set_bit(S_INT_ENABLED, &il->status);
  139. _il_wr(il, CSR_INT_MASK, il->inta_mask);
  140. }
  141. /**
  142. * il_beacon_time_mask_low - mask of lower 32 bit of beacon time
  143. * @il -- pointer to il_priv data structure
  144. * @tsf_bits -- number of bits need to shift for masking)
  145. */
  146. static inline u32 il_beacon_time_mask_low(struct il_priv *il,
  147. u16 tsf_bits)
  148. {
  149. return (1 << tsf_bits) - 1;
  150. }
  151. /**
  152. * il_beacon_time_mask_high - mask of higher 32 bit of beacon time
  153. * @il -- pointer to il_priv data structure
  154. * @tsf_bits -- number of bits need to shift for masking)
  155. */
  156. static inline u32 il_beacon_time_mask_high(struct il_priv *il,
  157. u16 tsf_bits)
  158. {
  159. return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
  160. }
  161. #endif /* __il_helpers_h__ */