iwl-helpers.h 5.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/******************************************************************************
 *
 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
 *
 * Portions of this file are derived from the ipw3945 project, as well
 * as portions of the ieee80211 subsystem header files.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
 *
 * The full GNU General Public License is included in this distribution in the
 * file called LICENSE.
 *
 * Contact Information:
 *  Intel Linux Wireless <ilw@linux.intel.com>
 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 *
 *****************************************************************************/

S
Stanislaw Gruszka 已提交
30 31
#ifndef __il_helpers_h__
#define __il_helpers_h__
32 33 34 35 36 37

#include <linux/ctype.h>
#include <net/mac80211.h>

#include "iwl-io.h"

S
Stanislaw Gruszka 已提交
38
#define IL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
39 40


S
Stanislaw Gruszka 已提交
41
static inline struct ieee80211_conf *il_ieee80211_get_hw_conf(
42 43 44 45 46 47
	struct ieee80211_hw *hw)
{
	return &hw->conf;
}

/**
S
Stanislaw Gruszka 已提交
48
 * il_queue_inc_wrap - increment queue index, wrap back to beginning
49 50 51
 * @index -- current index
 * @n_bd -- total number of entries in queue (must be power of 2)
 */
S
Stanislaw Gruszka 已提交
52
static inline int il_queue_inc_wrap(int index, int n_bd)
53 54 55 56 57
{
	return ++index & (n_bd - 1);
}

/**
S
Stanislaw Gruszka 已提交
58
 * il_queue_dec_wrap - decrement queue index, wrap back to end
59 60 61
 * @index -- current index
 * @n_bd -- total number of entries in queue (must be power of 2)
 */
S
Stanislaw Gruszka 已提交
62
static inline int il_queue_dec_wrap(int index, int n_bd)
63 64 65 66 67
{
	return --index & (n_bd - 1);
}

/* TODO: Move fw_desc functions to iwl-pci.ko */
S
Stanislaw Gruszka 已提交
68
static inline void il_free_fw_desc(struct pci_dev *pci_dev,
69 70 71 72 73 74 75 76 77
				    struct fw_desc *desc)
{
	if (desc->v_addr)
		dma_free_coherent(&pci_dev->dev, desc->len,
				  desc->v_addr, desc->p_addr);
	desc->v_addr = NULL;
	desc->len = 0;
}

S
Stanislaw Gruszka 已提交
78
static inline int il_alloc_fw_desc(struct pci_dev *pci_dev,
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
				    struct fw_desc *desc)
{
	if (!desc->len) {
		desc->v_addr = NULL;
		return -EINVAL;
	}

	desc->v_addr = dma_alloc_coherent(&pci_dev->dev, desc->len,
					  &desc->p_addr, GFP_KERNEL);
	return (desc->v_addr != NULL) ? 0 : -ENOMEM;
}

/*
 * we have 8 bits used like this:
 *
 * 7 6 5 4 3 2 1 0
 * | | | | | | | |
 * | | | | | | +-+-------- AC queue (0-3)
 * | | | | | |
 * | +-+-+-+-+------------ HW queue ID
 * |
 * +---------------------- unused
 */
static inline void
S
Stanislaw Gruszka 已提交
103
il_set_swq_id(struct il_tx_queue *txq, u8 ac, u8 hwq)
104 105 106 107 108 109 110
{
	BUG_ON(ac > 3);   /* only have 2 bits */
	BUG_ON(hwq > 31); /* only use 5 bits */

	txq->swq_id = (hwq << 2) | ac;
}

S
Stanislaw Gruszka 已提交
111
static inline void il_wake_queue(struct il_priv *il,
S
Stanislaw Gruszka 已提交
112
				  struct il_tx_queue *txq)
113 114 115 116 117
{
	u8 queue = txq->swq_id;
	u8 ac = queue & 3;
	u8 hwq = (queue >> 2) & 0x1f;

S
Stanislaw Gruszka 已提交
118 119 120
	if (test_and_clear_bit(hwq, il->queue_stopped))
		if (atomic_dec_return(&il->queue_stop_count[ac]) <= 0)
			ieee80211_wake_queue(il->hw, ac);
121 122
}

