internal.h revision ddaf5a5b300b8f9d3591b509fd8bedab1c9887be
1ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach/******************************************************************************
2ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach *
34e3182626a914443a5e0fbe014813f03e51a75dfWey-Yi Guy * Copyright(c) 2003 - 2012 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
185990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachstruct iwl_pcie_txq_entry {
186bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg	struct iwl_device_cmd *cmd;
1879679142291f51515bd1bf492535e8a12515558e9Emmanuel Grumbach	struct iwl_device_cmd *copy_cmd;
188bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg	struct sk_buff *skb;
189f4feb8ac6e666d2ca37cf722166bbfadf2c6adf8Johannes Berg	/* buffer to free after command completes */
190f4feb8ac6e666d2ca37cf722166bbfadf2c6adf8Johannes Berg	const void *free_buf;
191bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg	struct iwl_cmd_meta meta;
192bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg};
193bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg
194522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach/**
195990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach * struct iwl_txq - Tx Queue for DMA
196522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * @q: generic Rx/Tx queue descriptor
197bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @tfds: transmit frame descriptors (DMA memory)
198bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @entries: transmit entries (driver state)
199bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @lock: queue lock
200bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @stuck_timer: timer that fires if queue gets stuck
201bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @trans_pcie: pointer back to transport (for timer)
202522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * @need_update: indicates need to update read/write index
203bf8440e6a6f5fabf7843dbfecb1745e49182fa1cJohannes Berg * @active: stores if queue is active
204522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach *
205522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
206522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach * descriptors) and required locking structures.
207522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach */
208990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachstruct iwl_txq {
209522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	struct iwl_queue q;
210522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	struct iwl_tfd *tfds;
211990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach	struct iwl_pcie_txq_entry *entries;
212015c15e1067c988fc87fb550b222f075c8d3f47cJohannes Berg	spinlock_t lock;
2137c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	struct timer_list stuck_timer;
2147c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	struct iwl_trans_pcie *trans_pcie;
215522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	u8 need_update;
216522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach	u8 active;
217522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach};
218522376d206da66cecc90929134ad70c0446e874bEmmanuel Grumbach
2195a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach/**
220e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbach * struct iwl_trans_pcie - PCIe transport specific data
2215a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @rxq: all the RX queue data
2225a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @rx_replenish: work that will be called when buffers need to be allocated
2239130bab137844d9ad3db6ab524de299cd2b9e39dEmmanuel Grumbach * @drv - pointer to iwl_drv
2245a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach * @trans: pointer to the generic transport area
225105183b156b7c220b47c3162e087101a0a6abc9fEmmanuel Grumbach * @scd_base_addr: scheduler sram base address in SRAM
226105183b156b7c220b47c3162e087101a0a6abc9fEmmanuel Grumbach * @scd_bc_tbls: pointer to the byte count table of the scheduler
2279d6b2cb1ccf9c1e00a0891eff78b93eb1a1fc372Emmanuel Grumbach * @kw: keep warm address
228a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach * @pci_dev: basic pci-network driver stuff
229a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach * @hw_base: pci hardware address support
23013df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg * @ucode_write_complete: indicates that the ucode has been copied.
23113df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg * @ucode_write_waitq: wait queue for uCode load
2329a716863ae4a2f039bc4d0b2b2bb4b24a1dc7a91Don Fry * @status - transport specific status flags
233c6f600fcfe8a7e4f594fc4c80b2c7b66f248958bMeenakshi Venkataraman * @cmd_queue - command queue number
234b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg * @rx_buf_size_8k: 8 kB RX buffer size
235046db346386661906dffa33f5ed3dfcdccfddc0bEmmanuel Grumbach * @bc_table_dword: true if the BC table expects DWORD (as opposed to bytes)
236b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg * @rx_page_order: page order for receive buffer size
2377c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg * @wd_timeout: queue watchdog timeout (jiffies)
238e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbach */
239e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbachstruct iwl_trans_pcie {
240990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach	struct iwl_rxq rxq;
2415a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	struct work_struct rx_replenish;
2425a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	struct iwl_trans *trans;
2439130bab137844d9ad3db6ab524de299cd2b9e39dEmmanuel Grumbach	struct iwl_drv *drv;
2440c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
2450c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	/* INT ICT Table */
2460c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	__le32 *ict_tbl;
2470c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	dma_addr_t ict_tbl_dma;
2480c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	int ict_index;
2490c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	u32 inta;
2500c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	bool use_ict;
2510c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	struct tasklet_struct irq_tasklet;
2521f7b6172db86e9ab2b4cd794441bb2c40ab287fcEmmanuel Grumbach	struct isr_statistics isr_stats;
2530c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
2547b11488fbbbe06ada39a396dec16532db8c933e6Johannes Berg	spinlock_t irq_lock;
2550c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	u32 inta_mask;
256105183b156b7c220b47c3162e087101a0a6abc9fEmmanuel Grumbach	u32 scd_base_addr;
257105183b156b7c220b47c3162e087101a0a6abc9fEmmanuel Grumbach	struct iwl_dma_ptr scd_bc_tbls;
2589d6b2cb1ccf9c1e00a0891eff78b93eb1a1fc372Emmanuel Grumbach	struct iwl_dma_ptr kw;
259e13c0c59e0ec38558ac853d56555e915b4dc7dc2Emmanuel Grumbach
260990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach	struct iwl_txq *txq;
2619eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	unsigned long queue_used[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
2628ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach	unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
263a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach
264a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach	/* PCI bus related data */
265a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach	struct pci_dev *pci_dev;
266a42a184458ae95937893cb873c988385637c5e14Emmanuel Grumbach	void __iomem *hw_base;
26713df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg
26813df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg	bool ucode_write_complete;
26913df1aab4aa3cd99693c0cdeb7177e5359218431Johannes Berg	wait_queue_head_t ucode_write_waitq;
270f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	wait_queue_head_t wait_command_queue;
271f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach
2729a716863ae4a2f039bc4d0b2b2bb4b24a1dc7a91Don Fry	unsigned long status;
273c6f600fcfe8a7e4f594fc4c80b2c7b66f248958bMeenakshi Venkataraman	u8 cmd_queue;
274b04db9ac4f7641332e0133b2fd8f82e6e4553947Emmanuel Grumbach	u8 cmd_fifo;
275d663ee73f62903aed334eca25832a76c4a7e4c1cJohannes Berg	u8 n_no_reclaim_cmds;
276d663ee73f62903aed334eca25832a76c4a7e4c1cJohannes Berg	u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];
277b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg
278b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg	bool rx_buf_size_8k;
279046db346386661906dffa33f5ed3dfcdccfddc0bEmmanuel Grumbach	bool bc_table_dword;
280b2cf410ccb927141e69aa610b6dcf5137701f3afJohannes Berg	u32 rx_page_order;
2817c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg
282d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg	const char **command_names;
2837c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg
2847c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	/* queue watchdog */
2857c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	unsigned long wd_timeout;
286e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbach};
287e6bb4c9c00892c488f3218ea317dc6a71674faf4Emmanuel Grumbach
288b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach/**
289b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * enum iwl_pcie_status: status of the PCIe transport
290b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_HCMD_ACTIVE: a SYNC command is being processed
291b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_DEVICE_ENABLED: APM is enabled
292b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_TPOWER_PMI: the device might be asleep (need to wake it up)
293b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_INT_ENABLED: interrupts are enabled
294b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_RFKILL: the HW RFkill switch is in KILL position
295b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach * @STATUS_FW_ERROR: the fw is in error state
296b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbach */
297b55e57f53f8740a2d1432e4963372d303b798530Emmanuel Grumbachenum iwl_pcie_status {
298f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_HCMD_ACTIVE,
299f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_DEVICE_ENABLED,
300f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_TPOWER_PMI,
301f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_INT_ENABLED,
302f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach	STATUS_RFKILL,
303d18aa87fbfe80f33076942d11f19c9d813e835b1Johannes Berg	STATUS_FW_ERROR,
304f946b529502399d09471c5d13845fefbfe8555a6Emmanuel Grumbach};
30501d651d4b7f40c90821e104963dc04800fbde8cfDon Fry
3065a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach#define IWL_TRANS_GET_PCIE_TRANS(_iwl_trans) \
3075a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach	((struct iwl_trans_pcie *) ((_iwl_trans)->trans_specific))
3085a878bf60b2bb1f1509f49b8b1784e3c9f204c64Emmanuel Grumbach
3097c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Bergstatic inline struct iwl_trans *
3107c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Bergiwl_trans_pcie_get_trans(struct iwl_trans_pcie *trans_pcie)
3117c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg{
3127c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg	return container_of((void *)trans_pcie, struct iwl_trans,
3137c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg			    trans_specific);
3147c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg}
3157c5ba4a830cbb730770129b0004e2a06e47dbac5Johannes Berg
316f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach/*
317f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach * Convention: trans API functions: iwl_trans_pcie_XXX
318f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach *	Other functions: iwl_pcie_XXX
319f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach */
320d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Bergstruct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
321d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Berg				       const struct pci_device_id *ent,
322d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Berg				       const struct iwl_cfg *cfg);
323d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Bergvoid iwl_trans_pcie_free(struct iwl_trans *trans);
324d1ff52536a0d1bd516a628ef43dfaf6fe9c90fe2Johannes Berg
325253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach/*****************************************************
326253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach* RX
327253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach******************************************************/
3289805c4460ae37aa9328a470c7aebea32f0667e24Emmanuel Grumbachint iwl_pcie_rx_init(struct iwl_trans *trans);
329990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_tasklet(struct iwl_trans *trans);
3309805c4460ae37aa9328a470c7aebea32f0667e24Emmanuel Grumbachint iwl_pcie_rx_stop(struct iwl_trans *trans);
3319805c4460ae37aa9328a470c7aebea32f0667e24Emmanuel Grumbachvoid iwl_pcie_rx_free(struct iwl_trans *trans);
332ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach
333253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach/*****************************************************
334990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach* ICT - interrupt handling
3351a361cd838173879672cb0f0ebe1e7654d7edff6Emmanuel Grumbach******************************************************/
336990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachirqreturn_t iwl_pcie_isr_ict(int irq, void *data);
337990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachint iwl_pcie_alloc_ict(struct iwl_trans *trans);
338990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_free_ict(struct iwl_trans *trans);
339990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_reset_ict(struct iwl_trans *trans);
340990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_disable_ict(struct iwl_trans *trans);
3411a361cd838173879672cb0f0ebe1e7654d7edff6Emmanuel Grumbach
3421a361cd838173879672cb0f0ebe1e7654d7edff6Emmanuel Grumbach/*****************************************************
343253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach* TX / HCMD
344253a634ccd1b291282cd0cade219bd90eb0371ebEmmanuel Grumbach******************************************************/
345f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachint iwl_pcie_tx_init(struct iwl_trans *trans);
346f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_pcie_tx_start(struct iwl_trans *trans, u32 scd_base_addr);
347f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachint iwl_pcie_tx_stop(struct iwl_trans *trans);
348f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_pcie_tx_free(struct iwl_trans *trans);
349f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int txq_id, int fifo,
350f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach			       int sta_id, int tid, int frame_limit, u16 ssn);
351f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int queue);
352f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachint iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
353f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach		      struct iwl_device_cmd *dev_cmd, int txq_id);
354990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_txq_inc_wr_ptr(struct iwl_trans *trans, struct iwl_txq *txq);
355f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachint iwl_trans_pcie_send_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
356990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_hcmd_complete(struct iwl_trans *trans,
357990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach			    struct iwl_rx_cmd_buffer *rxb, int handler_status);
358f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbachvoid iwl_trans_pcie_reclaim(struct iwl_trans *trans, int txq_id, int ssn,
359f02831be962c7be68c72110fa779e916ab1a8cddEmmanuel Grumbach			    struct sk_buff_head *skbs);
360ddaf5a5b300b8f9d3591b509fd8bedab1c9887beJohannes Bergvoid iwl_trans_pcie_tx_reset(struct iwl_trans *trans);
361ddaf5a5b300b8f9d3591b509fd8bedab1c9887beJohannes Berg
3627ff94706a055f3e21710b08ffbe3979d7db615dbEmmanuel Grumbach/*****************************************************
3637ff94706a055f3e21710b08ffbe3979d7db615dbEmmanuel Grumbach* Error handling
3647ff94706a055f3e21710b08ffbe3979d7db615dbEmmanuel Grumbach******************************************************/
365990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachint iwl_pcie_dump_fh(struct iwl_trans *trans, char **buf);
366990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachvoid iwl_pcie_dump_csr(struct iwl_trans *trans);
36716db88ba51d669ef63c58990771a47208913152cEmmanuel Grumbach
3688ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach/*****************************************************
3698ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach* Helpers
3708ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach******************************************************/
3710c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbachstatic inline void iwl_disable_interrupts(struct iwl_trans *trans)
3720c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach{
37383626404a70da74c67f32f119e53c0ba032ba2d8Don Fry	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
37483626404a70da74c67f32f119e53c0ba032ba2d8Don Fry	clear_bit(STATUS_INT_ENABLED, &trans_pcie->status);
3750c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
3760c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	/* disable interrupts from uCode/NIC to host */
3771042db2af183b96cdce5972014d85e8bca0634adEmmanuel Grumbach	iwl_write32(trans, CSR_INT_MASK, 0x00000000);
3780c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
3790c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	/* acknowledge/clear/reset any interrupts still pending
3800c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	 * from uCode or flow handler (Rx/Tx DMA) */
3811042db2af183b96cdce5972014d85e8bca0634adEmmanuel Grumbach	iwl_write32(trans, CSR_INT, 0xffffffff);
3821042db2af183b96cdce5972014d85e8bca0634adEmmanuel Grumbach	iwl_write32(trans, CSR_FH_INT_STATUS, 0xffffffff);
3830c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	IWL_DEBUG_ISR(trans, "Disabled interrupts\n");
3840c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach}
3850c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
3860c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbachstatic inline void iwl_enable_interrupts(struct iwl_trans *trans)
3870c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach{
38883626404a70da74c67f32f119e53c0ba032ba2d8Don Fry	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
3890c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
3900c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach	IWL_DEBUG_ISR(trans, "Enabling interrupts\n");
39183626404a70da74c67f32f119e53c0ba032ba2d8Don Fry	set_bit(STATUS_INT_ENABLED, &trans_pcie->status);
3921042db2af183b96cdce5972014d85e8bca0634adEmmanuel Grumbach	iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
3930c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach}
3940c325769a394559941acda83e888a1d9b1ef8b7fEmmanuel Grumbach
3958722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszkastatic inline void iwl_enable_rfkill_int(struct iwl_trans *trans)
3968722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka{
3978722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka	IWL_DEBUG_ISR(trans, "Enabling rfkill interrupt\n");
3988722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka	iwl_write32(trans, CSR_INT_MASK, CSR_INT_BIT_RF_KILL);
3998722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka}
4008722c899a07f45457464803142bd1c2d2a2c3bd8Stanislaw Gruszka
401e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbachstatic inline void iwl_wake_queue(struct iwl_trans *trans,
402990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach				  struct iwl_txq *txq)
403e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbach{
4049eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
4059eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg
4069eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	if (test_and_clear_bit(txq->q.id, trans_pcie->queue_stopped)) {
4079eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		IWL_DEBUG_TX_QUEUES(trans, "Wake hwq %d\n", txq->q.id);
4089eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		iwl_op_mode_queue_not_full(trans->op_mode, txq->q.id);
40981a3de1ce2929fef2b112c048c50bc52b686f94dEmmanuel Grumbach	}
410e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbach}
411e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbach
412e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbachstatic inline void iwl_stop_queue(struct iwl_trans *trans,
413990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach				  struct iwl_txq *txq)
414e20d434170c3a7f388d5e916825499c9c0738606Emmanuel Grumbach{
4159eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
4168ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach
4179eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	if (!test_and_set_bit(txq->q.id, trans_pcie->queue_stopped)) {
4189eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		iwl_op_mode_queue_full(trans->op_mode, txq->q.id);
4199eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		IWL_DEBUG_TX_QUEUES(trans, "Stop hwq %d\n", txq->q.id);
4209eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg	} else
4219eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg		IWL_DEBUG_TX_QUEUES(trans, "hwq %d already stopped\n",
4229eae88fa9a02e31af69a215beaa5e1194da3a5a1Johannes Berg				    txq->q.id);
4238ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach}
4248ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach
4256ca6ebc1606c6fa7e8931445e84f21f4843e3babEmmanuel Grumbachstatic inline bool iwl_queue_used(const struct iwl_queue *q, int i)
4268ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach{
4278ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach	return q->write_ptr >= q->read_ptr ?
4288ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach		(i >= q->read_ptr && i < q->write_ptr) :
4298ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach		!(i < q->read_ptr && i >= q->write_ptr);
4308ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach}
4318ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach
4328ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbachstatic inline u8 get_cmd_index(struct iwl_queue *q, u32 index)
4338ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach{
4348ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach	return index & (q->n_window - 1);
4358ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach}
4368ad71bef4a9d8173cbcfbb2f796b08d33d4ca01bEmmanuel Grumbach
437990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbachstatic inline const char *get_cmd_string(struct iwl_trans_pcie *trans_pcie,
438990aa6d7b28d26bf22171410b49f191e8e9b09fcEmmanuel Grumbach					 u8 cmd)
439d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg{
440d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg	if (!trans_pcie->command_names || !trans_pcie->command_names[cmd])
441d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg		return "UNKNOWN";
442d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg	return trans_pcie->command_names[cmd];
443d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg}
444d9fb6465802c2279ea14cc26eb66d17c133478b1Johannes Berg
4458d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbachstatic inline bool iwl_is_rfkill_set(struct iwl_trans *trans)
4468d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach{
4478d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach	return !(iwl_read32(trans, CSR_GP_CNTRL) &
4488d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach		CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
4498d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach}
4508d425517f1f08f01a6171d22e05be62ef6ad93fcEmmanuel Grumbach
451ab697a9f1e73ba817955e15bd899a8a0627f9fd6Emmanuel Grumbach#endif /* __iwl_trans_int_pcie_h__ */
452