iwl-helpers.h 5.0 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 38

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

#include "iwl-io.h"

/**
S
Stanislaw Gruszka 已提交
39 40
 * il_queue_inc_wrap - increment queue idx, wrap back to beginning
 * @idx -- current idx
41 42
 * @n_bd -- total number of entries in queue (must be power of 2)
 */
S
Stanislaw Gruszka 已提交
43
static inline int il_queue_inc_wrap(int idx, int n_bd)
44
{
S
Stanislaw Gruszka 已提交
45
	return ++idx & (n_bd - 1);
46 47 48
}

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

/* TODO: Move fw_desc functions to iwl-pci.ko */
S
Stanislaw Gruszka 已提交
59
static inline void il_free_fw_desc(struct pci_dev *pci_dev,
60 61 62 63 64 65 66 67 68
				    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 已提交
69
static inline int il_alloc_fw_desc(struct pci_dev *pci_dev,
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
				    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 已提交
94
il_set_swq_id(struct il_tx_queue *txq, u8 ac, u8 hwq)
95 96 97 98 99 100 101
{
	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 已提交
102
static inline void il_wake_queue(struct il_priv *il,
S
Stanislaw Gruszka 已提交
103
				  struct il_tx_queue *txq)
104 105 106 107 108
{
	u8 queue = txq->swq_id;
	u8 ac = queue & 3;
	u8 hwq = (queue >> 2) & 0x1f;

S
Stanislaw Gruszka 已提交
109 110 111
	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);
112 113
}

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

S
Stanislaw Gruszka 已提交
121 122 123
	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);
124 125
}

K
Kalle Valo 已提交
126 127 128 129
#ifdef ieee80211_stop_queue
#undef ieee80211_stop_queue
#endif

130
#define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue
K
Kalle Valo 已提交
131 132 133 134 135

#ifdef ieee80211_wake_queue
#undef ieee80211_wake_queue
#endif

136 137
#define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue

S
Stanislaw Gruszka 已提交
138
static inline void il_disable_interrupts(struct il_priv *il)
139
{
S
Stanislaw Gruszka 已提交
140
	clear_bit(S_INT_ENABLED, &il->status);
141 142

	/* disable interrupts from uCode/NIC to host */
143
	_il_wr(il, CSR_INT_MASK, 0x00000000);
144 145 146

	/* acknowledge/clear/reset any interrupts still pending
	 * from uCode or flow handler (Rx/Tx DMA) */
147 148
	_il_wr(il, CSR_INT, 0xffffffff);
	_il_wr(il, CSR_FH_INT_STATUS, 0xffffffff);
149
	D_ISR("Disabled interrupts\n");
150 151
}

S
Stanislaw Gruszka 已提交
152
static inline void il_enable_rfkill_int(struct il_priv *il)
153
{
154
	D_ISR("Enabling rfkill interrupt\n");
155
	_il_wr(il, CSR_INT_MASK, CSR_INT_BIT_RF_KILL);
156 157
}

S
Stanislaw Gruszka 已提交
158
static inline void il_enable_interrupts(struct il_priv *il)
159
{
160
	D_ISR("Enabling interrupts\n");
S
Stanislaw Gruszka 已提交
161
	set_bit(S_INT_ENABLED, &il->status);
162
	_il_wr(il, CSR_INT_MASK, il->inta_mask);
163 164 165
}

/**
S
Stanislaw Gruszka 已提交
166
 * il_beacon_time_mask_low - mask of lower 32 bit of beacon time
S
Stanislaw Gruszka 已提交
167
 * @il -- pointer to il_priv data structure
168 169
 * @tsf_bits -- number of bits need to shift for masking)
 */
S
Stanislaw Gruszka 已提交
170
static inline u32 il_beacon_time_mask_low(struct il_priv *il,
171 172 173 174 175 176
					   u16 tsf_bits)
{
	return (1 << tsf_bits) - 1;
}

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

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