S
Stanislaw Gruszka 已提交
123
static inline void il_stop_queue(struct il_priv *il,
S
Stanislaw Gruszka 已提交
124
				  struct il_tx_queue *txq)
125 126 127 128 129
{
	u8 queue = txq->swq_id;
	u8 ac = queue & 3;
	u8 hwq = (queue >> 2) & 0x1f;

S
Stanislaw Gruszka 已提交
130 131 132
	if (!test_and_set_bit(hwq, il->queue_stopped))
		if (atomic_inc_return(&il->queue_stop_count[ac]) > 0)
			ieee80211_stop_queue(il->hw, ac);
133 134
}

K
Kalle Valo 已提交
135 136 137 138
#ifdef ieee80211_stop_queue
#undef ieee80211_stop_queue
#endif

139
#define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue
K
Kalle Valo 已提交
140 141 142 143 144

#ifdef ieee80211_wake_queue
#undef ieee80211_wake_queue
#endif

145 146
#define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue

S
Stanislaw Gruszka 已提交
147
static inline void il_disable_interrupts(struct il_priv *il)
148
{
S
Stanislaw Gruszka 已提交
149
	clear_bit(STATUS_INT_ENABLED, &il->status);
150 151

	/* disable interrupts from uCode/NIC to host */
S
Stanislaw Gruszka 已提交
152
	il_write32(il, CSR_INT_MASK, 0x00000000);
153 154 155

	/* acknowledge/clear/reset any interrupts still pending
	 * from uCode or flow handler (Rx/Tx DMA) */
S
Stanislaw Gruszka 已提交
156 157 158
	il_write32(il, CSR_INT, 0xffffffff);
	il_write32(il, CSR_FH_INT_STATUS, 0xffffffff);
	IL_DEBUG_ISR(il, "Disabled interrupts\n");
159 160
}

S
Stanislaw Gruszka 已提交
161
static inline void il_enable_rfkill_int(struct il_priv *il)
162
{
S
Stanislaw Gruszka 已提交
163 164
	IL_DEBUG_ISR(il, "Enabling rfkill interrupt\n");
	il_write32(il, CSR_INT_MASK, CSR_INT_BIT_RF_KILL);
165 166
}

S
Stanislaw Gruszka 已提交
167
static inline void il_enable_interrupts(struct il_priv *il)
168
{
S
Stanislaw Gruszka 已提交
169 170 171
	IL_DEBUG_ISR(il, "Enabling interrupts\n");
	set_bit(STATUS_INT_ENABLED, &il->status);
	il_write32(il, CSR_INT_MASK, il->inta_mask);
172 173 174
}

/**
S
Stanislaw Gruszka 已提交
175
 * il_beacon_time_mask_low - mask of lower 32 bit of beacon time
S
Stanislaw Gruszka 已提交
176
 * @il -- pointer to il_priv data structure
177 178
 * @tsf_bits -- number of bits need to shift for masking)
 */
S
Stanislaw Gruszka 已提交
179
static inline u32 il_beacon_time_mask_low(struct il_priv *il,
180 181 182 183 184 185
					   u16 tsf_bits)
{
	return (1 << tsf_bits) - 1;
}

/**
S
Stanislaw Gruszka 已提交
186
 * il_beacon_time_mask_high - mask of higher 32 bit of beacon time
S
Stanislaw Gruszka 已提交
187
 * @il -- pointer to il_priv data structure
188 189
 * @tsf_bits -- number of bits need to shift for masking)
 */
S
Stanislaw Gruszka 已提交
190
static inline u32 il_beacon_time_mask_high(struct il_priv *il,
191 192 193 194 195
					    u16 tsf_bits)
{
	return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
}

S
Stanislaw Gruszka 已提交
196
#endif				/* __il_helpers_h__ */