internal.h revision 8a964f44e01ad3bbc208c3e80d931ba91b9ea786
1ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach/******************************************************************************
2ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *
3128e63ef077ef7ccd9c5779bbdce566641714666Johannes Berg * Copyright(c) 2003 - 2013 Intel Corporation. All rights reserved.
4ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *
5ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * Portions of this file are derived from the ipw3945 project, as well
6ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * as portions of the ieee80211 subsystem header files.
7ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *
8ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * This program is free software; you can redistribute it and/or modify it
9ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * under the terms of version 2 of the GNU General Public License as
10ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * published by the Free Software Foundation.
11ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *
12ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * This program is distributed in the hope that it will be useful, but WITHOUT
13ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * more details.
16ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *
17ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * You should have received a copy of the GNU General Public License along with
18ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * this program; if not, write to the Free Software Foundation, Inc.,
19ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *
21ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * The full GNU General Public License is included in this distribution in the
22ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * file called LICENSE.
23ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *
24ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * Contact Information:
25ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *  Intel Linux Wireless <ilw@linux.intel.com>
26ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *
28ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *****************************************************************************/
29ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach#ifndef __iwl_trans_int_pcie_h__
30ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach#define __iwl_trans_int_pcie_h__
31ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach
32a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach#include <linux/spinlock.h>
33a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach#include <linux/interrupt.h>
34a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach#include <linux/skbuff.h>
3513df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg#include <linux/wait.h>
36522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach#include <linux/pci.h>
377c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg#include <linux/timer.h>
38a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach
39dda61a4482661d71034cc132d1f474f19ce34a4dEmmanuel Grumbach#include "iwl-fh.h"
40a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach#include "iwl-csr.h"
41a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach#include "iwl-trans.h"
42a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach#include "iwl-debug.h"
43a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach#include "iwl-io.h"
4402e3835884f352ac707dcf14d8bf455c0c0acbc5Emmanuel Grumbach#include "iwl-op-mode.h"
45a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach
46a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbachstruct iwl_host_cmd;
47dda61a4482661d71034cc132d1f474f19ce34a4dEmmanuel Grumbach
48ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach/*This file includes the declaration that are internal to the
49ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach * trans_pcie layer */
50ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach
5148a2d66f58d2bf1818acf5ff7ed9897a9977a96eJohannes Bergstruct iwl_rx_mem_buffer {
5248a2d66f58d2bf1818acf5ff7ed9897a9977a96eJohannes Berg	dma_addr_t page_dma;
5348a2d66f58d2bf1818acf5ff7ed9897a9977a96eJohannes Berg	struct page *page;
5448a2d66f58d2bf1818acf5ff7ed9897a9977a96eJohannes Berg	struct list_head list;
5548a2d66f58d2bf1818acf5ff7ed9897a9977a96eJohannes Berg};
5648a2d66f58d2bf1818acf5ff7ed9897a9977a96eJohannes Berg
57e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbach/**
581f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach * struct isr_statistics - interrupt statistics
591f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach *
601f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach */
611f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbachstruct isr_statistics {
621f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 hw;
631f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 sw;
641f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 err_code;
651f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 sch;
661f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 alive;
671f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 rfkill;
681f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 ctkill;
691f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 wakeup;
701f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 rx;
711f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 tx;
721f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	u32 unhandled;
731f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach};
741f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach
751f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach/**
76990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach * struct iwl_rxq - Rx queue
775a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
785a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
795a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @pool:
805a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @queue:
815a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @read: Shared index to newest available Rx buffer
825a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @write: Shared index to oldest written Rx packet
835a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @free_count: Number of pre-allocated buffers in rx_free
845a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @write_actual:
855a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @rx_free: list of free SKBs for use
865a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @rx_used: List of Rx buffers with no SKB
875a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @need_update: flag to indicate we need to update read/write index
885a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @rb_stts: driver's pointer to receive buffer status
895a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @rb_stts_dma: bus address of receive buffer status
905a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @lock:
915a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach *
925a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * NOTE:  rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
935a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach */
94990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachstruct iwl_rxq {
955a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	__le32 *bd;
965a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	dma_addr_t bd_dma;
975a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
985a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
995a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	u32 read;
1005a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	u32 write;
1015a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	u32 free_count;
1025a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	u32 write_actual;
1035a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	struct list_head rx_free;
1045a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	struct list_head rx_used;
1055a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	int need_update;
1065a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	struct iwl_rb_status *rb_stts;
1075a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	dma_addr_t rb_stts_dma;
1085a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	spinlock_t lock;
1095a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach};
1105a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach
111a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbachstruct iwl_dma_ptr {
112a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach	dma_addr_t dma;
113a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach	void *addr;
114a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach	size_t size;
115a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach};
116a72b8b088c3465b28192c1a14ba97be8223a8cecEmmanuel Grumbach
117bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg/**
118bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg * iwl_queue_inc_wrap - increment queue index, wrap back to beginning
119bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg * @index -- current index
120bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg * @n_bd -- total number of entries in queue (must be power of 2)
121bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg */
122bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Bergstatic inline int iwl_queue_inc_wrap(int index, int n_bd)
123bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg{
124bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg	return ++index & (n_bd - 1);
125bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg}
126bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg
127bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg/**
128bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg * iwl_queue_dec_wrap - decrement queue index, wrap back to end
129bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg * @index -- current index
130bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg * @n_bd -- total number of entries in queue (must be power of 2)
131bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg */
132bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Bergstatic inline int iwl_queue_dec_wrap(int index, int n_bd)
133bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg{
134bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg	return --index & (n_bd - 1);
135bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg}
136bffc66ce2210b149fd171eccad2aef9802c0b35dJohannes Berg
137522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbachstruct iwl_cmd_meta {
138522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	/* only for SYNC commands, iff the reply skb is wanted */
139522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	struct iwl_host_cmd *source;
140522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach
141522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	DEFINE_DMA_UNMAP_ADDR(mapping);
142522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	DEFINE_DMA_UNMAP_LEN(len);
143c14c73728b8feb01d9142f9241bf14601cfb86f7Johannes Berg
144c14c73728b8feb01d9142f9241bf14601cfb86f7Johannes Berg	u32 flags;
145522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach};
146522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach
147522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach/*
148522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * Generic queue structure
149522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach *
150522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * Contains common data for Rx and Tx queues.
151522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach *
152522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * Note the difference between n_bd and n_window: the hardware
153522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * always assumes 256 descriptors, so n_bd is always 256 (unless
154522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * there might be HW changes in the future). For the normal TX
155522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * queues, n_window, which is the size of the software queue data
156522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * is also 256; however, for the command queue, n_window is only
157522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * 32 since we don't need so many commands pending. Since the HW
158522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * still uses 256 BDs for DMA though, n_bd stays 256. As a result,
159522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * the software buffers (in the variables @meta, @txb in struct
160990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach * iwl_txq) only have 32 entries, while the HW buffers (@tfds in
161990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach * the same struct) have 256.
162522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * This means that we end up with the following:
163522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach *  HW entries: | 0 | ... | N * 32 | ... | N * 32 + 31 | ... | 255 |
164522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach *  SW entries:           | 0      | ... | 31          |
165522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * where N is a number between 0 and 7. This means that the SW
166522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * data is a window overlayed over the HW queue.
167522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach */
168522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbachstruct iwl_queue {
169522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	int n_bd;              /* number of BDs in this queue */
170522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	int write_ptr;       /* 1-st empty entry (index) host_w*/
171522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	int read_ptr;         /* last used entry (index) host_r*/
172522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	/* use for monitoring and recovering the stuck queue */
173522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	dma_addr_t dma_addr;   /* physical addr for BD's */
174522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	int n_window;	       /* safe queue window */
175522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	u32 id;
176522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	int low_mark;	       /* low watermark, resume queue if free
177522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach				* space more than this */
178522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	int high_mark;         /* high watermark, stop queue if free
179522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach				* space less than this */
180522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach};
181522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach
182bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg#define TFD_TX_CMD_SLOTS 256
183bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg#define TFD_CMD_SLOTS 32
184bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg
1858a964f44e01ad3bbc208c3e80d931ba91b9ea786Johannes Berg/*
1868a964f44e01ad3bbc208c3e80d931ba91b9ea786Johannes Berg * The FH will write back to the first TB only, so we need
1878a964f44e01ad3bbc208c3e80d931ba91b9ea786Johannes Berg * to copy some data into the buffer regardless of whether
1888a964f44e01ad3bbc208c3e80d931ba91b9ea786Johannes Berg * it should be mapped or not. This indicates how much to
1898a964f44e01ad3bbc208c3e80d931ba91b9ea786Johannes Berg * copy, even for HCMDs it must be big enough to fit the
1908a964f44e01ad3bbc208c3e80d931ba91b9ea786Johannes Berg * DRAM scratch from the TX cmd, at least 16 bytes.
1918a964f44e01ad3bbc208c3e80d931ba91b9ea786Johannes Berg */
1928a964f44e01ad3bbc208c3e80d931ba91b9ea786Johannes Berg#define IWL_HCMD_MIN_COPY_SIZE	16
1938a964f44e01ad3bbc208c3e80d931ba91b9ea786Johannes Berg
194990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachstruct iwl_pcie_txq_entry {
195bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg	struct iwl_device_cmd *cmd;
1969679142291f51515bd1bf492535e8a12515558e9Emmanuel Grumbach	struct iwl_device_cmd *copy_cmd;
197bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg	struct sk_buff *skb;
198f4feb8ac6e666d2ca37cf722166bbfadf2c6adf8Johannes Berg	/* buffer to free after command completes */
199f4feb8ac6e666d2ca37cf722166bbfadf2c6adf8Johannes Berg	const void *free_buf;
200bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg	struct iwl_cmd_meta meta;
201bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg};
202bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg
203522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach/**
204990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach * struct iwl_txq - Tx Queue for DMA
205522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * @q: generic Rx/Tx queue descriptor
206bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @tfds: transmit frame descriptors (DMA memory)
207bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @entries: transmit entries (driver state)
208bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @lock: queue lock
209bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @stuck_timer: timer that fires if queue gets stuck
210bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @trans_pcie: pointer back to transport (for timer)
211522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * @need_update: indicates need to update read/write index
212bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @active: stores if queue is active
213522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach *
214522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
215522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * descriptors) and required locking structures.
216522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach */
217990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachstruct iwl_txq {
218522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	struct iwl_queue q;
219522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	struct iwl_tfd *tfds;
220990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach	struct iwl_pcie_txq_entry *entries;
221015c15e1067c988fc87fb550b222f075c8d3f47cJohannes Berg	spinlock_t lock;
2227c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	struct timer_list stuck_timer;
2237c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	struct iwl_trans_pcie *trans_pcie;
224522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	u8 need_update;
225522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	u8 active;
226522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach};
227522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach
2285a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach/**
229e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbach * struct iwl_trans_pcie - PCIe transport specific data
2305a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @rxq: all the RX queue data
2315a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @rx_replenish: work that will be called when buffers need to be allocated
2329130bab137844d9ad3db6ab524de299cd2b9e39dEmmanuel Grumbach * @drv - pointer to iwl_drv
2335a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @trans: pointer to the generic transport area
234105183b156b7c220b47c3162e087101a0a6abc9fEmmanuel Grumbach * @scd_base_addr: scheduler sram base address in SRAM
235105183b156b7c220b47c3162e087101a0a6abc9fEmmanuel Grumbach * @scd_bc_tbls: pointer to the byte count table of the scheduler
2369d6b2cb1ccf9c1e00a0891eff78b93eb1a1fc372Emmanuel Grumbach * @kw: keep warm address
237a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach * @pci_dev: basic pci-network driver stuff
238a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach * @hw_base: pci hardware address support
23913df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg * @ucode_write_complete: indicates that the ucode has been copied.
24013df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg * @ucode_write_waitq: wait queue for uCode load
2419a716863ae4a2f039bc4d0b2b2bb4b24a1dc7a91Don Fry * @status - transport specific status flags
242c6f600fcfe8a7e4f594fc4c80b2c7b66f248958bMeenakshi Venkataraman * @cmd_queue - command queue number
243b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg * @rx_buf_size_8k: 8 kB RX buffer size
244046db346386661906dffa33f5ed3dfcdccfddc0bEmmanuel Grumbach * @bc_table_dword: true if the BC table expects DWORD (as opposed to bytes)
245b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg * @rx_page_order: page order for receive buffer size
2467c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg * @wd_timeout: queue watchdog timeout (jiffies)
247e56b04efc1f795da42cf1d9651b52a4a5bebd730Lilach Edelstein * @reg_lock: protect hw register access
248e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbach */
249e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbachstruct iwl_trans_pcie {
250990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach	struct iwl_rxq rxq;
2515a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	struct work_struct rx_replenish;
2525a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	struct iwl_trans *trans;
2539130bab137844d9ad3db6ab524de299cd2b9e39dEmmanuel Grumbach	struct iwl_drv *drv;
2540c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
2550c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	/* INT ICT Table */
2560c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	__le32 *ict_tbl;
2570c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	dma_addr_t ict_tbl_dma;
2580c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	int ict_index;
2590c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	u32 inta;
2600c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	bool use_ict;
2611f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	struct isr_statistics isr_stats;
2620c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
2637b11488fbbbe06ada39a396dec16532db8c933e6Johannes Berg	spinlock_t irq_lock;
2640c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	u32 inta_mask;
265105183b156b7c220b47c3162e087101a0a6abc9fEmmanuel Grumbach	u32 scd_base_addr;
266105183b156b7c220b47c3162e087101a0a6abc9fEmmanuel Grumbach	struct iwl_dma_ptr scd_bc_tbls;
2679d6b2cb1ccf9c1e00a0891eff78b93eb1a1fc372Emmanuel Grumbach	struct iwl_dma_ptr kw;
268e13c0c59e0ec38558ac853d56555e915b4dc7dc2Emmanuel Grumbach
269990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach	struct iwl_txq *txq;
2709eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	unsigned long queue_used[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
2718ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach	unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
272a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach
273a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach	/* PCI bus related data */
274a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach	struct pci_dev *pci_dev;
275a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach	void __iomem *hw_base;
27613df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg
27713df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg	bool ucode_write_complete;
27813df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg	wait_queue_head_t ucode_write_waitq;
279f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	wait_queue_head_t wait_command_queue;
280f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach
2819a716863ae4a2f039bc4d0b2b2bb4b24a1dc7a91Don Fry	unsigned long status;
282c6f600fcfe8a7e4f594fc4c80b2c7b66f248958bMeenakshi Venkataraman	u8 cmd_queue;
283b04db9ac4f7641332e0133b2fd8f82e6e4553947Emmanuel Grumbach	u8 cmd_fifo;
284d663ee73f62903aed334eca25832a76c4a7e4c1cJohannes Berg	u8 n_no_reclaim_cmds;
285d663ee73f62903aed334eca25832a76c4a7e4c1cJohannes Berg	u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];
286b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg
287b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg	bool rx_buf_size_8k;
288046db346386661906dffa33f5ed3dfcdccfddc0bEmmanuel Grumbach	bool bc_table_dword;
289b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg	u32 rx_page_order;
2907c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg
291d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg	const char **command_names;
2927c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg
2937c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	/* queue watchdog */
2947c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	unsigned long wd_timeout;
295e56b04efc1f795da42cf1d9651b52a4a5bebd730Lilach Edelstein
296e56b04efc1f795da42cf1d9651b52a4a5bebd730Lilach Edelstein	/*protect hw register */
297e56b04efc1f795da42cf1d9651b52a4a5bebd730Lilach Edelstein	spinlock_t reg_lock;
298e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbach};
299e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbach
300b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach/**
301b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * enum iwl_pcie_status: status of the PCIe transport
302b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_HCMD_ACTIVE: a SYNC command is being processed
303b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_DEVICE_ENABLED: APM is enabled
304b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_TPOWER_PMI: the device might be asleep (need to wake it up)
305b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_INT_ENABLED: interrupts are enabled
306b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_RFKILL: the HW RFkill switch is in KILL position
307b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_FW_ERROR: the fw is in error state
308b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach */
309b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbachenum iwl_pcie_status {
310f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_HCMD_ACTIVE,
311f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_DEVICE_ENABLED,
312f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_TPOWER_PMI,
313f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_INT_ENABLED,
314f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_RFKILL,
315d18aa87fbfe80f33076942d11f19c9d813e835b1Johannes Berg	STATUS_FW_ERROR,
316f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach};
31701d651d4b7f40c90821e104963dc04800fbde8cfDon Fry
3185a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach#define IWL_TRANS_GET_PCIE_TRANS(_iwl_trans) \
3195a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	((struct iwl_trans_pcie *) ((_iwl_trans)->trans_specific))
3205a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach
3217c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Bergstatic inline struct iwl_trans *
3227c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Bergiwl_trans_pcie_get_trans(struct iwl_trans_pcie *trans_pcie)
3237c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg{
3247c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	return container_of((void *)trans_pcie, struct iwl_trans,
3257c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg			    trans_specific);
3267c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg}
3277c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg
328f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach/*
329f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach * Convention: trans API functions: iwl_trans_pcie_XXX
330f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach *	Other functions: iwl_pcie_XXX
331f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach */
332d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Bergstruct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
333d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Berg				       const struct pci_device_id *ent,
334d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Berg				       const struct iwl_cfg *cfg);
335d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Bergvoid iwl_trans_pcie_free(struct iwl_trans *trans);
336d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Berg
337253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach/*****************************************************
338253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach* RX
339253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach******************************************************/
3409805c4460ae37aa9328a470c7aebea32f0667e24Emmanuel Grumbachint iwl_pcie_rx_init(struct iwl_trans *trans);
3412bfb50924c7e92362ac937aef2ab56bc7bd3ca52Johannes Bergirqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id);
3429805c4460ae37aa9328a470c7aebea32f0667e24Emmanuel Grumbachint iwl_pcie_rx_stop(struct iwl_trans *trans);
3439805c4460ae37aa9328a470c7aebea32f0667e24Emmanuel Grumbachvoid iwl_pcie_rx_free(struct iwl_trans *trans);
344ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach
345253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach/*****************************************************
346990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach* ICT - interrupt handling
3471a361cd838173879672cb0f0ebe1e7654d7edff6Emmanuel Grumbach******************************************************/
348990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachirqreturn_t iwl_pcie_isr_ict(int irq, void *data);
349990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachint iwl_pcie_alloc_ict(struct iwl_trans *trans);
350990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_free_ict(struct iwl_trans *trans);
351990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_reset_ict(struct iwl_trans *trans);
352990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_disable_ict(struct iwl_trans *trans);
3531a361cd838173879672cb0f0ebe1e7654d7edff6Emmanuel Grumbach
3541a361cd838173879672cb0f0ebe1e7654d7edff6Emmanuel Grumbach/*****************************************************
355253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach* TX / HCMD
356253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach******************************************************/
357f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachint iwl_pcie_tx_init(struct iwl_trans *trans);
358f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_pcie_tx_start(struct iwl_trans *trans, u32 scd_base_addr);
359f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachint iwl_pcie_tx_stop(struct iwl_trans *trans);
360f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_pcie_tx_free(struct iwl_trans *trans);
361f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int txq_id, int fifo,
362f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach			       int sta_id, int tid, int frame_limit, u16 ssn);
363f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int queue);
364f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachint iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
365f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach		      struct iwl_device_cmd *dev_cmd, int txq_id);
366990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_txq_inc_wr_ptr(struct iwl_trans *trans, struct iwl_txq *txq);
367f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachint iwl_trans_pcie_send_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
368990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_hcmd_complete(struct iwl_trans *trans,
369990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach			    struct iwl_rx_cmd_buffer *rxb, int handler_status);
370f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_trans_pcie_reclaim(struct iwl_trans *trans, int txq_id, int ssn,
371f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach			    struct sk_buff_head *skbs);
372ddaf5a5b300b8f9d3591b509fd8bedab1c9887beJohannes Bergvoid iwl_trans_pcie_tx_reset(struct iwl_trans *trans);
373ddaf5a5b300b8f9d3591b509fd8bedab1c9887beJohannes Berg
3747ff94706a055f3e21710b08ffbe3979d7db615dbEmmanuel Grumbach/*****************************************************
3757ff94706a055f3e21710b08ffbe3979d7db615dbEmmanuel Grumbach* Error handling
3767ff94706a055f3e21710b08ffbe3979d7db615dbEmmanuel Grumbach******************************************************/
377990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachint iwl_pcie_dump_fh(struct iwl_trans *trans, char **buf);
378990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_dump_csr(struct iwl_trans *trans);
37916db88ba51d669ef63c58990771a47208913152cEmmanuel Grumbach
3808ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach/*****************************************************
3818ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach* Helpers
3828ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach******************************************************/
3830c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbachstatic inline void iwl_disable_interrupts(struct iwl_trans *trans)
3840c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach{
38583626404a70da74c67f32f119e53c0ba032ba2d8Don Fry	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
38683626404a70da74c67f32f119e53c0ba032ba2d8Don Fry	clear_bit(STATUS_INT_ENABLED, &trans_pcie->status);
3870c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
3880c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	/* disable interrupts from uCode/NIC to host */
3891042db2af183b96cdce5972014d85e8bca0634adEmmanuel Grumbach	iwl_write32(trans, CSR_INT_MASK, 0x00000000);
3900c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
3910c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	/* acknowledge/clear/reset any interrupts still pending
3920c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	 * from uCode or flow handler (Rx/Tx DMA) */
3931042db2af183b96cdce5972014d85e8bca0634adEmmanuel Grumbach	iwl_write32(trans, CSR_INT, 0xffffffff);
3941042db2af183b96cdce5972014d85e8bca0634adEmmanuel Grumbach	iwl_write32(trans, CSR_FH_INT_STATUS, 0xffffffff);
3950c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	IWL_DEBUG_ISR(trans, "Disabled interrupts\n");
3960c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach}
3970c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
3980c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbachstatic inline void iwl_enable_interrupts(struct iwl_trans *trans)
3990c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach{
40083626404a70da74c67f32f119e53c0ba032ba2d8Don Fry	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
4010c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
4020c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	IWL_DEBUG_ISR(trans, "Enabling interrupts\n");
40383626404a70da74c67f32f119e53c0ba032ba2d8Don Fry	set_bit(STATUS_INT_ENABLED, &trans_pcie->status);
4041042db2af183b96cdce5972014d85e8bca0634adEmmanuel Grumbach	iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
4050c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach}
4060c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
4078722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszkastatic inline void iwl_enable_rfkill_int(struct iwl_trans *trans)
4088722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka{
4098722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka	IWL_DEBUG_ISR(trans, "Enabling rfkill interrupt\n");
4108722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka	iwl_write32(trans, CSR_INT_MASK, CSR_INT_BIT_RF_KILL);
4118722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka}
4128722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka
413e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbachstatic inline void iwl_wake_queue(struct iwl_trans *trans,
414990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach				  struct iwl_txq *txq)
415e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbach{
4169eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
4179eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg
4189eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	if (test_and_clear_bit(txq->q.id, trans_pcie->queue_stopped)) {
4199eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		IWL_DEBUG_TX_QUEUES(trans, "Wake hwq %d\n", txq->q.id);
4209eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		iwl_op_mode_queue_not_full(trans->op_mode, txq->q.id);
42181a3de1ce2929fef2b112c048c50bc52b686f94dEmmanuel Grumbach	}
422e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbach}
423e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbach
424e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbachstatic inline void iwl_stop_queue(struct iwl_trans *trans,
425990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach				  struct iwl_txq *txq)
426e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbach{
4279eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
4288ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach
4299eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	if (!test_and_set_bit(txq->q.id, trans_pcie->queue_stopped)) {
4309eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		iwl_op_mode_queue_full(trans->op_mode, txq->q.id);
4319eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		IWL_DEBUG_TX_QUEUES(trans, "Stop hwq %d\n", txq->q.id);
4329eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	} else
4339eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		IWL_DEBUG_TX_QUEUES(trans, "hwq %d already stopped\n",
4349eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg				    txq->q.id);
4358ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach}
4368ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach
4376ca6ebc1606c6fa7e8931445e84f21f4843e3babEmmanuel Grumbachstatic inline bool iwl_queue_used(const struct iwl_queue *q, int i)
4388ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach{
4398ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach	return q->write_ptr >= q->read_ptr ?
4408ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach		(i >= q->read_ptr && i < q->write_ptr) :
4418ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach		!(i < q->read_ptr && i >= q->write_ptr);
4428ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach}
4438ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach
4448ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbachstatic inline u8 get_cmd_index(struct iwl_queue *q, u32 index)
4458ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach{
4468ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach	return index & (q->n_window - 1);
4478ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach}
4488ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach
449990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachstatic inline const char *get_cmd_string(struct iwl_trans_pcie *trans_pcie,
450990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach					 u8 cmd)
451d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg{
452d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg	if (!trans_pcie->command_names || !trans_pcie->command_names[cmd])
453d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg		return "UNKNOWN";
454d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg	return trans_pcie->command_names[cmd];
455d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg}
456d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg
4578d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbachstatic inline bool iwl_is_rfkill_set(struct iwl_trans *trans)
4588d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach{
4598d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach	return !(iwl_read32(trans, CSR_GP_CNTRL) &
4608d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach		CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
4618d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach}
4628d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach
463ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach#endif /* __iwl_trans_int_pcie_h__ */
464