| Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** | 
|  | 2 | * | 
| Wey-Yi Guy | 901069c | 2011-04-05 09:42:00 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. | 
| Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 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: | 
| Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | *  Intel Linux Wireless <ilw@linux.intel.com> | 
| Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | 
|  | 27 | * | 
|  | 28 | *****************************************************************************/ | 
|  | 29 |  | 
|  | 30 | #ifndef __iwl_helpers_h__ | 
|  | 31 | #define __iwl_helpers_h__ | 
|  | 32 |  | 
|  | 33 | #include <linux/ctype.h> | 
| Johannes Berg | a117512 | 2010-01-21 06:21:10 -0800 | [diff] [blame] | 34 | #include <net/mac80211.h> | 
|  | 35 |  | 
|  | 36 | #include "iwl-io.h" | 
| Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 37 |  | 
| Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame] | 38 | #define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo)))) | 
|  | 39 |  | 
| Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 40 |  | 
| Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 41 | static inline struct ieee80211_conf *ieee80211_get_hw_conf( | 
|  | 42 | struct ieee80211_hw *hw) | 
|  | 43 | { | 
|  | 44 | return &hw->conf; | 
|  | 45 | } | 
|  | 46 |  | 
| Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 47 | /** | 
|  | 48 | * iwl_queue_inc_wrap - increment queue index, wrap back to beginning | 
|  | 49 | * @index -- current index | 
|  | 50 | * @n_bd -- total number of entries in queue (must be power of 2) | 
|  | 51 | */ | 
|  | 52 | static inline int iwl_queue_inc_wrap(int index, int n_bd) | 
|  | 53 | { | 
|  | 54 | return ++index & (n_bd - 1); | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | /** | 
|  | 58 | * iwl_queue_dec_wrap - decrement queue index, wrap back to end | 
|  | 59 | * @index -- current index | 
|  | 60 | * @n_bd -- total number of entries in queue (must be power of 2) | 
|  | 61 | */ | 
|  | 62 | static inline int iwl_queue_dec_wrap(int index, int n_bd) | 
|  | 63 | { | 
|  | 64 | return --index & (n_bd - 1); | 
|  | 65 | } | 
|  | 66 |  | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 67 | /* | 
|  | 68 | * we have 8 bits used like this: | 
|  | 69 | * | 
|  | 70 | * 7 6 5 4 3 2 1 0 | 
|  | 71 | * | | | | | | | | | 
|  | 72 | * | | | | | | +-+-------- AC queue (0-3) | 
|  | 73 | * | | | | | | | 
| Johannes Berg | ea9b307 | 2010-11-10 18:25:45 -0800 | [diff] [blame] | 74 | * | +-+-+-+-+------------ HW queue ID | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 75 | * | | 
| Johannes Berg | ea9b307 | 2010-11-10 18:25:45 -0800 | [diff] [blame] | 76 | * +---------------------- unused | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 77 | */ | 
| Johannes Berg | ea9b307 | 2010-11-10 18:25:45 -0800 | [diff] [blame] | 78 | static inline void iwl_set_swq_id(struct iwl_tx_queue *txq, u8 ac, u8 hwq) | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 79 | { | 
|  | 80 | BUG_ON(ac > 3);   /* only have 2 bits */ | 
| Johannes Berg | ea9b307 | 2010-11-10 18:25:45 -0800 | [diff] [blame] | 81 | BUG_ON(hwq > 31); /* only use 5 bits */ | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 82 |  | 
| Johannes Berg | ea9b307 | 2010-11-10 18:25:45 -0800 | [diff] [blame] | 83 | txq->swq_id = (hwq << 2) | ac; | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 84 | } | 
|  | 85 |  | 
| Johannes Berg | 549a04e | 2010-11-10 18:25:44 -0800 | [diff] [blame] | 86 | static inline void iwl_wake_queue(struct iwl_priv *priv, | 
|  | 87 | struct iwl_tx_queue *txq) | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 88 | { | 
| Johannes Berg | 549a04e | 2010-11-10 18:25:44 -0800 | [diff] [blame] | 89 | u8 queue = txq->swq_id; | 
| Johannes Berg | ea9b307 | 2010-11-10 18:25:45 -0800 | [diff] [blame] | 90 | u8 ac = queue & 3; | 
|  | 91 | u8 hwq = (queue >> 2) & 0x1f; | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 92 |  | 
|  | 93 | if (test_and_clear_bit(hwq, priv->queue_stopped)) | 
|  | 94 | if (atomic_dec_return(&priv->queue_stop_count[ac]) <= 0) | 
|  | 95 | ieee80211_wake_queue(priv->hw, ac); | 
|  | 96 | } | 
|  | 97 |  | 
| Johannes Berg | 549a04e | 2010-11-10 18:25:44 -0800 | [diff] [blame] | 98 | static inline void iwl_stop_queue(struct iwl_priv *priv, | 
|  | 99 | struct iwl_tx_queue *txq) | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 100 | { | 
| Johannes Berg | 549a04e | 2010-11-10 18:25:44 -0800 | [diff] [blame] | 101 | u8 queue = txq->swq_id; | 
| Johannes Berg | ea9b307 | 2010-11-10 18:25:45 -0800 | [diff] [blame] | 102 | u8 ac = queue & 3; | 
|  | 103 | u8 hwq = (queue >> 2) & 0x1f; | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 104 |  | 
|  | 105 | if (!test_and_set_bit(hwq, priv->queue_stopped)) | 
|  | 106 | if (atomic_inc_return(&priv->queue_stop_count[ac]) > 0) | 
|  | 107 | ieee80211_stop_queue(priv->hw, ac); | 
|  | 108 | } | 
|  | 109 |  | 
| Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame] | 110 | static inline void iwl_wake_any_queue(struct iwl_priv *priv, | 
|  | 111 | struct iwl_rxon_context *ctx) | 
|  | 112 | { | 
|  | 113 | u8 ac; | 
|  | 114 |  | 
|  | 115 | for (ac = 0; ac < AC_NUM; ac++) { | 
|  | 116 | IWL_DEBUG_INFO(priv, "Queue Status: Q[%d] %s\n", | 
|  | 117 | ac, (atomic_read(&priv->queue_stop_count[ac]) > 0) | 
|  | 118 | ? "stopped" : "awake"); | 
|  | 119 | iwl_wake_queue(priv, &priv->txq[ctx->ac_to_queue[ac]]); | 
|  | 120 | } | 
|  | 121 | } | 
|  | 122 |  | 
| Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 123 | #define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue | 
|  | 124 | #define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue | 
|  | 125 |  | 
| Wey-Yi Guy | 30a12a8 | 2009-07-17 09:30:27 -0700 | [diff] [blame] | 126 | static inline void iwl_disable_interrupts(struct iwl_priv *priv) | 
|  | 127 | { | 
|  | 128 | clear_bit(STATUS_INT_ENABLED, &priv->status); | 
|  | 129 |  | 
|  | 130 | /* disable interrupts from uCode/NIC to host */ | 
|  | 131 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); | 
|  | 132 |  | 
|  | 133 | /* acknowledge/clear/reset any interrupts still pending | 
|  | 134 | * from uCode or flow handler (Rx/Tx DMA) */ | 
|  | 135 | iwl_write32(priv, CSR_INT, 0xffffffff); | 
|  | 136 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); | 
|  | 137 | IWL_DEBUG_ISR(priv, "Disabled interrupts\n"); | 
|  | 138 | } | 
|  | 139 |  | 
| Stanislaw Gruszka | 554d1d0 | 2010-12-23 12:38:21 +0100 | [diff] [blame] | 140 | static inline void iwl_enable_rfkill_int(struct iwl_priv *priv) | 
|  | 141 | { | 
|  | 142 | IWL_DEBUG_ISR(priv, "Enabling rfkill interrupt\n"); | 
|  | 143 | iwl_write32(priv, CSR_INT_MASK, CSR_INT_BIT_RF_KILL); | 
|  | 144 | } | 
|  | 145 |  | 
| Wey-Yi Guy | 30a12a8 | 2009-07-17 09:30:27 -0700 | [diff] [blame] | 146 | static inline void iwl_enable_interrupts(struct iwl_priv *priv) | 
|  | 147 | { | 
|  | 148 | IWL_DEBUG_ISR(priv, "Enabling interrupts\n"); | 
|  | 149 | set_bit(STATUS_INT_ENABLED, &priv->status); | 
|  | 150 | iwl_write32(priv, CSR_INT_MASK, priv->inta_mask); | 
|  | 151 | } | 
|  | 152 |  | 
| Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 153 | /** | 
|  | 154 | * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time | 
|  | 155 | * @priv -- pointer to iwl_priv data structure | 
|  | 156 | * @tsf_bits -- number of bits need to shift for masking) | 
|  | 157 | */ | 
|  | 158 | static inline u32 iwl_beacon_time_mask_low(struct iwl_priv *priv, | 
|  | 159 | u16 tsf_bits) | 
|  | 160 | { | 
|  | 161 | return (1 << tsf_bits) - 1; | 
|  | 162 | } | 
|  | 163 |  | 
|  | 164 | /** | 
|  | 165 | * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time | 
|  | 166 | * @priv -- pointer to iwl_priv data structure | 
|  | 167 | * @tsf_bits -- number of bits need to shift for masking) | 
|  | 168 | */ | 
|  | 169 | static inline u32 iwl_beacon_time_mask_high(struct iwl_priv *priv, | 
|  | 170 | u16 tsf_bits) | 
|  | 171 | { | 
|  | 172 | return ((1 << (32 - tsf_bits)) - 1) << tsf_bits; | 
|  | 173 | } | 
|  | 174 |  | 
| Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 175 | #endif				/* __iwl_helpers_h__ */ |