1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * This file is provided under a dual BSD/GPLv2 license. When using or
4*4882a593Smuzhiyun * redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * GPL LICENSE SUMMARY
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
9*4882a593Smuzhiyun * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10*4882a593Smuzhiyun * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11*4882a593Smuzhiyun * Copyright(c) 2018 - 2019 Intel Corporation
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify it
14*4882a593Smuzhiyun * under the terms of version 2 of the GNU General Public License as
15*4882a593Smuzhiyun * published by the Free Software Foundation.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but WITHOUT
18*4882a593Smuzhiyun * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20*4882a593Smuzhiyun * more details.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * The full GNU General Public License is included in this distribution in the
23*4882a593Smuzhiyun * file called COPYING.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * Contact Information:
26*4882a593Smuzhiyun * Intel Linux Wireless <linuxwifi@intel.com>
27*4882a593Smuzhiyun * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28*4882a593Smuzhiyun *
29*4882a593Smuzhiyun * BSD LICENSE
30*4882a593Smuzhiyun *
31*4882a593Smuzhiyun * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
32*4882a593Smuzhiyun * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33*4882a593Smuzhiyun * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34*4882a593Smuzhiyun * Copyright(c) 2018 - 2019 Intel Corporation
35*4882a593Smuzhiyun * All rights reserved.
36*4882a593Smuzhiyun *
37*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
38*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
39*4882a593Smuzhiyun * are met:
40*4882a593Smuzhiyun *
41*4882a593Smuzhiyun * * Redistributions of source code must retain the above copyright
42*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
43*4882a593Smuzhiyun * * Redistributions in binary form must reproduce the above copyright
44*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in
45*4882a593Smuzhiyun * the documentation and/or other materials provided with the
46*4882a593Smuzhiyun * distribution.
47*4882a593Smuzhiyun * * Neither the name Intel Corporation nor the names of its
48*4882a593Smuzhiyun * contributors may be used to endorse or promote products derived
49*4882a593Smuzhiyun * from this software without specific prior written permission.
50*4882a593Smuzhiyun *
51*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55*4882a593Smuzhiyun * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56*4882a593Smuzhiyun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57*4882a593Smuzhiyun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58*4882a593Smuzhiyun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59*4882a593Smuzhiyun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61*4882a593Smuzhiyun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62*4882a593Smuzhiyun *
63*4882a593Smuzhiyun *****************************************************************************/
64*4882a593Smuzhiyun #include <linux/sched.h>
65*4882a593Smuzhiyun #include <linux/wait.h>
66*4882a593Smuzhiyun #include <linux/gfp.h>
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #include "iwl-prph.h"
69*4882a593Smuzhiyun #include "iwl-io.h"
70*4882a593Smuzhiyun #include "internal.h"
71*4882a593Smuzhiyun #include "iwl-op-mode.h"
72*4882a593Smuzhiyun #include "iwl-context-info-gen3.h"
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /******************************************************************************
75*4882a593Smuzhiyun *
76*4882a593Smuzhiyun * RX path functions
77*4882a593Smuzhiyun *
78*4882a593Smuzhiyun ******************************************************************************/
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /*
81*4882a593Smuzhiyun * Rx theory of operation
82*4882a593Smuzhiyun *
83*4882a593Smuzhiyun * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
84*4882a593Smuzhiyun * each of which point to Receive Buffers to be filled by the NIC. These get
85*4882a593Smuzhiyun * used not only for Rx frames, but for any command response or notification
86*4882a593Smuzhiyun * from the NIC. The driver and NIC manage the Rx buffers by means
87*4882a593Smuzhiyun * of indexes into the circular buffer.
88*4882a593Smuzhiyun *
89*4882a593Smuzhiyun * Rx Queue Indexes
90*4882a593Smuzhiyun * The host/firmware share two index registers for managing the Rx buffers.
91*4882a593Smuzhiyun *
92*4882a593Smuzhiyun * The READ index maps to the first position that the firmware may be writing
93*4882a593Smuzhiyun * to -- the driver can read up to (but not including) this position and get
94*4882a593Smuzhiyun * good data.
95*4882a593Smuzhiyun * The READ index is managed by the firmware once the card is enabled.
96*4882a593Smuzhiyun *
97*4882a593Smuzhiyun * The WRITE index maps to the last position the driver has read from -- the
98*4882a593Smuzhiyun * position preceding WRITE is the last slot the firmware can place a packet.
99*4882a593Smuzhiyun *
100*4882a593Smuzhiyun * The queue is empty (no good data) if WRITE = READ - 1, and is full if
101*4882a593Smuzhiyun * WRITE = READ.
102*4882a593Smuzhiyun *
103*4882a593Smuzhiyun * During initialization, the host sets up the READ queue position to the first
104*4882a593Smuzhiyun * INDEX position, and WRITE to the last (READ - 1 wrapped)
105*4882a593Smuzhiyun *
106*4882a593Smuzhiyun * When the firmware places a packet in a buffer, it will advance the READ index
107*4882a593Smuzhiyun * and fire the RX interrupt. The driver can then query the READ index and
108*4882a593Smuzhiyun * process as many packets as possible, moving the WRITE index forward as it
109*4882a593Smuzhiyun * resets the Rx queue buffers with new memory.
110*4882a593Smuzhiyun *
111*4882a593Smuzhiyun * The management in the driver is as follows:
112*4882a593Smuzhiyun * + A list of pre-allocated RBDs is stored in iwl->rxq->rx_free.
113*4882a593Smuzhiyun * When the interrupt handler is called, the request is processed.
114*4882a593Smuzhiyun * The page is either stolen - transferred to the upper layer
115*4882a593Smuzhiyun * or reused - added immediately to the iwl->rxq->rx_free list.
116*4882a593Smuzhiyun * + When the page is stolen - the driver updates the matching queue's used
117*4882a593Smuzhiyun * count, detaches the RBD and transfers it to the queue used list.
118*4882a593Smuzhiyun * When there are two used RBDs - they are transferred to the allocator empty
119*4882a593Smuzhiyun * list. Work is then scheduled for the allocator to start allocating
120*4882a593Smuzhiyun * eight buffers.
121*4882a593Smuzhiyun * When there are another 6 used RBDs - they are transferred to the allocator
122*4882a593Smuzhiyun * empty list and the driver tries to claim the pre-allocated buffers and
123*4882a593Smuzhiyun * add them to iwl->rxq->rx_free. If it fails - it continues to claim them
124*4882a593Smuzhiyun * until ready.
125*4882a593Smuzhiyun * When there are 8+ buffers in the free list - either from allocation or from
126*4882a593Smuzhiyun * 8 reused unstolen pages - restock is called to update the FW and indexes.
127*4882a593Smuzhiyun * + In order to make sure the allocator always has RBDs to use for allocation
128*4882a593Smuzhiyun * the allocator has initial pool in the size of num_queues*(8-2) - the
129*4882a593Smuzhiyun * maximum missing RBDs per allocation request (request posted with 2
130*4882a593Smuzhiyun * empty RBDs, there is no guarantee when the other 6 RBDs are supplied).
131*4882a593Smuzhiyun * The queues supplies the recycle of the rest of the RBDs.
132*4882a593Smuzhiyun * + A received packet is processed and handed to the kernel network stack,
133*4882a593Smuzhiyun * detached from the iwl->rxq. The driver 'processed' index is updated.
134*4882a593Smuzhiyun * + If there are no allocated buffers in iwl->rxq->rx_free,
135*4882a593Smuzhiyun * the READ INDEX is not incremented and iwl->status(RX_STALLED) is set.
136*4882a593Smuzhiyun * If there were enough free buffers and RX_STALLED is set it is cleared.
137*4882a593Smuzhiyun *
138*4882a593Smuzhiyun *
139*4882a593Smuzhiyun * Driver sequence:
140*4882a593Smuzhiyun *
141*4882a593Smuzhiyun * iwl_rxq_alloc() Allocates rx_free
142*4882a593Smuzhiyun * iwl_pcie_rx_replenish() Replenishes rx_free list from rx_used, and calls
143*4882a593Smuzhiyun * iwl_pcie_rxq_restock.
144*4882a593Smuzhiyun * Used only during initialization.
145*4882a593Smuzhiyun * iwl_pcie_rxq_restock() Moves available buffers from rx_free into Rx
146*4882a593Smuzhiyun * queue, updates firmware pointers, and updates
147*4882a593Smuzhiyun * the WRITE index.
148*4882a593Smuzhiyun * iwl_pcie_rx_allocator() Background work for allocating pages.
149*4882a593Smuzhiyun *
150*4882a593Smuzhiyun * -- enable interrupts --
151*4882a593Smuzhiyun * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the
152*4882a593Smuzhiyun * READ INDEX, detaching the SKB from the pool.
153*4882a593Smuzhiyun * Moves the packet buffer from queue to rx_used.
154*4882a593Smuzhiyun * Posts and claims requests to the allocator.
155*4882a593Smuzhiyun * Calls iwl_pcie_rxq_restock to refill any empty
156*4882a593Smuzhiyun * slots.
157*4882a593Smuzhiyun *
158*4882a593Smuzhiyun * RBD life-cycle:
159*4882a593Smuzhiyun *
160*4882a593Smuzhiyun * Init:
161*4882a593Smuzhiyun * rxq.pool -> rxq.rx_used -> rxq.rx_free -> rxq.queue
162*4882a593Smuzhiyun *
163*4882a593Smuzhiyun * Regular Receive interrupt:
164*4882a593Smuzhiyun * Page Stolen:
165*4882a593Smuzhiyun * rxq.queue -> rxq.rx_used -> allocator.rbd_empty ->
166*4882a593Smuzhiyun * allocator.rbd_allocated -> rxq.rx_free -> rxq.queue
167*4882a593Smuzhiyun * Page not Stolen:
168*4882a593Smuzhiyun * rxq.queue -> rxq.rx_free -> rxq.queue
169*4882a593Smuzhiyun * ...
170*4882a593Smuzhiyun *
171*4882a593Smuzhiyun */
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun /*
174*4882a593Smuzhiyun * iwl_rxq_space - Return number of free slots available in queue.
175*4882a593Smuzhiyun */
iwl_rxq_space(const struct iwl_rxq * rxq)176*4882a593Smuzhiyun static int iwl_rxq_space(const struct iwl_rxq *rxq)
177*4882a593Smuzhiyun {
178*4882a593Smuzhiyun /* Make sure rx queue size is a power of 2 */
179*4882a593Smuzhiyun WARN_ON(rxq->queue_size & (rxq->queue_size - 1));
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun /*
182*4882a593Smuzhiyun * There can be up to (RX_QUEUE_SIZE - 1) free slots, to avoid ambiguity
183*4882a593Smuzhiyun * between empty and completely full queues.
184*4882a593Smuzhiyun * The following is equivalent to modulo by RX_QUEUE_SIZE and is well
185*4882a593Smuzhiyun * defined for negative dividends.
186*4882a593Smuzhiyun */
187*4882a593Smuzhiyun return (rxq->read - rxq->write - 1) & (rxq->queue_size - 1);
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun /*
191*4882a593Smuzhiyun * iwl_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
192*4882a593Smuzhiyun */
iwl_pcie_dma_addr2rbd_ptr(dma_addr_t dma_addr)193*4882a593Smuzhiyun static inline __le32 iwl_pcie_dma_addr2rbd_ptr(dma_addr_t dma_addr)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun return cpu_to_le32((u32)(dma_addr >> 8));
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun /*
199*4882a593Smuzhiyun * iwl_pcie_rx_stop - stops the Rx DMA
200*4882a593Smuzhiyun */
iwl_pcie_rx_stop(struct iwl_trans * trans)201*4882a593Smuzhiyun int iwl_pcie_rx_stop(struct iwl_trans *trans)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
204*4882a593Smuzhiyun /* TODO: remove this once fw does it */
205*4882a593Smuzhiyun iwl_write_umac_prph(trans, RFH_RXF_DMA_CFG_GEN3, 0);
206*4882a593Smuzhiyun return iwl_poll_umac_prph_bit(trans, RFH_GEN_STATUS_GEN3,
207*4882a593Smuzhiyun RXF_DMA_IDLE, RXF_DMA_IDLE, 1000);
208*4882a593Smuzhiyun } else if (trans->trans_cfg->mq_rx_supported) {
209*4882a593Smuzhiyun iwl_write_prph(trans, RFH_RXF_DMA_CFG, 0);
210*4882a593Smuzhiyun return iwl_poll_prph_bit(trans, RFH_GEN_STATUS,
211*4882a593Smuzhiyun RXF_DMA_IDLE, RXF_DMA_IDLE, 1000);
212*4882a593Smuzhiyun } else {
213*4882a593Smuzhiyun iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
214*4882a593Smuzhiyun return iwl_poll_direct_bit(trans, FH_MEM_RSSR_RX_STATUS_REG,
215*4882a593Smuzhiyun FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE,
216*4882a593Smuzhiyun 1000);
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun /*
221*4882a593Smuzhiyun * iwl_pcie_rxq_inc_wr_ptr - Update the write pointer for the RX queue
222*4882a593Smuzhiyun */
iwl_pcie_rxq_inc_wr_ptr(struct iwl_trans * trans,struct iwl_rxq * rxq)223*4882a593Smuzhiyun static void iwl_pcie_rxq_inc_wr_ptr(struct iwl_trans *trans,
224*4882a593Smuzhiyun struct iwl_rxq *rxq)
225*4882a593Smuzhiyun {
226*4882a593Smuzhiyun u32 reg;
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun lockdep_assert_held(&rxq->lock);
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun /*
231*4882a593Smuzhiyun * explicitly wake up the NIC if:
232*4882a593Smuzhiyun * 1. shadow registers aren't enabled
233*4882a593Smuzhiyun * 2. there is a chance that the NIC is asleep
234*4882a593Smuzhiyun */
235*4882a593Smuzhiyun if (!trans->trans_cfg->base_params->shadow_reg_enable &&
236*4882a593Smuzhiyun test_bit(STATUS_TPOWER_PMI, &trans->status)) {
237*4882a593Smuzhiyun reg = iwl_read32(trans, CSR_UCODE_DRV_GP1);
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
240*4882a593Smuzhiyun IWL_DEBUG_INFO(trans, "Rx queue requesting wakeup, GP1 = 0x%x\n",
241*4882a593Smuzhiyun reg);
242*4882a593Smuzhiyun iwl_set_bit(trans, CSR_GP_CNTRL,
243*4882a593Smuzhiyun CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
244*4882a593Smuzhiyun rxq->need_update = true;
245*4882a593Smuzhiyun return;
246*4882a593Smuzhiyun }
247*4882a593Smuzhiyun }
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun rxq->write_actual = round_down(rxq->write, 8);
250*4882a593Smuzhiyun if (trans->trans_cfg->mq_rx_supported)
251*4882a593Smuzhiyun iwl_write32(trans, RFH_Q_FRBDCB_WIDX_TRG(rxq->id),
252*4882a593Smuzhiyun rxq->write_actual);
253*4882a593Smuzhiyun else
254*4882a593Smuzhiyun iwl_write32(trans, FH_RSCSR_CHNL0_WPTR, rxq->write_actual);
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun
iwl_pcie_rxq_check_wrptr(struct iwl_trans * trans)257*4882a593Smuzhiyun static void iwl_pcie_rxq_check_wrptr(struct iwl_trans *trans)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
260*4882a593Smuzhiyun int i;
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun for (i = 0; i < trans->num_rx_queues; i++) {
263*4882a593Smuzhiyun struct iwl_rxq *rxq = &trans_pcie->rxq[i];
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun if (!rxq->need_update)
266*4882a593Smuzhiyun continue;
267*4882a593Smuzhiyun spin_lock(&rxq->lock);
268*4882a593Smuzhiyun iwl_pcie_rxq_inc_wr_ptr(trans, rxq);
269*4882a593Smuzhiyun rxq->need_update = false;
270*4882a593Smuzhiyun spin_unlock(&rxq->lock);
271*4882a593Smuzhiyun }
272*4882a593Smuzhiyun }
273*4882a593Smuzhiyun
iwl_pcie_restock_bd(struct iwl_trans * trans,struct iwl_rxq * rxq,struct iwl_rx_mem_buffer * rxb)274*4882a593Smuzhiyun static void iwl_pcie_restock_bd(struct iwl_trans *trans,
275*4882a593Smuzhiyun struct iwl_rxq *rxq,
276*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb)
277*4882a593Smuzhiyun {
278*4882a593Smuzhiyun if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
279*4882a593Smuzhiyun struct iwl_rx_transfer_desc *bd = rxq->bd;
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun BUILD_BUG_ON(sizeof(*bd) != 2 * sizeof(u64));
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun bd[rxq->write].addr = cpu_to_le64(rxb->page_dma);
284*4882a593Smuzhiyun bd[rxq->write].rbid = cpu_to_le16(rxb->vid);
285*4882a593Smuzhiyun } else {
286*4882a593Smuzhiyun __le64 *bd = rxq->bd;
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun bd[rxq->write] = cpu_to_le64(rxb->page_dma | rxb->vid);
289*4882a593Smuzhiyun }
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun IWL_DEBUG_RX(trans, "Assigned virtual RB ID %u to queue %d index %d\n",
292*4882a593Smuzhiyun (u32)rxb->vid, rxq->id, rxq->write);
293*4882a593Smuzhiyun }
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun /*
296*4882a593Smuzhiyun * iwl_pcie_rxmq_restock - restock implementation for multi-queue rx
297*4882a593Smuzhiyun */
iwl_pcie_rxmq_restock(struct iwl_trans * trans,struct iwl_rxq * rxq)298*4882a593Smuzhiyun static void iwl_pcie_rxmq_restock(struct iwl_trans *trans,
299*4882a593Smuzhiyun struct iwl_rxq *rxq)
300*4882a593Smuzhiyun {
301*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
302*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb;
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun /*
305*4882a593Smuzhiyun * If the device isn't enabled - no need to try to add buffers...
306*4882a593Smuzhiyun * This can happen when we stop the device and still have an interrupt
307*4882a593Smuzhiyun * pending. We stop the APM before we sync the interrupts because we
308*4882a593Smuzhiyun * have to (see comment there). On the other hand, since the APM is
309*4882a593Smuzhiyun * stopped, we cannot access the HW (in particular not prph).
310*4882a593Smuzhiyun * So don't try to restock if the APM has been already stopped.
311*4882a593Smuzhiyun */
312*4882a593Smuzhiyun if (!test_bit(STATUS_DEVICE_ENABLED, &trans->status))
313*4882a593Smuzhiyun return;
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun spin_lock(&rxq->lock);
316*4882a593Smuzhiyun while (rxq->free_count) {
317*4882a593Smuzhiyun /* Get next free Rx buffer, remove from free list */
318*4882a593Smuzhiyun rxb = list_first_entry(&rxq->rx_free, struct iwl_rx_mem_buffer,
319*4882a593Smuzhiyun list);
320*4882a593Smuzhiyun list_del(&rxb->list);
321*4882a593Smuzhiyun rxb->invalid = false;
322*4882a593Smuzhiyun /* some low bits are expected to be unset (depending on hw) */
323*4882a593Smuzhiyun WARN_ON(rxb->page_dma & trans_pcie->supported_dma_mask);
324*4882a593Smuzhiyun /* Point to Rx buffer via next RBD in circular buffer */
325*4882a593Smuzhiyun iwl_pcie_restock_bd(trans, rxq, rxb);
326*4882a593Smuzhiyun rxq->write = (rxq->write + 1) & (rxq->queue_size - 1);
327*4882a593Smuzhiyun rxq->free_count--;
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun spin_unlock(&rxq->lock);
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun /*
332*4882a593Smuzhiyun * If we've added more space for the firmware to place data, tell it.
333*4882a593Smuzhiyun * Increment device's write pointer in multiples of 8.
334*4882a593Smuzhiyun */
335*4882a593Smuzhiyun if (rxq->write_actual != (rxq->write & ~0x7)) {
336*4882a593Smuzhiyun spin_lock(&rxq->lock);
337*4882a593Smuzhiyun iwl_pcie_rxq_inc_wr_ptr(trans, rxq);
338*4882a593Smuzhiyun spin_unlock(&rxq->lock);
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun /*
343*4882a593Smuzhiyun * iwl_pcie_rxsq_restock - restock implementation for single queue rx
344*4882a593Smuzhiyun */
iwl_pcie_rxsq_restock(struct iwl_trans * trans,struct iwl_rxq * rxq)345*4882a593Smuzhiyun static void iwl_pcie_rxsq_restock(struct iwl_trans *trans,
346*4882a593Smuzhiyun struct iwl_rxq *rxq)
347*4882a593Smuzhiyun {
348*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb;
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun /*
351*4882a593Smuzhiyun * If the device isn't enabled - not need to try to add buffers...
352*4882a593Smuzhiyun * This can happen when we stop the device and still have an interrupt
353*4882a593Smuzhiyun * pending. We stop the APM before we sync the interrupts because we
354*4882a593Smuzhiyun * have to (see comment there). On the other hand, since the APM is
355*4882a593Smuzhiyun * stopped, we cannot access the HW (in particular not prph).
356*4882a593Smuzhiyun * So don't try to restock if the APM has been already stopped.
357*4882a593Smuzhiyun */
358*4882a593Smuzhiyun if (!test_bit(STATUS_DEVICE_ENABLED, &trans->status))
359*4882a593Smuzhiyun return;
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun spin_lock(&rxq->lock);
362*4882a593Smuzhiyun while ((iwl_rxq_space(rxq) > 0) && (rxq->free_count)) {
363*4882a593Smuzhiyun __le32 *bd = (__le32 *)rxq->bd;
364*4882a593Smuzhiyun /* The overwritten rxb must be a used one */
365*4882a593Smuzhiyun rxb = rxq->queue[rxq->write];
366*4882a593Smuzhiyun BUG_ON(rxb && rxb->page);
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun /* Get next free Rx buffer, remove from free list */
369*4882a593Smuzhiyun rxb = list_first_entry(&rxq->rx_free, struct iwl_rx_mem_buffer,
370*4882a593Smuzhiyun list);
371*4882a593Smuzhiyun list_del(&rxb->list);
372*4882a593Smuzhiyun rxb->invalid = false;
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun /* Point to Rx buffer via next RBD in circular buffer */
375*4882a593Smuzhiyun bd[rxq->write] = iwl_pcie_dma_addr2rbd_ptr(rxb->page_dma);
376*4882a593Smuzhiyun rxq->queue[rxq->write] = rxb;
377*4882a593Smuzhiyun rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
378*4882a593Smuzhiyun rxq->free_count--;
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun spin_unlock(&rxq->lock);
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun /* If we've added more space for the firmware to place data, tell it.
383*4882a593Smuzhiyun * Increment device's write pointer in multiples of 8. */
384*4882a593Smuzhiyun if (rxq->write_actual != (rxq->write & ~0x7)) {
385*4882a593Smuzhiyun spin_lock(&rxq->lock);
386*4882a593Smuzhiyun iwl_pcie_rxq_inc_wr_ptr(trans, rxq);
387*4882a593Smuzhiyun spin_unlock(&rxq->lock);
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun }
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun /*
392*4882a593Smuzhiyun * iwl_pcie_rxq_restock - refill RX queue from pre-allocated pool
393*4882a593Smuzhiyun *
394*4882a593Smuzhiyun * If there are slots in the RX queue that need to be restocked,
395*4882a593Smuzhiyun * and we have free pre-allocated buffers, fill the ranks as much
396*4882a593Smuzhiyun * as we can, pulling from rx_free.
397*4882a593Smuzhiyun *
398*4882a593Smuzhiyun * This moves the 'write' index forward to catch up with 'processed', and
399*4882a593Smuzhiyun * also updates the memory address in the firmware to reference the new
400*4882a593Smuzhiyun * target buffer.
401*4882a593Smuzhiyun */
402*4882a593Smuzhiyun static
iwl_pcie_rxq_restock(struct iwl_trans * trans,struct iwl_rxq * rxq)403*4882a593Smuzhiyun void iwl_pcie_rxq_restock(struct iwl_trans *trans, struct iwl_rxq *rxq)
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun if (trans->trans_cfg->mq_rx_supported)
406*4882a593Smuzhiyun iwl_pcie_rxmq_restock(trans, rxq);
407*4882a593Smuzhiyun else
408*4882a593Smuzhiyun iwl_pcie_rxsq_restock(trans, rxq);
409*4882a593Smuzhiyun }
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun /*
412*4882a593Smuzhiyun * iwl_pcie_rx_alloc_page - allocates and returns a page.
413*4882a593Smuzhiyun *
414*4882a593Smuzhiyun */
iwl_pcie_rx_alloc_page(struct iwl_trans * trans,u32 * offset,gfp_t priority)415*4882a593Smuzhiyun static struct page *iwl_pcie_rx_alloc_page(struct iwl_trans *trans,
416*4882a593Smuzhiyun u32 *offset, gfp_t priority)
417*4882a593Smuzhiyun {
418*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
419*4882a593Smuzhiyun unsigned int rbsize = iwl_trans_get_rb_size(trans_pcie->rx_buf_size);
420*4882a593Smuzhiyun unsigned int allocsize = PAGE_SIZE << trans_pcie->rx_page_order;
421*4882a593Smuzhiyun struct page *page;
422*4882a593Smuzhiyun gfp_t gfp_mask = priority;
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun if (trans_pcie->rx_page_order > 0)
425*4882a593Smuzhiyun gfp_mask |= __GFP_COMP;
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun if (trans_pcie->alloc_page) {
428*4882a593Smuzhiyun spin_lock_bh(&trans_pcie->alloc_page_lock);
429*4882a593Smuzhiyun /* recheck */
430*4882a593Smuzhiyun if (trans_pcie->alloc_page) {
431*4882a593Smuzhiyun *offset = trans_pcie->alloc_page_used;
432*4882a593Smuzhiyun page = trans_pcie->alloc_page;
433*4882a593Smuzhiyun trans_pcie->alloc_page_used += rbsize;
434*4882a593Smuzhiyun if (trans_pcie->alloc_page_used >= allocsize)
435*4882a593Smuzhiyun trans_pcie->alloc_page = NULL;
436*4882a593Smuzhiyun else
437*4882a593Smuzhiyun get_page(page);
438*4882a593Smuzhiyun spin_unlock_bh(&trans_pcie->alloc_page_lock);
439*4882a593Smuzhiyun return page;
440*4882a593Smuzhiyun }
441*4882a593Smuzhiyun spin_unlock_bh(&trans_pcie->alloc_page_lock);
442*4882a593Smuzhiyun }
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun /* Alloc a new receive buffer */
445*4882a593Smuzhiyun page = alloc_pages(gfp_mask, trans_pcie->rx_page_order);
446*4882a593Smuzhiyun if (!page) {
447*4882a593Smuzhiyun if (net_ratelimit())
448*4882a593Smuzhiyun IWL_DEBUG_INFO(trans, "alloc_pages failed, order: %d\n",
449*4882a593Smuzhiyun trans_pcie->rx_page_order);
450*4882a593Smuzhiyun /*
451*4882a593Smuzhiyun * Issue an error if we don't have enough pre-allocated
452*4882a593Smuzhiyun * buffers.
453*4882a593Smuzhiyun */
454*4882a593Smuzhiyun if (!(gfp_mask & __GFP_NOWARN) && net_ratelimit())
455*4882a593Smuzhiyun IWL_CRIT(trans,
456*4882a593Smuzhiyun "Failed to alloc_pages\n");
457*4882a593Smuzhiyun return NULL;
458*4882a593Smuzhiyun }
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun if (2 * rbsize <= allocsize) {
461*4882a593Smuzhiyun spin_lock_bh(&trans_pcie->alloc_page_lock);
462*4882a593Smuzhiyun if (!trans_pcie->alloc_page) {
463*4882a593Smuzhiyun get_page(page);
464*4882a593Smuzhiyun trans_pcie->alloc_page = page;
465*4882a593Smuzhiyun trans_pcie->alloc_page_used = rbsize;
466*4882a593Smuzhiyun }
467*4882a593Smuzhiyun spin_unlock_bh(&trans_pcie->alloc_page_lock);
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun *offset = 0;
471*4882a593Smuzhiyun return page;
472*4882a593Smuzhiyun }
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun /*
475*4882a593Smuzhiyun * iwl_pcie_rxq_alloc_rbs - allocate a page for each used RBD
476*4882a593Smuzhiyun *
477*4882a593Smuzhiyun * A used RBD is an Rx buffer that has been given to the stack. To use it again
478*4882a593Smuzhiyun * a page must be allocated and the RBD must point to the page. This function
479*4882a593Smuzhiyun * doesn't change the HW pointer but handles the list of pages that is used by
480*4882a593Smuzhiyun * iwl_pcie_rxq_restock. The latter function will update the HW to use the newly
481*4882a593Smuzhiyun * allocated buffers.
482*4882a593Smuzhiyun */
iwl_pcie_rxq_alloc_rbs(struct iwl_trans * trans,gfp_t priority,struct iwl_rxq * rxq)483*4882a593Smuzhiyun void iwl_pcie_rxq_alloc_rbs(struct iwl_trans *trans, gfp_t priority,
484*4882a593Smuzhiyun struct iwl_rxq *rxq)
485*4882a593Smuzhiyun {
486*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
487*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb;
488*4882a593Smuzhiyun struct page *page;
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun while (1) {
491*4882a593Smuzhiyun unsigned int offset;
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun spin_lock(&rxq->lock);
494*4882a593Smuzhiyun if (list_empty(&rxq->rx_used)) {
495*4882a593Smuzhiyun spin_unlock(&rxq->lock);
496*4882a593Smuzhiyun return;
497*4882a593Smuzhiyun }
498*4882a593Smuzhiyun spin_unlock(&rxq->lock);
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun page = iwl_pcie_rx_alloc_page(trans, &offset, priority);
501*4882a593Smuzhiyun if (!page)
502*4882a593Smuzhiyun return;
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun spin_lock(&rxq->lock);
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun if (list_empty(&rxq->rx_used)) {
507*4882a593Smuzhiyun spin_unlock(&rxq->lock);
508*4882a593Smuzhiyun __free_pages(page, trans_pcie->rx_page_order);
509*4882a593Smuzhiyun return;
510*4882a593Smuzhiyun }
511*4882a593Smuzhiyun rxb = list_first_entry(&rxq->rx_used, struct iwl_rx_mem_buffer,
512*4882a593Smuzhiyun list);
513*4882a593Smuzhiyun list_del(&rxb->list);
514*4882a593Smuzhiyun spin_unlock(&rxq->lock);
515*4882a593Smuzhiyun
516*4882a593Smuzhiyun BUG_ON(rxb->page);
517*4882a593Smuzhiyun rxb->page = page;
518*4882a593Smuzhiyun rxb->offset = offset;
519*4882a593Smuzhiyun /* Get physical address of the RB */
520*4882a593Smuzhiyun rxb->page_dma =
521*4882a593Smuzhiyun dma_map_page(trans->dev, page, rxb->offset,
522*4882a593Smuzhiyun trans_pcie->rx_buf_bytes,
523*4882a593Smuzhiyun DMA_FROM_DEVICE);
524*4882a593Smuzhiyun if (dma_mapping_error(trans->dev, rxb->page_dma)) {
525*4882a593Smuzhiyun rxb->page = NULL;
526*4882a593Smuzhiyun spin_lock(&rxq->lock);
527*4882a593Smuzhiyun list_add(&rxb->list, &rxq->rx_used);
528*4882a593Smuzhiyun spin_unlock(&rxq->lock);
529*4882a593Smuzhiyun __free_pages(page, trans_pcie->rx_page_order);
530*4882a593Smuzhiyun return;
531*4882a593Smuzhiyun }
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun spin_lock(&rxq->lock);
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun list_add_tail(&rxb->list, &rxq->rx_free);
536*4882a593Smuzhiyun rxq->free_count++;
537*4882a593Smuzhiyun
538*4882a593Smuzhiyun spin_unlock(&rxq->lock);
539*4882a593Smuzhiyun }
540*4882a593Smuzhiyun }
541*4882a593Smuzhiyun
iwl_pcie_free_rbs_pool(struct iwl_trans * trans)542*4882a593Smuzhiyun void iwl_pcie_free_rbs_pool(struct iwl_trans *trans)
543*4882a593Smuzhiyun {
544*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
545*4882a593Smuzhiyun int i;
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun if (!trans_pcie->rx_pool)
548*4882a593Smuzhiyun return;
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun for (i = 0; i < RX_POOL_SIZE(trans_pcie->num_rx_bufs); i++) {
551*4882a593Smuzhiyun if (!trans_pcie->rx_pool[i].page)
552*4882a593Smuzhiyun continue;
553*4882a593Smuzhiyun dma_unmap_page(trans->dev, trans_pcie->rx_pool[i].page_dma,
554*4882a593Smuzhiyun trans_pcie->rx_buf_bytes, DMA_FROM_DEVICE);
555*4882a593Smuzhiyun __free_pages(trans_pcie->rx_pool[i].page,
556*4882a593Smuzhiyun trans_pcie->rx_page_order);
557*4882a593Smuzhiyun trans_pcie->rx_pool[i].page = NULL;
558*4882a593Smuzhiyun }
559*4882a593Smuzhiyun }
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun /*
562*4882a593Smuzhiyun * iwl_pcie_rx_allocator - Allocates pages in the background for RX queues
563*4882a593Smuzhiyun *
564*4882a593Smuzhiyun * Allocates for each received request 8 pages
565*4882a593Smuzhiyun * Called as a scheduled work item.
566*4882a593Smuzhiyun */
iwl_pcie_rx_allocator(struct iwl_trans * trans)567*4882a593Smuzhiyun static void iwl_pcie_rx_allocator(struct iwl_trans *trans)
568*4882a593Smuzhiyun {
569*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
570*4882a593Smuzhiyun struct iwl_rb_allocator *rba = &trans_pcie->rba;
571*4882a593Smuzhiyun struct list_head local_empty;
572*4882a593Smuzhiyun int pending = atomic_read(&rba->req_pending);
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun IWL_DEBUG_TPT(trans, "Pending allocation requests = %d\n", pending);
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun /* If we were scheduled - there is at least one request */
577*4882a593Smuzhiyun spin_lock(&rba->lock);
578*4882a593Smuzhiyun /* swap out the rba->rbd_empty to a local list */
579*4882a593Smuzhiyun list_replace_init(&rba->rbd_empty, &local_empty);
580*4882a593Smuzhiyun spin_unlock(&rba->lock);
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun while (pending) {
583*4882a593Smuzhiyun int i;
584*4882a593Smuzhiyun LIST_HEAD(local_allocated);
585*4882a593Smuzhiyun gfp_t gfp_mask = GFP_KERNEL;
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun /* Do not post a warning if there are only a few requests */
588*4882a593Smuzhiyun if (pending < RX_PENDING_WATERMARK)
589*4882a593Smuzhiyun gfp_mask |= __GFP_NOWARN;
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun for (i = 0; i < RX_CLAIM_REQ_ALLOC;) {
592*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb;
593*4882a593Smuzhiyun struct page *page;
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun /* List should never be empty - each reused RBD is
596*4882a593Smuzhiyun * returned to the list, and initial pool covers any
597*4882a593Smuzhiyun * possible gap between the time the page is allocated
598*4882a593Smuzhiyun * to the time the RBD is added.
599*4882a593Smuzhiyun */
600*4882a593Smuzhiyun BUG_ON(list_empty(&local_empty));
601*4882a593Smuzhiyun /* Get the first rxb from the rbd list */
602*4882a593Smuzhiyun rxb = list_first_entry(&local_empty,
603*4882a593Smuzhiyun struct iwl_rx_mem_buffer, list);
604*4882a593Smuzhiyun BUG_ON(rxb->page);
605*4882a593Smuzhiyun
606*4882a593Smuzhiyun /* Alloc a new receive buffer */
607*4882a593Smuzhiyun page = iwl_pcie_rx_alloc_page(trans, &rxb->offset,
608*4882a593Smuzhiyun gfp_mask);
609*4882a593Smuzhiyun if (!page)
610*4882a593Smuzhiyun continue;
611*4882a593Smuzhiyun rxb->page = page;
612*4882a593Smuzhiyun
613*4882a593Smuzhiyun /* Get physical address of the RB */
614*4882a593Smuzhiyun rxb->page_dma = dma_map_page(trans->dev, page,
615*4882a593Smuzhiyun rxb->offset,
616*4882a593Smuzhiyun trans_pcie->rx_buf_bytes,
617*4882a593Smuzhiyun DMA_FROM_DEVICE);
618*4882a593Smuzhiyun if (dma_mapping_error(trans->dev, rxb->page_dma)) {
619*4882a593Smuzhiyun rxb->page = NULL;
620*4882a593Smuzhiyun __free_pages(page, trans_pcie->rx_page_order);
621*4882a593Smuzhiyun continue;
622*4882a593Smuzhiyun }
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun /* move the allocated entry to the out list */
625*4882a593Smuzhiyun list_move(&rxb->list, &local_allocated);
626*4882a593Smuzhiyun i++;
627*4882a593Smuzhiyun }
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun atomic_dec(&rba->req_pending);
630*4882a593Smuzhiyun pending--;
631*4882a593Smuzhiyun
632*4882a593Smuzhiyun if (!pending) {
633*4882a593Smuzhiyun pending = atomic_read(&rba->req_pending);
634*4882a593Smuzhiyun if (pending)
635*4882a593Smuzhiyun IWL_DEBUG_TPT(trans,
636*4882a593Smuzhiyun "Got more pending allocation requests = %d\n",
637*4882a593Smuzhiyun pending);
638*4882a593Smuzhiyun }
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun spin_lock(&rba->lock);
641*4882a593Smuzhiyun /* add the allocated rbds to the allocator allocated list */
642*4882a593Smuzhiyun list_splice_tail(&local_allocated, &rba->rbd_allocated);
643*4882a593Smuzhiyun /* get more empty RBDs for current pending requests */
644*4882a593Smuzhiyun list_splice_tail_init(&rba->rbd_empty, &local_empty);
645*4882a593Smuzhiyun spin_unlock(&rba->lock);
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun atomic_inc(&rba->req_ready);
648*4882a593Smuzhiyun
649*4882a593Smuzhiyun }
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun spin_lock(&rba->lock);
652*4882a593Smuzhiyun /* return unused rbds to the allocator empty list */
653*4882a593Smuzhiyun list_splice_tail(&local_empty, &rba->rbd_empty);
654*4882a593Smuzhiyun spin_unlock(&rba->lock);
655*4882a593Smuzhiyun
656*4882a593Smuzhiyun IWL_DEBUG_TPT(trans, "%s, exit.\n", __func__);
657*4882a593Smuzhiyun }
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun /*
660*4882a593Smuzhiyun * iwl_pcie_rx_allocator_get - returns the pre-allocated pages
661*4882a593Smuzhiyun .*
662*4882a593Smuzhiyun .* Called by queue when the queue posted allocation request and
663*4882a593Smuzhiyun * has freed 8 RBDs in order to restock itself.
664*4882a593Smuzhiyun * This function directly moves the allocated RBs to the queue's ownership
665*4882a593Smuzhiyun * and updates the relevant counters.
666*4882a593Smuzhiyun */
iwl_pcie_rx_allocator_get(struct iwl_trans * trans,struct iwl_rxq * rxq)667*4882a593Smuzhiyun static void iwl_pcie_rx_allocator_get(struct iwl_trans *trans,
668*4882a593Smuzhiyun struct iwl_rxq *rxq)
669*4882a593Smuzhiyun {
670*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
671*4882a593Smuzhiyun struct iwl_rb_allocator *rba = &trans_pcie->rba;
672*4882a593Smuzhiyun int i;
673*4882a593Smuzhiyun
674*4882a593Smuzhiyun lockdep_assert_held(&rxq->lock);
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun /*
677*4882a593Smuzhiyun * atomic_dec_if_positive returns req_ready - 1 for any scenario.
678*4882a593Smuzhiyun * If req_ready is 0 atomic_dec_if_positive will return -1 and this
679*4882a593Smuzhiyun * function will return early, as there are no ready requests.
680*4882a593Smuzhiyun * atomic_dec_if_positive will perofrm the *actual* decrement only if
681*4882a593Smuzhiyun * req_ready > 0, i.e. - there are ready requests and the function
682*4882a593Smuzhiyun * hands one request to the caller.
683*4882a593Smuzhiyun */
684*4882a593Smuzhiyun if (atomic_dec_if_positive(&rba->req_ready) < 0)
685*4882a593Smuzhiyun return;
686*4882a593Smuzhiyun
687*4882a593Smuzhiyun spin_lock(&rba->lock);
688*4882a593Smuzhiyun for (i = 0; i < RX_CLAIM_REQ_ALLOC; i++) {
689*4882a593Smuzhiyun /* Get next free Rx buffer, remove it from free list */
690*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb =
691*4882a593Smuzhiyun list_first_entry(&rba->rbd_allocated,
692*4882a593Smuzhiyun struct iwl_rx_mem_buffer, list);
693*4882a593Smuzhiyun
694*4882a593Smuzhiyun list_move(&rxb->list, &rxq->rx_free);
695*4882a593Smuzhiyun }
696*4882a593Smuzhiyun spin_unlock(&rba->lock);
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun rxq->used_count -= RX_CLAIM_REQ_ALLOC;
699*4882a593Smuzhiyun rxq->free_count += RX_CLAIM_REQ_ALLOC;
700*4882a593Smuzhiyun }
701*4882a593Smuzhiyun
iwl_pcie_rx_allocator_work(struct work_struct * data)702*4882a593Smuzhiyun void iwl_pcie_rx_allocator_work(struct work_struct *data)
703*4882a593Smuzhiyun {
704*4882a593Smuzhiyun struct iwl_rb_allocator *rba_p =
705*4882a593Smuzhiyun container_of(data, struct iwl_rb_allocator, rx_alloc);
706*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie =
707*4882a593Smuzhiyun container_of(rba_p, struct iwl_trans_pcie, rba);
708*4882a593Smuzhiyun
709*4882a593Smuzhiyun iwl_pcie_rx_allocator(trans_pcie->trans);
710*4882a593Smuzhiyun }
711*4882a593Smuzhiyun
iwl_pcie_free_bd_size(struct iwl_trans * trans,bool use_rx_td)712*4882a593Smuzhiyun static int iwl_pcie_free_bd_size(struct iwl_trans *trans, bool use_rx_td)
713*4882a593Smuzhiyun {
714*4882a593Smuzhiyun struct iwl_rx_transfer_desc *rx_td;
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun if (use_rx_td)
717*4882a593Smuzhiyun return sizeof(*rx_td);
718*4882a593Smuzhiyun else
719*4882a593Smuzhiyun return trans->trans_cfg->mq_rx_supported ? sizeof(__le64) :
720*4882a593Smuzhiyun sizeof(__le32);
721*4882a593Smuzhiyun }
722*4882a593Smuzhiyun
iwl_pcie_free_rxq_dma(struct iwl_trans * trans,struct iwl_rxq * rxq)723*4882a593Smuzhiyun static void iwl_pcie_free_rxq_dma(struct iwl_trans *trans,
724*4882a593Smuzhiyun struct iwl_rxq *rxq)
725*4882a593Smuzhiyun {
726*4882a593Smuzhiyun struct device *dev = trans->dev;
727*4882a593Smuzhiyun bool use_rx_td = (trans->trans_cfg->device_family >=
728*4882a593Smuzhiyun IWL_DEVICE_FAMILY_AX210);
729*4882a593Smuzhiyun int free_size = iwl_pcie_free_bd_size(trans, use_rx_td);
730*4882a593Smuzhiyun
731*4882a593Smuzhiyun if (rxq->bd)
732*4882a593Smuzhiyun dma_free_coherent(trans->dev,
733*4882a593Smuzhiyun free_size * rxq->queue_size,
734*4882a593Smuzhiyun rxq->bd, rxq->bd_dma);
735*4882a593Smuzhiyun rxq->bd_dma = 0;
736*4882a593Smuzhiyun rxq->bd = NULL;
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun rxq->rb_stts_dma = 0;
739*4882a593Smuzhiyun rxq->rb_stts = NULL;
740*4882a593Smuzhiyun
741*4882a593Smuzhiyun if (rxq->used_bd)
742*4882a593Smuzhiyun dma_free_coherent(trans->dev,
743*4882a593Smuzhiyun (use_rx_td ? sizeof(*rxq->cd) :
744*4882a593Smuzhiyun sizeof(__le32)) * rxq->queue_size,
745*4882a593Smuzhiyun rxq->used_bd, rxq->used_bd_dma);
746*4882a593Smuzhiyun rxq->used_bd_dma = 0;
747*4882a593Smuzhiyun rxq->used_bd = NULL;
748*4882a593Smuzhiyun
749*4882a593Smuzhiyun if (trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210)
750*4882a593Smuzhiyun return;
751*4882a593Smuzhiyun
752*4882a593Smuzhiyun if (rxq->tr_tail)
753*4882a593Smuzhiyun dma_free_coherent(dev, sizeof(__le16),
754*4882a593Smuzhiyun rxq->tr_tail, rxq->tr_tail_dma);
755*4882a593Smuzhiyun rxq->tr_tail_dma = 0;
756*4882a593Smuzhiyun rxq->tr_tail = NULL;
757*4882a593Smuzhiyun
758*4882a593Smuzhiyun if (rxq->cr_tail)
759*4882a593Smuzhiyun dma_free_coherent(dev, sizeof(__le16),
760*4882a593Smuzhiyun rxq->cr_tail, rxq->cr_tail_dma);
761*4882a593Smuzhiyun rxq->cr_tail_dma = 0;
762*4882a593Smuzhiyun rxq->cr_tail = NULL;
763*4882a593Smuzhiyun }
764*4882a593Smuzhiyun
iwl_pcie_alloc_rxq_dma(struct iwl_trans * trans,struct iwl_rxq * rxq)765*4882a593Smuzhiyun static int iwl_pcie_alloc_rxq_dma(struct iwl_trans *trans,
766*4882a593Smuzhiyun struct iwl_rxq *rxq)
767*4882a593Smuzhiyun {
768*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
769*4882a593Smuzhiyun struct device *dev = trans->dev;
770*4882a593Smuzhiyun int i;
771*4882a593Smuzhiyun int free_size;
772*4882a593Smuzhiyun bool use_rx_td = (trans->trans_cfg->device_family >=
773*4882a593Smuzhiyun IWL_DEVICE_FAMILY_AX210);
774*4882a593Smuzhiyun size_t rb_stts_size = use_rx_td ? sizeof(__le16) :
775*4882a593Smuzhiyun sizeof(struct iwl_rb_status);
776*4882a593Smuzhiyun
777*4882a593Smuzhiyun spin_lock_init(&rxq->lock);
778*4882a593Smuzhiyun if (trans->trans_cfg->mq_rx_supported)
779*4882a593Smuzhiyun rxq->queue_size = trans->cfg->num_rbds;
780*4882a593Smuzhiyun else
781*4882a593Smuzhiyun rxq->queue_size = RX_QUEUE_SIZE;
782*4882a593Smuzhiyun
783*4882a593Smuzhiyun free_size = iwl_pcie_free_bd_size(trans, use_rx_td);
784*4882a593Smuzhiyun
785*4882a593Smuzhiyun /*
786*4882a593Smuzhiyun * Allocate the circular buffer of Read Buffer Descriptors
787*4882a593Smuzhiyun * (RBDs)
788*4882a593Smuzhiyun */
789*4882a593Smuzhiyun rxq->bd = dma_alloc_coherent(dev, free_size * rxq->queue_size,
790*4882a593Smuzhiyun &rxq->bd_dma, GFP_KERNEL);
791*4882a593Smuzhiyun if (!rxq->bd)
792*4882a593Smuzhiyun goto err;
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun if (trans->trans_cfg->mq_rx_supported) {
795*4882a593Smuzhiyun rxq->used_bd = dma_alloc_coherent(dev,
796*4882a593Smuzhiyun (use_rx_td ? sizeof(*rxq->cd) : sizeof(__le32)) * rxq->queue_size,
797*4882a593Smuzhiyun &rxq->used_bd_dma,
798*4882a593Smuzhiyun GFP_KERNEL);
799*4882a593Smuzhiyun if (!rxq->used_bd)
800*4882a593Smuzhiyun goto err;
801*4882a593Smuzhiyun }
802*4882a593Smuzhiyun
803*4882a593Smuzhiyun rxq->rb_stts = trans_pcie->base_rb_stts + rxq->id * rb_stts_size;
804*4882a593Smuzhiyun rxq->rb_stts_dma =
805*4882a593Smuzhiyun trans_pcie->base_rb_stts_dma + rxq->id * rb_stts_size;
806*4882a593Smuzhiyun
807*4882a593Smuzhiyun if (!use_rx_td)
808*4882a593Smuzhiyun return 0;
809*4882a593Smuzhiyun
810*4882a593Smuzhiyun /* Allocate the driver's pointer to TR tail */
811*4882a593Smuzhiyun rxq->tr_tail = dma_alloc_coherent(dev, sizeof(__le16),
812*4882a593Smuzhiyun &rxq->tr_tail_dma, GFP_KERNEL);
813*4882a593Smuzhiyun if (!rxq->tr_tail)
814*4882a593Smuzhiyun goto err;
815*4882a593Smuzhiyun
816*4882a593Smuzhiyun /* Allocate the driver's pointer to CR tail */
817*4882a593Smuzhiyun rxq->cr_tail = dma_alloc_coherent(dev, sizeof(__le16),
818*4882a593Smuzhiyun &rxq->cr_tail_dma, GFP_KERNEL);
819*4882a593Smuzhiyun if (!rxq->cr_tail)
820*4882a593Smuzhiyun goto err;
821*4882a593Smuzhiyun
822*4882a593Smuzhiyun return 0;
823*4882a593Smuzhiyun
824*4882a593Smuzhiyun err:
825*4882a593Smuzhiyun for (i = 0; i < trans->num_rx_queues; i++) {
826*4882a593Smuzhiyun struct iwl_rxq *rxq = &trans_pcie->rxq[i];
827*4882a593Smuzhiyun
828*4882a593Smuzhiyun iwl_pcie_free_rxq_dma(trans, rxq);
829*4882a593Smuzhiyun }
830*4882a593Smuzhiyun
831*4882a593Smuzhiyun return -ENOMEM;
832*4882a593Smuzhiyun }
833*4882a593Smuzhiyun
iwl_pcie_rx_alloc(struct iwl_trans * trans)834*4882a593Smuzhiyun static int iwl_pcie_rx_alloc(struct iwl_trans *trans)
835*4882a593Smuzhiyun {
836*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
837*4882a593Smuzhiyun struct iwl_rb_allocator *rba = &trans_pcie->rba;
838*4882a593Smuzhiyun int i, ret;
839*4882a593Smuzhiyun size_t rb_stts_size = trans->trans_cfg->device_family >=
840*4882a593Smuzhiyun IWL_DEVICE_FAMILY_AX210 ?
841*4882a593Smuzhiyun sizeof(__le16) : sizeof(struct iwl_rb_status);
842*4882a593Smuzhiyun
843*4882a593Smuzhiyun if (WARN_ON(trans_pcie->rxq))
844*4882a593Smuzhiyun return -EINVAL;
845*4882a593Smuzhiyun
846*4882a593Smuzhiyun trans_pcie->rxq = kcalloc(trans->num_rx_queues, sizeof(struct iwl_rxq),
847*4882a593Smuzhiyun GFP_KERNEL);
848*4882a593Smuzhiyun trans_pcie->rx_pool = kcalloc(RX_POOL_SIZE(trans_pcie->num_rx_bufs),
849*4882a593Smuzhiyun sizeof(trans_pcie->rx_pool[0]),
850*4882a593Smuzhiyun GFP_KERNEL);
851*4882a593Smuzhiyun trans_pcie->global_table =
852*4882a593Smuzhiyun kcalloc(RX_POOL_SIZE(trans_pcie->num_rx_bufs),
853*4882a593Smuzhiyun sizeof(trans_pcie->global_table[0]),
854*4882a593Smuzhiyun GFP_KERNEL);
855*4882a593Smuzhiyun if (!trans_pcie->rxq || !trans_pcie->rx_pool ||
856*4882a593Smuzhiyun !trans_pcie->global_table) {
857*4882a593Smuzhiyun ret = -ENOMEM;
858*4882a593Smuzhiyun goto err;
859*4882a593Smuzhiyun }
860*4882a593Smuzhiyun
861*4882a593Smuzhiyun spin_lock_init(&rba->lock);
862*4882a593Smuzhiyun
863*4882a593Smuzhiyun /*
864*4882a593Smuzhiyun * Allocate the driver's pointer to receive buffer status.
865*4882a593Smuzhiyun * Allocate for all queues continuously (HW requirement).
866*4882a593Smuzhiyun */
867*4882a593Smuzhiyun trans_pcie->base_rb_stts =
868*4882a593Smuzhiyun dma_alloc_coherent(trans->dev,
869*4882a593Smuzhiyun rb_stts_size * trans->num_rx_queues,
870*4882a593Smuzhiyun &trans_pcie->base_rb_stts_dma,
871*4882a593Smuzhiyun GFP_KERNEL);
872*4882a593Smuzhiyun if (!trans_pcie->base_rb_stts) {
873*4882a593Smuzhiyun ret = -ENOMEM;
874*4882a593Smuzhiyun goto err;
875*4882a593Smuzhiyun }
876*4882a593Smuzhiyun
877*4882a593Smuzhiyun for (i = 0; i < trans->num_rx_queues; i++) {
878*4882a593Smuzhiyun struct iwl_rxq *rxq = &trans_pcie->rxq[i];
879*4882a593Smuzhiyun
880*4882a593Smuzhiyun rxq->id = i;
881*4882a593Smuzhiyun ret = iwl_pcie_alloc_rxq_dma(trans, rxq);
882*4882a593Smuzhiyun if (ret)
883*4882a593Smuzhiyun goto err;
884*4882a593Smuzhiyun }
885*4882a593Smuzhiyun return 0;
886*4882a593Smuzhiyun
887*4882a593Smuzhiyun err:
888*4882a593Smuzhiyun if (trans_pcie->base_rb_stts) {
889*4882a593Smuzhiyun dma_free_coherent(trans->dev,
890*4882a593Smuzhiyun rb_stts_size * trans->num_rx_queues,
891*4882a593Smuzhiyun trans_pcie->base_rb_stts,
892*4882a593Smuzhiyun trans_pcie->base_rb_stts_dma);
893*4882a593Smuzhiyun trans_pcie->base_rb_stts = NULL;
894*4882a593Smuzhiyun trans_pcie->base_rb_stts_dma = 0;
895*4882a593Smuzhiyun }
896*4882a593Smuzhiyun kfree(trans_pcie->rx_pool);
897*4882a593Smuzhiyun kfree(trans_pcie->global_table);
898*4882a593Smuzhiyun kfree(trans_pcie->rxq);
899*4882a593Smuzhiyun
900*4882a593Smuzhiyun return ret;
901*4882a593Smuzhiyun }
902*4882a593Smuzhiyun
iwl_pcie_rx_hw_init(struct iwl_trans * trans,struct iwl_rxq * rxq)903*4882a593Smuzhiyun static void iwl_pcie_rx_hw_init(struct iwl_trans *trans, struct iwl_rxq *rxq)
904*4882a593Smuzhiyun {
905*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
906*4882a593Smuzhiyun u32 rb_size;
907*4882a593Smuzhiyun unsigned long flags;
908*4882a593Smuzhiyun const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
909*4882a593Smuzhiyun
910*4882a593Smuzhiyun switch (trans_pcie->rx_buf_size) {
911*4882a593Smuzhiyun case IWL_AMSDU_4K:
912*4882a593Smuzhiyun rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
913*4882a593Smuzhiyun break;
914*4882a593Smuzhiyun case IWL_AMSDU_8K:
915*4882a593Smuzhiyun rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
916*4882a593Smuzhiyun break;
917*4882a593Smuzhiyun case IWL_AMSDU_12K:
918*4882a593Smuzhiyun rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K;
919*4882a593Smuzhiyun break;
920*4882a593Smuzhiyun default:
921*4882a593Smuzhiyun WARN_ON(1);
922*4882a593Smuzhiyun rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
923*4882a593Smuzhiyun }
924*4882a593Smuzhiyun
925*4882a593Smuzhiyun if (!iwl_trans_grab_nic_access(trans, &flags))
926*4882a593Smuzhiyun return;
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun /* Stop Rx DMA */
929*4882a593Smuzhiyun iwl_write32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
930*4882a593Smuzhiyun /* reset and flush pointers */
931*4882a593Smuzhiyun iwl_write32(trans, FH_MEM_RCSR_CHNL0_RBDCB_WPTR, 0);
932*4882a593Smuzhiyun iwl_write32(trans, FH_MEM_RCSR_CHNL0_FLUSH_RB_REQ, 0);
933*4882a593Smuzhiyun iwl_write32(trans, FH_RSCSR_CHNL0_RDPTR, 0);
934*4882a593Smuzhiyun
935*4882a593Smuzhiyun /* Reset driver's Rx queue write index */
936*4882a593Smuzhiyun iwl_write32(trans, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
937*4882a593Smuzhiyun
938*4882a593Smuzhiyun /* Tell device where to find RBD circular buffer in DRAM */
939*4882a593Smuzhiyun iwl_write32(trans, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
940*4882a593Smuzhiyun (u32)(rxq->bd_dma >> 8));
941*4882a593Smuzhiyun
942*4882a593Smuzhiyun /* Tell device where in DRAM to update its Rx status */
943*4882a593Smuzhiyun iwl_write32(trans, FH_RSCSR_CHNL0_STTS_WPTR_REG,
944*4882a593Smuzhiyun rxq->rb_stts_dma >> 4);
945*4882a593Smuzhiyun
946*4882a593Smuzhiyun /* Enable Rx DMA
947*4882a593Smuzhiyun * FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY is set because of HW bug in
948*4882a593Smuzhiyun * the credit mechanism in 5000 HW RX FIFO
949*4882a593Smuzhiyun * Direct rx interrupts to hosts
950*4882a593Smuzhiyun * Rx buffer size 4 or 8k or 12k
951*4882a593Smuzhiyun * RB timeout 0x10
952*4882a593Smuzhiyun * 256 RBDs
953*4882a593Smuzhiyun */
954*4882a593Smuzhiyun iwl_write32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG,
955*4882a593Smuzhiyun FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
956*4882a593Smuzhiyun FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY |
957*4882a593Smuzhiyun FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
958*4882a593Smuzhiyun rb_size |
959*4882a593Smuzhiyun (RX_RB_TIMEOUT << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS) |
960*4882a593Smuzhiyun (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun iwl_trans_release_nic_access(trans, &flags);
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun /* Set interrupt coalescing timer to default (2048 usecs) */
965*4882a593Smuzhiyun iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF);
966*4882a593Smuzhiyun
967*4882a593Smuzhiyun /* W/A for interrupt coalescing bug in 7260 and 3160 */
968*4882a593Smuzhiyun if (trans->cfg->host_interrupt_operation_mode)
969*4882a593Smuzhiyun iwl_set_bit(trans, CSR_INT_COALESCING, IWL_HOST_INT_OPER_MODE);
970*4882a593Smuzhiyun }
971*4882a593Smuzhiyun
iwl_pcie_rx_mq_hw_init(struct iwl_trans * trans)972*4882a593Smuzhiyun static void iwl_pcie_rx_mq_hw_init(struct iwl_trans *trans)
973*4882a593Smuzhiyun {
974*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
975*4882a593Smuzhiyun u32 rb_size, enabled = 0;
976*4882a593Smuzhiyun unsigned long flags;
977*4882a593Smuzhiyun int i;
978*4882a593Smuzhiyun
979*4882a593Smuzhiyun switch (trans_pcie->rx_buf_size) {
980*4882a593Smuzhiyun case IWL_AMSDU_2K:
981*4882a593Smuzhiyun rb_size = RFH_RXF_DMA_RB_SIZE_2K;
982*4882a593Smuzhiyun break;
983*4882a593Smuzhiyun case IWL_AMSDU_4K:
984*4882a593Smuzhiyun rb_size = RFH_RXF_DMA_RB_SIZE_4K;
985*4882a593Smuzhiyun break;
986*4882a593Smuzhiyun case IWL_AMSDU_8K:
987*4882a593Smuzhiyun rb_size = RFH_RXF_DMA_RB_SIZE_8K;
988*4882a593Smuzhiyun break;
989*4882a593Smuzhiyun case IWL_AMSDU_12K:
990*4882a593Smuzhiyun rb_size = RFH_RXF_DMA_RB_SIZE_12K;
991*4882a593Smuzhiyun break;
992*4882a593Smuzhiyun default:
993*4882a593Smuzhiyun WARN_ON(1);
994*4882a593Smuzhiyun rb_size = RFH_RXF_DMA_RB_SIZE_4K;
995*4882a593Smuzhiyun }
996*4882a593Smuzhiyun
997*4882a593Smuzhiyun if (!iwl_trans_grab_nic_access(trans, &flags))
998*4882a593Smuzhiyun return;
999*4882a593Smuzhiyun
1000*4882a593Smuzhiyun /* Stop Rx DMA */
1001*4882a593Smuzhiyun iwl_write_prph_no_grab(trans, RFH_RXF_DMA_CFG, 0);
1002*4882a593Smuzhiyun /* disable free amd used rx queue operation */
1003*4882a593Smuzhiyun iwl_write_prph_no_grab(trans, RFH_RXF_RXQ_ACTIVE, 0);
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun for (i = 0; i < trans->num_rx_queues; i++) {
1006*4882a593Smuzhiyun /* Tell device where to find RBD free table in DRAM */
1007*4882a593Smuzhiyun iwl_write_prph64_no_grab(trans,
1008*4882a593Smuzhiyun RFH_Q_FRBDCB_BA_LSB(i),
1009*4882a593Smuzhiyun trans_pcie->rxq[i].bd_dma);
1010*4882a593Smuzhiyun /* Tell device where to find RBD used table in DRAM */
1011*4882a593Smuzhiyun iwl_write_prph64_no_grab(trans,
1012*4882a593Smuzhiyun RFH_Q_URBDCB_BA_LSB(i),
1013*4882a593Smuzhiyun trans_pcie->rxq[i].used_bd_dma);
1014*4882a593Smuzhiyun /* Tell device where in DRAM to update its Rx status */
1015*4882a593Smuzhiyun iwl_write_prph64_no_grab(trans,
1016*4882a593Smuzhiyun RFH_Q_URBD_STTS_WPTR_LSB(i),
1017*4882a593Smuzhiyun trans_pcie->rxq[i].rb_stts_dma);
1018*4882a593Smuzhiyun /* Reset device indice tables */
1019*4882a593Smuzhiyun iwl_write_prph_no_grab(trans, RFH_Q_FRBDCB_WIDX(i), 0);
1020*4882a593Smuzhiyun iwl_write_prph_no_grab(trans, RFH_Q_FRBDCB_RIDX(i), 0);
1021*4882a593Smuzhiyun iwl_write_prph_no_grab(trans, RFH_Q_URBDCB_WIDX(i), 0);
1022*4882a593Smuzhiyun
1023*4882a593Smuzhiyun enabled |= BIT(i) | BIT(i + 16);
1024*4882a593Smuzhiyun }
1025*4882a593Smuzhiyun
1026*4882a593Smuzhiyun /*
1027*4882a593Smuzhiyun * Enable Rx DMA
1028*4882a593Smuzhiyun * Rx buffer size 4 or 8k or 12k
1029*4882a593Smuzhiyun * Min RB size 4 or 8
1030*4882a593Smuzhiyun * Drop frames that exceed RB size
1031*4882a593Smuzhiyun * 512 RBDs
1032*4882a593Smuzhiyun */
1033*4882a593Smuzhiyun iwl_write_prph_no_grab(trans, RFH_RXF_DMA_CFG,
1034*4882a593Smuzhiyun RFH_DMA_EN_ENABLE_VAL | rb_size |
1035*4882a593Smuzhiyun RFH_RXF_DMA_MIN_RB_4_8 |
1036*4882a593Smuzhiyun RFH_RXF_DMA_DROP_TOO_LARGE_MASK |
1037*4882a593Smuzhiyun RFH_RXF_DMA_RBDCB_SIZE_512);
1038*4882a593Smuzhiyun
1039*4882a593Smuzhiyun /*
1040*4882a593Smuzhiyun * Activate DMA snooping.
1041*4882a593Smuzhiyun * Set RX DMA chunk size to 64B for IOSF and 128B for PCIe
1042*4882a593Smuzhiyun * Default queue is 0
1043*4882a593Smuzhiyun */
1044*4882a593Smuzhiyun iwl_write_prph_no_grab(trans, RFH_GEN_CFG,
1045*4882a593Smuzhiyun RFH_GEN_CFG_RFH_DMA_SNOOP |
1046*4882a593Smuzhiyun RFH_GEN_CFG_VAL(DEFAULT_RXQ_NUM, 0) |
1047*4882a593Smuzhiyun RFH_GEN_CFG_SERVICE_DMA_SNOOP |
1048*4882a593Smuzhiyun RFH_GEN_CFG_VAL(RB_CHUNK_SIZE,
1049*4882a593Smuzhiyun trans->trans_cfg->integrated ?
1050*4882a593Smuzhiyun RFH_GEN_CFG_RB_CHUNK_SIZE_64 :
1051*4882a593Smuzhiyun RFH_GEN_CFG_RB_CHUNK_SIZE_128));
1052*4882a593Smuzhiyun /* Enable the relevant rx queues */
1053*4882a593Smuzhiyun iwl_write_prph_no_grab(trans, RFH_RXF_RXQ_ACTIVE, enabled);
1054*4882a593Smuzhiyun
1055*4882a593Smuzhiyun iwl_trans_release_nic_access(trans, &flags);
1056*4882a593Smuzhiyun
1057*4882a593Smuzhiyun /* Set interrupt coalescing timer to default (2048 usecs) */
1058*4882a593Smuzhiyun iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF);
1059*4882a593Smuzhiyun }
1060*4882a593Smuzhiyun
iwl_pcie_rx_init_rxb_lists(struct iwl_rxq * rxq)1061*4882a593Smuzhiyun void iwl_pcie_rx_init_rxb_lists(struct iwl_rxq *rxq)
1062*4882a593Smuzhiyun {
1063*4882a593Smuzhiyun lockdep_assert_held(&rxq->lock);
1064*4882a593Smuzhiyun
1065*4882a593Smuzhiyun INIT_LIST_HEAD(&rxq->rx_free);
1066*4882a593Smuzhiyun INIT_LIST_HEAD(&rxq->rx_used);
1067*4882a593Smuzhiyun rxq->free_count = 0;
1068*4882a593Smuzhiyun rxq->used_count = 0;
1069*4882a593Smuzhiyun }
1070*4882a593Smuzhiyun
iwl_pcie_dummy_napi_poll(struct napi_struct * napi,int budget)1071*4882a593Smuzhiyun int iwl_pcie_dummy_napi_poll(struct napi_struct *napi, int budget)
1072*4882a593Smuzhiyun {
1073*4882a593Smuzhiyun WARN_ON(1);
1074*4882a593Smuzhiyun return 0;
1075*4882a593Smuzhiyun }
1076*4882a593Smuzhiyun
_iwl_pcie_rx_init(struct iwl_trans * trans)1077*4882a593Smuzhiyun static int _iwl_pcie_rx_init(struct iwl_trans *trans)
1078*4882a593Smuzhiyun {
1079*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1080*4882a593Smuzhiyun struct iwl_rxq *def_rxq;
1081*4882a593Smuzhiyun struct iwl_rb_allocator *rba = &trans_pcie->rba;
1082*4882a593Smuzhiyun int i, err, queue_size, allocator_pool_size, num_alloc;
1083*4882a593Smuzhiyun
1084*4882a593Smuzhiyun if (!trans_pcie->rxq) {
1085*4882a593Smuzhiyun err = iwl_pcie_rx_alloc(trans);
1086*4882a593Smuzhiyun if (err)
1087*4882a593Smuzhiyun return err;
1088*4882a593Smuzhiyun }
1089*4882a593Smuzhiyun def_rxq = trans_pcie->rxq;
1090*4882a593Smuzhiyun
1091*4882a593Smuzhiyun cancel_work_sync(&rba->rx_alloc);
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun spin_lock(&rba->lock);
1094*4882a593Smuzhiyun atomic_set(&rba->req_pending, 0);
1095*4882a593Smuzhiyun atomic_set(&rba->req_ready, 0);
1096*4882a593Smuzhiyun INIT_LIST_HEAD(&rba->rbd_allocated);
1097*4882a593Smuzhiyun INIT_LIST_HEAD(&rba->rbd_empty);
1098*4882a593Smuzhiyun spin_unlock(&rba->lock);
1099*4882a593Smuzhiyun
1100*4882a593Smuzhiyun /* free all first - we overwrite everything here */
1101*4882a593Smuzhiyun iwl_pcie_free_rbs_pool(trans);
1102*4882a593Smuzhiyun
1103*4882a593Smuzhiyun for (i = 0; i < RX_QUEUE_SIZE; i++)
1104*4882a593Smuzhiyun def_rxq->queue[i] = NULL;
1105*4882a593Smuzhiyun
1106*4882a593Smuzhiyun for (i = 0; i < trans->num_rx_queues; i++) {
1107*4882a593Smuzhiyun struct iwl_rxq *rxq = &trans_pcie->rxq[i];
1108*4882a593Smuzhiyun
1109*4882a593Smuzhiyun spin_lock(&rxq->lock);
1110*4882a593Smuzhiyun /*
1111*4882a593Smuzhiyun * Set read write pointer to reflect that we have processed
1112*4882a593Smuzhiyun * and used all buffers, but have not restocked the Rx queue
1113*4882a593Smuzhiyun * with fresh buffers
1114*4882a593Smuzhiyun */
1115*4882a593Smuzhiyun rxq->read = 0;
1116*4882a593Smuzhiyun rxq->write = 0;
1117*4882a593Smuzhiyun rxq->write_actual = 0;
1118*4882a593Smuzhiyun memset(rxq->rb_stts, 0,
1119*4882a593Smuzhiyun (trans->trans_cfg->device_family >=
1120*4882a593Smuzhiyun IWL_DEVICE_FAMILY_AX210) ?
1121*4882a593Smuzhiyun sizeof(__le16) : sizeof(struct iwl_rb_status));
1122*4882a593Smuzhiyun
1123*4882a593Smuzhiyun iwl_pcie_rx_init_rxb_lists(rxq);
1124*4882a593Smuzhiyun
1125*4882a593Smuzhiyun if (!rxq->napi.poll)
1126*4882a593Smuzhiyun netif_napi_add(&trans_pcie->napi_dev, &rxq->napi,
1127*4882a593Smuzhiyun iwl_pcie_dummy_napi_poll, 64);
1128*4882a593Smuzhiyun
1129*4882a593Smuzhiyun spin_unlock(&rxq->lock);
1130*4882a593Smuzhiyun }
1131*4882a593Smuzhiyun
1132*4882a593Smuzhiyun /* move the pool to the default queue and allocator ownerships */
1133*4882a593Smuzhiyun queue_size = trans->trans_cfg->mq_rx_supported ?
1134*4882a593Smuzhiyun trans_pcie->num_rx_bufs - 1 : RX_QUEUE_SIZE;
1135*4882a593Smuzhiyun allocator_pool_size = trans->num_rx_queues *
1136*4882a593Smuzhiyun (RX_CLAIM_REQ_ALLOC - RX_POST_REQ_ALLOC);
1137*4882a593Smuzhiyun num_alloc = queue_size + allocator_pool_size;
1138*4882a593Smuzhiyun
1139*4882a593Smuzhiyun for (i = 0; i < num_alloc; i++) {
1140*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb = &trans_pcie->rx_pool[i];
1141*4882a593Smuzhiyun
1142*4882a593Smuzhiyun if (i < allocator_pool_size)
1143*4882a593Smuzhiyun list_add(&rxb->list, &rba->rbd_empty);
1144*4882a593Smuzhiyun else
1145*4882a593Smuzhiyun list_add(&rxb->list, &def_rxq->rx_used);
1146*4882a593Smuzhiyun trans_pcie->global_table[i] = rxb;
1147*4882a593Smuzhiyun rxb->vid = (u16)(i + 1);
1148*4882a593Smuzhiyun rxb->invalid = true;
1149*4882a593Smuzhiyun }
1150*4882a593Smuzhiyun
1151*4882a593Smuzhiyun iwl_pcie_rxq_alloc_rbs(trans, GFP_KERNEL, def_rxq);
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun return 0;
1154*4882a593Smuzhiyun }
1155*4882a593Smuzhiyun
iwl_pcie_rx_init(struct iwl_trans * trans)1156*4882a593Smuzhiyun int iwl_pcie_rx_init(struct iwl_trans *trans)
1157*4882a593Smuzhiyun {
1158*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1159*4882a593Smuzhiyun int ret = _iwl_pcie_rx_init(trans);
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun if (ret)
1162*4882a593Smuzhiyun return ret;
1163*4882a593Smuzhiyun
1164*4882a593Smuzhiyun if (trans->trans_cfg->mq_rx_supported)
1165*4882a593Smuzhiyun iwl_pcie_rx_mq_hw_init(trans);
1166*4882a593Smuzhiyun else
1167*4882a593Smuzhiyun iwl_pcie_rx_hw_init(trans, trans_pcie->rxq);
1168*4882a593Smuzhiyun
1169*4882a593Smuzhiyun iwl_pcie_rxq_restock(trans, trans_pcie->rxq);
1170*4882a593Smuzhiyun
1171*4882a593Smuzhiyun spin_lock(&trans_pcie->rxq->lock);
1172*4882a593Smuzhiyun iwl_pcie_rxq_inc_wr_ptr(trans, trans_pcie->rxq);
1173*4882a593Smuzhiyun spin_unlock(&trans_pcie->rxq->lock);
1174*4882a593Smuzhiyun
1175*4882a593Smuzhiyun return 0;
1176*4882a593Smuzhiyun }
1177*4882a593Smuzhiyun
iwl_pcie_gen2_rx_init(struct iwl_trans * trans)1178*4882a593Smuzhiyun int iwl_pcie_gen2_rx_init(struct iwl_trans *trans)
1179*4882a593Smuzhiyun {
1180*4882a593Smuzhiyun /* Set interrupt coalescing timer to default (2048 usecs) */
1181*4882a593Smuzhiyun iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF);
1182*4882a593Smuzhiyun
1183*4882a593Smuzhiyun /*
1184*4882a593Smuzhiyun * We don't configure the RFH.
1185*4882a593Smuzhiyun * Restock will be done at alive, after firmware configured the RFH.
1186*4882a593Smuzhiyun */
1187*4882a593Smuzhiyun return _iwl_pcie_rx_init(trans);
1188*4882a593Smuzhiyun }
1189*4882a593Smuzhiyun
iwl_pcie_rx_free(struct iwl_trans * trans)1190*4882a593Smuzhiyun void iwl_pcie_rx_free(struct iwl_trans *trans)
1191*4882a593Smuzhiyun {
1192*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1193*4882a593Smuzhiyun struct iwl_rb_allocator *rba = &trans_pcie->rba;
1194*4882a593Smuzhiyun int i;
1195*4882a593Smuzhiyun size_t rb_stts_size = trans->trans_cfg->device_family >=
1196*4882a593Smuzhiyun IWL_DEVICE_FAMILY_AX210 ?
1197*4882a593Smuzhiyun sizeof(__le16) : sizeof(struct iwl_rb_status);
1198*4882a593Smuzhiyun
1199*4882a593Smuzhiyun /*
1200*4882a593Smuzhiyun * if rxq is NULL, it means that nothing has been allocated,
1201*4882a593Smuzhiyun * exit now
1202*4882a593Smuzhiyun */
1203*4882a593Smuzhiyun if (!trans_pcie->rxq) {
1204*4882a593Smuzhiyun IWL_DEBUG_INFO(trans, "Free NULL rx context\n");
1205*4882a593Smuzhiyun return;
1206*4882a593Smuzhiyun }
1207*4882a593Smuzhiyun
1208*4882a593Smuzhiyun cancel_work_sync(&rba->rx_alloc);
1209*4882a593Smuzhiyun
1210*4882a593Smuzhiyun iwl_pcie_free_rbs_pool(trans);
1211*4882a593Smuzhiyun
1212*4882a593Smuzhiyun if (trans_pcie->base_rb_stts) {
1213*4882a593Smuzhiyun dma_free_coherent(trans->dev,
1214*4882a593Smuzhiyun rb_stts_size * trans->num_rx_queues,
1215*4882a593Smuzhiyun trans_pcie->base_rb_stts,
1216*4882a593Smuzhiyun trans_pcie->base_rb_stts_dma);
1217*4882a593Smuzhiyun trans_pcie->base_rb_stts = NULL;
1218*4882a593Smuzhiyun trans_pcie->base_rb_stts_dma = 0;
1219*4882a593Smuzhiyun }
1220*4882a593Smuzhiyun
1221*4882a593Smuzhiyun for (i = 0; i < trans->num_rx_queues; i++) {
1222*4882a593Smuzhiyun struct iwl_rxq *rxq = &trans_pcie->rxq[i];
1223*4882a593Smuzhiyun
1224*4882a593Smuzhiyun iwl_pcie_free_rxq_dma(trans, rxq);
1225*4882a593Smuzhiyun
1226*4882a593Smuzhiyun if (rxq->napi.poll)
1227*4882a593Smuzhiyun netif_napi_del(&rxq->napi);
1228*4882a593Smuzhiyun }
1229*4882a593Smuzhiyun kfree(trans_pcie->rx_pool);
1230*4882a593Smuzhiyun kfree(trans_pcie->global_table);
1231*4882a593Smuzhiyun kfree(trans_pcie->rxq);
1232*4882a593Smuzhiyun
1233*4882a593Smuzhiyun if (trans_pcie->alloc_page)
1234*4882a593Smuzhiyun __free_pages(trans_pcie->alloc_page, trans_pcie->rx_page_order);
1235*4882a593Smuzhiyun }
1236*4882a593Smuzhiyun
iwl_pcie_rx_move_to_allocator(struct iwl_rxq * rxq,struct iwl_rb_allocator * rba)1237*4882a593Smuzhiyun static void iwl_pcie_rx_move_to_allocator(struct iwl_rxq *rxq,
1238*4882a593Smuzhiyun struct iwl_rb_allocator *rba)
1239*4882a593Smuzhiyun {
1240*4882a593Smuzhiyun spin_lock(&rba->lock);
1241*4882a593Smuzhiyun list_splice_tail_init(&rxq->rx_used, &rba->rbd_empty);
1242*4882a593Smuzhiyun spin_unlock(&rba->lock);
1243*4882a593Smuzhiyun }
1244*4882a593Smuzhiyun
1245*4882a593Smuzhiyun /*
1246*4882a593Smuzhiyun * iwl_pcie_rx_reuse_rbd - Recycle used RBDs
1247*4882a593Smuzhiyun *
1248*4882a593Smuzhiyun * Called when a RBD can be reused. The RBD is transferred to the allocator.
1249*4882a593Smuzhiyun * When there are 2 empty RBDs - a request for allocation is posted
1250*4882a593Smuzhiyun */
iwl_pcie_rx_reuse_rbd(struct iwl_trans * trans,struct iwl_rx_mem_buffer * rxb,struct iwl_rxq * rxq,bool emergency)1251*4882a593Smuzhiyun static void iwl_pcie_rx_reuse_rbd(struct iwl_trans *trans,
1252*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb,
1253*4882a593Smuzhiyun struct iwl_rxq *rxq, bool emergency)
1254*4882a593Smuzhiyun {
1255*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1256*4882a593Smuzhiyun struct iwl_rb_allocator *rba = &trans_pcie->rba;
1257*4882a593Smuzhiyun
1258*4882a593Smuzhiyun /* Move the RBD to the used list, will be moved to allocator in batches
1259*4882a593Smuzhiyun * before claiming or posting a request*/
1260*4882a593Smuzhiyun list_add_tail(&rxb->list, &rxq->rx_used);
1261*4882a593Smuzhiyun
1262*4882a593Smuzhiyun if (unlikely(emergency))
1263*4882a593Smuzhiyun return;
1264*4882a593Smuzhiyun
1265*4882a593Smuzhiyun /* Count the allocator owned RBDs */
1266*4882a593Smuzhiyun rxq->used_count++;
1267*4882a593Smuzhiyun
1268*4882a593Smuzhiyun /* If we have RX_POST_REQ_ALLOC new released rx buffers -
1269*4882a593Smuzhiyun * issue a request for allocator. Modulo RX_CLAIM_REQ_ALLOC is
1270*4882a593Smuzhiyun * used for the case we failed to claim RX_CLAIM_REQ_ALLOC,
1271*4882a593Smuzhiyun * after but we still need to post another request.
1272*4882a593Smuzhiyun */
1273*4882a593Smuzhiyun if ((rxq->used_count % RX_CLAIM_REQ_ALLOC) == RX_POST_REQ_ALLOC) {
1274*4882a593Smuzhiyun /* Move the 2 RBDs to the allocator ownership.
1275*4882a593Smuzhiyun Allocator has another 6 from pool for the request completion*/
1276*4882a593Smuzhiyun iwl_pcie_rx_move_to_allocator(rxq, rba);
1277*4882a593Smuzhiyun
1278*4882a593Smuzhiyun atomic_inc(&rba->req_pending);
1279*4882a593Smuzhiyun queue_work(rba->alloc_wq, &rba->rx_alloc);
1280*4882a593Smuzhiyun }
1281*4882a593Smuzhiyun }
1282*4882a593Smuzhiyun
iwl_pcie_rx_handle_rb(struct iwl_trans * trans,struct iwl_rxq * rxq,struct iwl_rx_mem_buffer * rxb,bool emergency,int i)1283*4882a593Smuzhiyun static void iwl_pcie_rx_handle_rb(struct iwl_trans *trans,
1284*4882a593Smuzhiyun struct iwl_rxq *rxq,
1285*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb,
1286*4882a593Smuzhiyun bool emergency,
1287*4882a593Smuzhiyun int i)
1288*4882a593Smuzhiyun {
1289*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1290*4882a593Smuzhiyun struct iwl_txq *txq = trans->txqs.txq[trans->txqs.cmd.q_id];
1291*4882a593Smuzhiyun bool page_stolen = false;
1292*4882a593Smuzhiyun int max_len = trans_pcie->rx_buf_bytes;
1293*4882a593Smuzhiyun u32 offset = 0;
1294*4882a593Smuzhiyun
1295*4882a593Smuzhiyun if (WARN_ON(!rxb))
1296*4882a593Smuzhiyun return;
1297*4882a593Smuzhiyun
1298*4882a593Smuzhiyun dma_unmap_page(trans->dev, rxb->page_dma, max_len, DMA_FROM_DEVICE);
1299*4882a593Smuzhiyun
1300*4882a593Smuzhiyun while (offset + sizeof(u32) + sizeof(struct iwl_cmd_header) < max_len) {
1301*4882a593Smuzhiyun struct iwl_rx_packet *pkt;
1302*4882a593Smuzhiyun u16 sequence;
1303*4882a593Smuzhiyun bool reclaim;
1304*4882a593Smuzhiyun int index, cmd_index, len;
1305*4882a593Smuzhiyun struct iwl_rx_cmd_buffer rxcb = {
1306*4882a593Smuzhiyun ._offset = rxb->offset + offset,
1307*4882a593Smuzhiyun ._rx_page_order = trans_pcie->rx_page_order,
1308*4882a593Smuzhiyun ._page = rxb->page,
1309*4882a593Smuzhiyun ._page_stolen = false,
1310*4882a593Smuzhiyun .truesize = max_len,
1311*4882a593Smuzhiyun };
1312*4882a593Smuzhiyun
1313*4882a593Smuzhiyun pkt = rxb_addr(&rxcb);
1314*4882a593Smuzhiyun
1315*4882a593Smuzhiyun if (pkt->len_n_flags == cpu_to_le32(FH_RSCSR_FRAME_INVALID)) {
1316*4882a593Smuzhiyun IWL_DEBUG_RX(trans,
1317*4882a593Smuzhiyun "Q %d: RB end marker at offset %d\n",
1318*4882a593Smuzhiyun rxq->id, offset);
1319*4882a593Smuzhiyun break;
1320*4882a593Smuzhiyun }
1321*4882a593Smuzhiyun
1322*4882a593Smuzhiyun WARN((le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_RXQ_MASK) >>
1323*4882a593Smuzhiyun FH_RSCSR_RXQ_POS != rxq->id,
1324*4882a593Smuzhiyun "frame on invalid queue - is on %d and indicates %d\n",
1325*4882a593Smuzhiyun rxq->id,
1326*4882a593Smuzhiyun (le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_RXQ_MASK) >>
1327*4882a593Smuzhiyun FH_RSCSR_RXQ_POS);
1328*4882a593Smuzhiyun
1329*4882a593Smuzhiyun IWL_DEBUG_RX(trans,
1330*4882a593Smuzhiyun "Q %d: cmd at offset %d: %s (%.2x.%2x, seq 0x%x)\n",
1331*4882a593Smuzhiyun rxq->id, offset,
1332*4882a593Smuzhiyun iwl_get_cmd_string(trans,
1333*4882a593Smuzhiyun iwl_cmd_id(pkt->hdr.cmd,
1334*4882a593Smuzhiyun pkt->hdr.group_id,
1335*4882a593Smuzhiyun 0)),
1336*4882a593Smuzhiyun pkt->hdr.group_id, pkt->hdr.cmd,
1337*4882a593Smuzhiyun le16_to_cpu(pkt->hdr.sequence));
1338*4882a593Smuzhiyun
1339*4882a593Smuzhiyun len = iwl_rx_packet_len(pkt);
1340*4882a593Smuzhiyun len += sizeof(u32); /* account for status word */
1341*4882a593Smuzhiyun trace_iwlwifi_dev_rx(trans->dev, trans, pkt, len);
1342*4882a593Smuzhiyun trace_iwlwifi_dev_rx_data(trans->dev, trans, pkt, len);
1343*4882a593Smuzhiyun
1344*4882a593Smuzhiyun /* Reclaim a command buffer only if this packet is a response
1345*4882a593Smuzhiyun * to a (driver-originated) command.
1346*4882a593Smuzhiyun * If the packet (e.g. Rx frame) originated from uCode,
1347*4882a593Smuzhiyun * there is no command buffer to reclaim.
1348*4882a593Smuzhiyun * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1349*4882a593Smuzhiyun * but apparently a few don't get set; catch them here. */
1350*4882a593Smuzhiyun reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME);
1351*4882a593Smuzhiyun if (reclaim && !pkt->hdr.group_id) {
1352*4882a593Smuzhiyun int i;
1353*4882a593Smuzhiyun
1354*4882a593Smuzhiyun for (i = 0; i < trans_pcie->n_no_reclaim_cmds; i++) {
1355*4882a593Smuzhiyun if (trans_pcie->no_reclaim_cmds[i] ==
1356*4882a593Smuzhiyun pkt->hdr.cmd) {
1357*4882a593Smuzhiyun reclaim = false;
1358*4882a593Smuzhiyun break;
1359*4882a593Smuzhiyun }
1360*4882a593Smuzhiyun }
1361*4882a593Smuzhiyun }
1362*4882a593Smuzhiyun
1363*4882a593Smuzhiyun sequence = le16_to_cpu(pkt->hdr.sequence);
1364*4882a593Smuzhiyun index = SEQ_TO_INDEX(sequence);
1365*4882a593Smuzhiyun cmd_index = iwl_txq_get_cmd_index(txq, index);
1366*4882a593Smuzhiyun
1367*4882a593Smuzhiyun if (rxq->id == trans_pcie->def_rx_queue)
1368*4882a593Smuzhiyun iwl_op_mode_rx(trans->op_mode, &rxq->napi,
1369*4882a593Smuzhiyun &rxcb);
1370*4882a593Smuzhiyun else
1371*4882a593Smuzhiyun iwl_op_mode_rx_rss(trans->op_mode, &rxq->napi,
1372*4882a593Smuzhiyun &rxcb, rxq->id);
1373*4882a593Smuzhiyun
1374*4882a593Smuzhiyun if (reclaim) {
1375*4882a593Smuzhiyun kfree_sensitive(txq->entries[cmd_index].free_buf);
1376*4882a593Smuzhiyun txq->entries[cmd_index].free_buf = NULL;
1377*4882a593Smuzhiyun }
1378*4882a593Smuzhiyun
1379*4882a593Smuzhiyun /*
1380*4882a593Smuzhiyun * After here, we should always check rxcb._page_stolen,
1381*4882a593Smuzhiyun * if it is true then one of the handlers took the page.
1382*4882a593Smuzhiyun */
1383*4882a593Smuzhiyun
1384*4882a593Smuzhiyun if (reclaim) {
1385*4882a593Smuzhiyun /* Invoke any callbacks, transfer the buffer to caller,
1386*4882a593Smuzhiyun * and fire off the (possibly) blocking
1387*4882a593Smuzhiyun * iwl_trans_send_cmd()
1388*4882a593Smuzhiyun * as we reclaim the driver command queue */
1389*4882a593Smuzhiyun if (!rxcb._page_stolen)
1390*4882a593Smuzhiyun iwl_pcie_hcmd_complete(trans, &rxcb);
1391*4882a593Smuzhiyun else
1392*4882a593Smuzhiyun IWL_WARN(trans, "Claim null rxb?\n");
1393*4882a593Smuzhiyun }
1394*4882a593Smuzhiyun
1395*4882a593Smuzhiyun page_stolen |= rxcb._page_stolen;
1396*4882a593Smuzhiyun if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
1397*4882a593Smuzhiyun break;
1398*4882a593Smuzhiyun offset += ALIGN(len, FH_RSCSR_FRAME_ALIGN);
1399*4882a593Smuzhiyun }
1400*4882a593Smuzhiyun
1401*4882a593Smuzhiyun /* page was stolen from us -- free our reference */
1402*4882a593Smuzhiyun if (page_stolen) {
1403*4882a593Smuzhiyun __free_pages(rxb->page, trans_pcie->rx_page_order);
1404*4882a593Smuzhiyun rxb->page = NULL;
1405*4882a593Smuzhiyun }
1406*4882a593Smuzhiyun
1407*4882a593Smuzhiyun /* Reuse the page if possible. For notification packets and
1408*4882a593Smuzhiyun * SKBs that fail to Rx correctly, add them back into the
1409*4882a593Smuzhiyun * rx_free list for reuse later. */
1410*4882a593Smuzhiyun if (rxb->page != NULL) {
1411*4882a593Smuzhiyun rxb->page_dma =
1412*4882a593Smuzhiyun dma_map_page(trans->dev, rxb->page, rxb->offset,
1413*4882a593Smuzhiyun trans_pcie->rx_buf_bytes,
1414*4882a593Smuzhiyun DMA_FROM_DEVICE);
1415*4882a593Smuzhiyun if (dma_mapping_error(trans->dev, rxb->page_dma)) {
1416*4882a593Smuzhiyun /*
1417*4882a593Smuzhiyun * free the page(s) as well to not break
1418*4882a593Smuzhiyun * the invariant that the items on the used
1419*4882a593Smuzhiyun * list have no page(s)
1420*4882a593Smuzhiyun */
1421*4882a593Smuzhiyun __free_pages(rxb->page, trans_pcie->rx_page_order);
1422*4882a593Smuzhiyun rxb->page = NULL;
1423*4882a593Smuzhiyun iwl_pcie_rx_reuse_rbd(trans, rxb, rxq, emergency);
1424*4882a593Smuzhiyun } else {
1425*4882a593Smuzhiyun list_add_tail(&rxb->list, &rxq->rx_free);
1426*4882a593Smuzhiyun rxq->free_count++;
1427*4882a593Smuzhiyun }
1428*4882a593Smuzhiyun } else
1429*4882a593Smuzhiyun iwl_pcie_rx_reuse_rbd(trans, rxb, rxq, emergency);
1430*4882a593Smuzhiyun }
1431*4882a593Smuzhiyun
iwl_pcie_get_rxb(struct iwl_trans * trans,struct iwl_rxq * rxq,int i,bool * join)1432*4882a593Smuzhiyun static struct iwl_rx_mem_buffer *iwl_pcie_get_rxb(struct iwl_trans *trans,
1433*4882a593Smuzhiyun struct iwl_rxq *rxq, int i,
1434*4882a593Smuzhiyun bool *join)
1435*4882a593Smuzhiyun {
1436*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1437*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb;
1438*4882a593Smuzhiyun u16 vid;
1439*4882a593Smuzhiyun
1440*4882a593Smuzhiyun BUILD_BUG_ON(sizeof(struct iwl_rx_completion_desc) != 32);
1441*4882a593Smuzhiyun
1442*4882a593Smuzhiyun if (!trans->trans_cfg->mq_rx_supported) {
1443*4882a593Smuzhiyun rxb = rxq->queue[i];
1444*4882a593Smuzhiyun rxq->queue[i] = NULL;
1445*4882a593Smuzhiyun return rxb;
1446*4882a593Smuzhiyun }
1447*4882a593Smuzhiyun
1448*4882a593Smuzhiyun if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
1449*4882a593Smuzhiyun vid = le16_to_cpu(rxq->cd[i].rbid);
1450*4882a593Smuzhiyun *join = rxq->cd[i].flags & IWL_RX_CD_FLAGS_FRAGMENTED;
1451*4882a593Smuzhiyun } else {
1452*4882a593Smuzhiyun vid = le32_to_cpu(rxq->bd_32[i]) & 0x0FFF; /* 12-bit VID */
1453*4882a593Smuzhiyun }
1454*4882a593Smuzhiyun
1455*4882a593Smuzhiyun if (!vid || vid > RX_POOL_SIZE(trans_pcie->num_rx_bufs))
1456*4882a593Smuzhiyun goto out_err;
1457*4882a593Smuzhiyun
1458*4882a593Smuzhiyun rxb = trans_pcie->global_table[vid - 1];
1459*4882a593Smuzhiyun if (rxb->invalid)
1460*4882a593Smuzhiyun goto out_err;
1461*4882a593Smuzhiyun
1462*4882a593Smuzhiyun IWL_DEBUG_RX(trans, "Got virtual RB ID %u\n", (u32)rxb->vid);
1463*4882a593Smuzhiyun
1464*4882a593Smuzhiyun rxb->invalid = true;
1465*4882a593Smuzhiyun
1466*4882a593Smuzhiyun return rxb;
1467*4882a593Smuzhiyun
1468*4882a593Smuzhiyun out_err:
1469*4882a593Smuzhiyun WARN(1, "Invalid rxb from HW %u\n", (u32)vid);
1470*4882a593Smuzhiyun iwl_force_nmi(trans);
1471*4882a593Smuzhiyun return NULL;
1472*4882a593Smuzhiyun }
1473*4882a593Smuzhiyun
1474*4882a593Smuzhiyun /*
1475*4882a593Smuzhiyun * iwl_pcie_rx_handle - Main entry function for receiving responses from fw
1476*4882a593Smuzhiyun */
iwl_pcie_rx_handle(struct iwl_trans * trans,int queue)1477*4882a593Smuzhiyun static void iwl_pcie_rx_handle(struct iwl_trans *trans, int queue)
1478*4882a593Smuzhiyun {
1479*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1480*4882a593Smuzhiyun struct napi_struct *napi;
1481*4882a593Smuzhiyun struct iwl_rxq *rxq;
1482*4882a593Smuzhiyun u32 r, i, count = 0;
1483*4882a593Smuzhiyun bool emergency = false;
1484*4882a593Smuzhiyun
1485*4882a593Smuzhiyun if (WARN_ON_ONCE(!trans_pcie->rxq || !trans_pcie->rxq[queue].bd))
1486*4882a593Smuzhiyun return;
1487*4882a593Smuzhiyun
1488*4882a593Smuzhiyun rxq = &trans_pcie->rxq[queue];
1489*4882a593Smuzhiyun
1490*4882a593Smuzhiyun restart:
1491*4882a593Smuzhiyun spin_lock(&rxq->lock);
1492*4882a593Smuzhiyun /* uCode's read index (stored in shared DRAM) indicates the last Rx
1493*4882a593Smuzhiyun * buffer that the driver may process (last buffer filled by ucode). */
1494*4882a593Smuzhiyun r = le16_to_cpu(iwl_get_closed_rb_stts(trans, rxq)) & 0x0FFF;
1495*4882a593Smuzhiyun i = rxq->read;
1496*4882a593Smuzhiyun
1497*4882a593Smuzhiyun /* W/A 9000 device step A0 wrap-around bug */
1498*4882a593Smuzhiyun r &= (rxq->queue_size - 1);
1499*4882a593Smuzhiyun
1500*4882a593Smuzhiyun /* Rx interrupt, but nothing sent from uCode */
1501*4882a593Smuzhiyun if (i == r)
1502*4882a593Smuzhiyun IWL_DEBUG_RX(trans, "Q %d: HW = SW = %d\n", rxq->id, r);
1503*4882a593Smuzhiyun
1504*4882a593Smuzhiyun while (i != r) {
1505*4882a593Smuzhiyun struct iwl_rb_allocator *rba = &trans_pcie->rba;
1506*4882a593Smuzhiyun struct iwl_rx_mem_buffer *rxb;
1507*4882a593Smuzhiyun /* number of RBDs still waiting for page allocation */
1508*4882a593Smuzhiyun u32 rb_pending_alloc =
1509*4882a593Smuzhiyun atomic_read(&trans_pcie->rba.req_pending) *
1510*4882a593Smuzhiyun RX_CLAIM_REQ_ALLOC;
1511*4882a593Smuzhiyun bool join = false;
1512*4882a593Smuzhiyun
1513*4882a593Smuzhiyun if (unlikely(rb_pending_alloc >= rxq->queue_size / 2 &&
1514*4882a593Smuzhiyun !emergency)) {
1515*4882a593Smuzhiyun iwl_pcie_rx_move_to_allocator(rxq, rba);
1516*4882a593Smuzhiyun emergency = true;
1517*4882a593Smuzhiyun IWL_DEBUG_TPT(trans,
1518*4882a593Smuzhiyun "RX path is in emergency. Pending allocations %d\n",
1519*4882a593Smuzhiyun rb_pending_alloc);
1520*4882a593Smuzhiyun }
1521*4882a593Smuzhiyun
1522*4882a593Smuzhiyun IWL_DEBUG_RX(trans, "Q %d: HW = %d, SW = %d\n", rxq->id, r, i);
1523*4882a593Smuzhiyun
1524*4882a593Smuzhiyun rxb = iwl_pcie_get_rxb(trans, rxq, i, &join);
1525*4882a593Smuzhiyun if (!rxb)
1526*4882a593Smuzhiyun goto out;
1527*4882a593Smuzhiyun
1528*4882a593Smuzhiyun if (unlikely(join || rxq->next_rb_is_fragment)) {
1529*4882a593Smuzhiyun rxq->next_rb_is_fragment = join;
1530*4882a593Smuzhiyun /*
1531*4882a593Smuzhiyun * We can only get a multi-RB in the following cases:
1532*4882a593Smuzhiyun * - firmware issue, sending a too big notification
1533*4882a593Smuzhiyun * - sniffer mode with a large A-MSDU
1534*4882a593Smuzhiyun * - large MTU frames (>2k)
1535*4882a593Smuzhiyun * since the multi-RB functionality is limited to newer
1536*4882a593Smuzhiyun * hardware that cannot put multiple entries into a
1537*4882a593Smuzhiyun * single RB.
1538*4882a593Smuzhiyun *
1539*4882a593Smuzhiyun * Right now, the higher layers aren't set up to deal
1540*4882a593Smuzhiyun * with that, so discard all of these.
1541*4882a593Smuzhiyun */
1542*4882a593Smuzhiyun list_add_tail(&rxb->list, &rxq->rx_free);
1543*4882a593Smuzhiyun rxq->free_count++;
1544*4882a593Smuzhiyun } else {
1545*4882a593Smuzhiyun iwl_pcie_rx_handle_rb(trans, rxq, rxb, emergency, i);
1546*4882a593Smuzhiyun }
1547*4882a593Smuzhiyun
1548*4882a593Smuzhiyun i = (i + 1) & (rxq->queue_size - 1);
1549*4882a593Smuzhiyun
1550*4882a593Smuzhiyun /*
1551*4882a593Smuzhiyun * If we have RX_CLAIM_REQ_ALLOC released rx buffers -
1552*4882a593Smuzhiyun * try to claim the pre-allocated buffers from the allocator.
1553*4882a593Smuzhiyun * If not ready - will try to reclaim next time.
1554*4882a593Smuzhiyun * There is no need to reschedule work - allocator exits only
1555*4882a593Smuzhiyun * on success
1556*4882a593Smuzhiyun */
1557*4882a593Smuzhiyun if (rxq->used_count >= RX_CLAIM_REQ_ALLOC)
1558*4882a593Smuzhiyun iwl_pcie_rx_allocator_get(trans, rxq);
1559*4882a593Smuzhiyun
1560*4882a593Smuzhiyun if (rxq->used_count % RX_CLAIM_REQ_ALLOC == 0 && !emergency) {
1561*4882a593Smuzhiyun /* Add the remaining empty RBDs for allocator use */
1562*4882a593Smuzhiyun iwl_pcie_rx_move_to_allocator(rxq, rba);
1563*4882a593Smuzhiyun } else if (emergency) {
1564*4882a593Smuzhiyun count++;
1565*4882a593Smuzhiyun if (count == 8) {
1566*4882a593Smuzhiyun count = 0;
1567*4882a593Smuzhiyun if (rb_pending_alloc < rxq->queue_size / 3) {
1568*4882a593Smuzhiyun IWL_DEBUG_TPT(trans,
1569*4882a593Smuzhiyun "RX path exited emergency. Pending allocations %d\n",
1570*4882a593Smuzhiyun rb_pending_alloc);
1571*4882a593Smuzhiyun emergency = false;
1572*4882a593Smuzhiyun }
1573*4882a593Smuzhiyun
1574*4882a593Smuzhiyun rxq->read = i;
1575*4882a593Smuzhiyun spin_unlock(&rxq->lock);
1576*4882a593Smuzhiyun iwl_pcie_rxq_alloc_rbs(trans, GFP_ATOMIC, rxq);
1577*4882a593Smuzhiyun iwl_pcie_rxq_restock(trans, rxq);
1578*4882a593Smuzhiyun goto restart;
1579*4882a593Smuzhiyun }
1580*4882a593Smuzhiyun }
1581*4882a593Smuzhiyun }
1582*4882a593Smuzhiyun out:
1583*4882a593Smuzhiyun /* Backtrack one entry */
1584*4882a593Smuzhiyun rxq->read = i;
1585*4882a593Smuzhiyun /* update cr tail with the rxq read pointer */
1586*4882a593Smuzhiyun if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
1587*4882a593Smuzhiyun *rxq->cr_tail = cpu_to_le16(r);
1588*4882a593Smuzhiyun spin_unlock(&rxq->lock);
1589*4882a593Smuzhiyun
1590*4882a593Smuzhiyun /*
1591*4882a593Smuzhiyun * handle a case where in emergency there are some unallocated RBDs.
1592*4882a593Smuzhiyun * those RBDs are in the used list, but are not tracked by the queue's
1593*4882a593Smuzhiyun * used_count which counts allocator owned RBDs.
1594*4882a593Smuzhiyun * unallocated emergency RBDs must be allocated on exit, otherwise
1595*4882a593Smuzhiyun * when called again the function may not be in emergency mode and
1596*4882a593Smuzhiyun * they will be handed to the allocator with no tracking in the RBD
1597*4882a593Smuzhiyun * allocator counters, which will lead to them never being claimed back
1598*4882a593Smuzhiyun * by the queue.
1599*4882a593Smuzhiyun * by allocating them here, they are now in the queue free list, and
1600*4882a593Smuzhiyun * will be restocked by the next call of iwl_pcie_rxq_restock.
1601*4882a593Smuzhiyun */
1602*4882a593Smuzhiyun if (unlikely(emergency && count))
1603*4882a593Smuzhiyun iwl_pcie_rxq_alloc_rbs(trans, GFP_ATOMIC, rxq);
1604*4882a593Smuzhiyun
1605*4882a593Smuzhiyun napi = &rxq->napi;
1606*4882a593Smuzhiyun if (napi->poll) {
1607*4882a593Smuzhiyun napi_gro_flush(napi, false);
1608*4882a593Smuzhiyun
1609*4882a593Smuzhiyun if (napi->rx_count) {
1610*4882a593Smuzhiyun netif_receive_skb_list(&napi->rx_list);
1611*4882a593Smuzhiyun INIT_LIST_HEAD(&napi->rx_list);
1612*4882a593Smuzhiyun napi->rx_count = 0;
1613*4882a593Smuzhiyun }
1614*4882a593Smuzhiyun }
1615*4882a593Smuzhiyun
1616*4882a593Smuzhiyun iwl_pcie_rxq_restock(trans, rxq);
1617*4882a593Smuzhiyun }
1618*4882a593Smuzhiyun
iwl_pcie_get_trans_pcie(struct msix_entry * entry)1619*4882a593Smuzhiyun static struct iwl_trans_pcie *iwl_pcie_get_trans_pcie(struct msix_entry *entry)
1620*4882a593Smuzhiyun {
1621*4882a593Smuzhiyun u8 queue = entry->entry;
1622*4882a593Smuzhiyun struct msix_entry *entries = entry - queue;
1623*4882a593Smuzhiyun
1624*4882a593Smuzhiyun return container_of(entries, struct iwl_trans_pcie, msix_entries[0]);
1625*4882a593Smuzhiyun }
1626*4882a593Smuzhiyun
1627*4882a593Smuzhiyun /*
1628*4882a593Smuzhiyun * iwl_pcie_rx_msix_handle - Main entry function for receiving responses from fw
1629*4882a593Smuzhiyun * This interrupt handler should be used with RSS queue only.
1630*4882a593Smuzhiyun */
iwl_pcie_irq_rx_msix_handler(int irq,void * dev_id)1631*4882a593Smuzhiyun irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id)
1632*4882a593Smuzhiyun {
1633*4882a593Smuzhiyun struct msix_entry *entry = dev_id;
1634*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = iwl_pcie_get_trans_pcie(entry);
1635*4882a593Smuzhiyun struct iwl_trans *trans = trans_pcie->trans;
1636*4882a593Smuzhiyun
1637*4882a593Smuzhiyun trace_iwlwifi_dev_irq_msix(trans->dev, entry, false, 0, 0);
1638*4882a593Smuzhiyun
1639*4882a593Smuzhiyun if (WARN_ON(entry->entry >= trans->num_rx_queues))
1640*4882a593Smuzhiyun return IRQ_NONE;
1641*4882a593Smuzhiyun
1642*4882a593Smuzhiyun lock_map_acquire(&trans->sync_cmd_lockdep_map);
1643*4882a593Smuzhiyun
1644*4882a593Smuzhiyun local_bh_disable();
1645*4882a593Smuzhiyun iwl_pcie_rx_handle(trans, entry->entry);
1646*4882a593Smuzhiyun local_bh_enable();
1647*4882a593Smuzhiyun
1648*4882a593Smuzhiyun iwl_pcie_clear_irq(trans, entry);
1649*4882a593Smuzhiyun
1650*4882a593Smuzhiyun lock_map_release(&trans->sync_cmd_lockdep_map);
1651*4882a593Smuzhiyun
1652*4882a593Smuzhiyun return IRQ_HANDLED;
1653*4882a593Smuzhiyun }
1654*4882a593Smuzhiyun
1655*4882a593Smuzhiyun /*
1656*4882a593Smuzhiyun * iwl_pcie_irq_handle_error - called for HW or SW error interrupt from card
1657*4882a593Smuzhiyun */
iwl_pcie_irq_handle_error(struct iwl_trans * trans)1658*4882a593Smuzhiyun static void iwl_pcie_irq_handle_error(struct iwl_trans *trans)
1659*4882a593Smuzhiyun {
1660*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1661*4882a593Smuzhiyun int i;
1662*4882a593Smuzhiyun
1663*4882a593Smuzhiyun /* W/A for WiFi/WiMAX coex and WiMAX own the RF */
1664*4882a593Smuzhiyun if (trans->cfg->internal_wimax_coex &&
1665*4882a593Smuzhiyun !trans->cfg->apmg_not_supported &&
1666*4882a593Smuzhiyun (!(iwl_read_prph(trans, APMG_CLK_CTRL_REG) &
1667*4882a593Smuzhiyun APMS_CLK_VAL_MRB_FUNC_MODE) ||
1668*4882a593Smuzhiyun (iwl_read_prph(trans, APMG_PS_CTRL_REG) &
1669*4882a593Smuzhiyun APMG_PS_CTRL_VAL_RESET_REQ))) {
1670*4882a593Smuzhiyun clear_bit(STATUS_SYNC_HCMD_ACTIVE, &trans->status);
1671*4882a593Smuzhiyun iwl_op_mode_wimax_active(trans->op_mode);
1672*4882a593Smuzhiyun wake_up(&trans_pcie->wait_command_queue);
1673*4882a593Smuzhiyun return;
1674*4882a593Smuzhiyun }
1675*4882a593Smuzhiyun
1676*4882a593Smuzhiyun for (i = 0; i < trans->trans_cfg->base_params->num_of_queues; i++) {
1677*4882a593Smuzhiyun if (!trans->txqs.txq[i])
1678*4882a593Smuzhiyun continue;
1679*4882a593Smuzhiyun del_timer(&trans->txqs.txq[i]->stuck_timer);
1680*4882a593Smuzhiyun }
1681*4882a593Smuzhiyun
1682*4882a593Smuzhiyun /* The STATUS_FW_ERROR bit is set in this function. This must happen
1683*4882a593Smuzhiyun * before we wake up the command caller, to ensure a proper cleanup. */
1684*4882a593Smuzhiyun iwl_trans_fw_error(trans);
1685*4882a593Smuzhiyun
1686*4882a593Smuzhiyun clear_bit(STATUS_SYNC_HCMD_ACTIVE, &trans->status);
1687*4882a593Smuzhiyun wake_up(&trans_pcie->wait_command_queue);
1688*4882a593Smuzhiyun }
1689*4882a593Smuzhiyun
iwl_pcie_int_cause_non_ict(struct iwl_trans * trans)1690*4882a593Smuzhiyun static u32 iwl_pcie_int_cause_non_ict(struct iwl_trans *trans)
1691*4882a593Smuzhiyun {
1692*4882a593Smuzhiyun u32 inta;
1693*4882a593Smuzhiyun
1694*4882a593Smuzhiyun lockdep_assert_held(&IWL_TRANS_GET_PCIE_TRANS(trans)->irq_lock);
1695*4882a593Smuzhiyun
1696*4882a593Smuzhiyun trace_iwlwifi_dev_irq(trans->dev);
1697*4882a593Smuzhiyun
1698*4882a593Smuzhiyun /* Discover which interrupts are active/pending */
1699*4882a593Smuzhiyun inta = iwl_read32(trans, CSR_INT);
1700*4882a593Smuzhiyun
1701*4882a593Smuzhiyun /* the thread will service interrupts and re-enable them */
1702*4882a593Smuzhiyun return inta;
1703*4882a593Smuzhiyun }
1704*4882a593Smuzhiyun
1705*4882a593Smuzhiyun /* a device (PCI-E) page is 4096 bytes long */
1706*4882a593Smuzhiyun #define ICT_SHIFT 12
1707*4882a593Smuzhiyun #define ICT_SIZE (1 << ICT_SHIFT)
1708*4882a593Smuzhiyun #define ICT_COUNT (ICT_SIZE / sizeof(u32))
1709*4882a593Smuzhiyun
1710*4882a593Smuzhiyun /* interrupt handler using ict table, with this interrupt driver will
1711*4882a593Smuzhiyun * stop using INTA register to get device's interrupt, reading this register
1712*4882a593Smuzhiyun * is expensive, device will write interrupts in ICT dram table, increment
1713*4882a593Smuzhiyun * index then will fire interrupt to driver, driver will OR all ICT table
1714*4882a593Smuzhiyun * entries from current index up to table entry with 0 value. the result is
1715*4882a593Smuzhiyun * the interrupt we need to service, driver will set the entries back to 0 and
1716*4882a593Smuzhiyun * set index.
1717*4882a593Smuzhiyun */
iwl_pcie_int_cause_ict(struct iwl_trans * trans)1718*4882a593Smuzhiyun static u32 iwl_pcie_int_cause_ict(struct iwl_trans *trans)
1719*4882a593Smuzhiyun {
1720*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1721*4882a593Smuzhiyun u32 inta;
1722*4882a593Smuzhiyun u32 val = 0;
1723*4882a593Smuzhiyun u32 read;
1724*4882a593Smuzhiyun
1725*4882a593Smuzhiyun trace_iwlwifi_dev_irq(trans->dev);
1726*4882a593Smuzhiyun
1727*4882a593Smuzhiyun /* Ignore interrupt if there's nothing in NIC to service.
1728*4882a593Smuzhiyun * This may be due to IRQ shared with another device,
1729*4882a593Smuzhiyun * or due to sporadic interrupts thrown from our NIC. */
1730*4882a593Smuzhiyun read = le32_to_cpu(trans_pcie->ict_tbl[trans_pcie->ict_index]);
1731*4882a593Smuzhiyun trace_iwlwifi_dev_ict_read(trans->dev, trans_pcie->ict_index, read);
1732*4882a593Smuzhiyun if (!read)
1733*4882a593Smuzhiyun return 0;
1734*4882a593Smuzhiyun
1735*4882a593Smuzhiyun /*
1736*4882a593Smuzhiyun * Collect all entries up to the first 0, starting from ict_index;
1737*4882a593Smuzhiyun * note we already read at ict_index.
1738*4882a593Smuzhiyun */
1739*4882a593Smuzhiyun do {
1740*4882a593Smuzhiyun val |= read;
1741*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "ICT index %d value 0x%08X\n",
1742*4882a593Smuzhiyun trans_pcie->ict_index, read);
1743*4882a593Smuzhiyun trans_pcie->ict_tbl[trans_pcie->ict_index] = 0;
1744*4882a593Smuzhiyun trans_pcie->ict_index =
1745*4882a593Smuzhiyun ((trans_pcie->ict_index + 1) & (ICT_COUNT - 1));
1746*4882a593Smuzhiyun
1747*4882a593Smuzhiyun read = le32_to_cpu(trans_pcie->ict_tbl[trans_pcie->ict_index]);
1748*4882a593Smuzhiyun trace_iwlwifi_dev_ict_read(trans->dev, trans_pcie->ict_index,
1749*4882a593Smuzhiyun read);
1750*4882a593Smuzhiyun } while (read);
1751*4882a593Smuzhiyun
1752*4882a593Smuzhiyun /* We should not get this value, just ignore it. */
1753*4882a593Smuzhiyun if (val == 0xffffffff)
1754*4882a593Smuzhiyun val = 0;
1755*4882a593Smuzhiyun
1756*4882a593Smuzhiyun /*
1757*4882a593Smuzhiyun * this is a w/a for a h/w bug. the h/w bug may cause the Rx bit
1758*4882a593Smuzhiyun * (bit 15 before shifting it to 31) to clear when using interrupt
1759*4882a593Smuzhiyun * coalescing. fortunately, bits 18 and 19 stay set when this happens
1760*4882a593Smuzhiyun * so we use them to decide on the real state of the Rx bit.
1761*4882a593Smuzhiyun * In order words, bit 15 is set if bit 18 or bit 19 are set.
1762*4882a593Smuzhiyun */
1763*4882a593Smuzhiyun if (val & 0xC0000)
1764*4882a593Smuzhiyun val |= 0x8000;
1765*4882a593Smuzhiyun
1766*4882a593Smuzhiyun inta = (0xff & val) | ((0xff00 & val) << 16);
1767*4882a593Smuzhiyun return inta;
1768*4882a593Smuzhiyun }
1769*4882a593Smuzhiyun
iwl_pcie_handle_rfkill_irq(struct iwl_trans * trans)1770*4882a593Smuzhiyun void iwl_pcie_handle_rfkill_irq(struct iwl_trans *trans)
1771*4882a593Smuzhiyun {
1772*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1773*4882a593Smuzhiyun struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
1774*4882a593Smuzhiyun bool hw_rfkill, prev, report;
1775*4882a593Smuzhiyun
1776*4882a593Smuzhiyun mutex_lock(&trans_pcie->mutex);
1777*4882a593Smuzhiyun prev = test_bit(STATUS_RFKILL_OPMODE, &trans->status);
1778*4882a593Smuzhiyun hw_rfkill = iwl_is_rfkill_set(trans);
1779*4882a593Smuzhiyun if (hw_rfkill) {
1780*4882a593Smuzhiyun set_bit(STATUS_RFKILL_OPMODE, &trans->status);
1781*4882a593Smuzhiyun set_bit(STATUS_RFKILL_HW, &trans->status);
1782*4882a593Smuzhiyun }
1783*4882a593Smuzhiyun if (trans_pcie->opmode_down)
1784*4882a593Smuzhiyun report = hw_rfkill;
1785*4882a593Smuzhiyun else
1786*4882a593Smuzhiyun report = test_bit(STATUS_RFKILL_OPMODE, &trans->status);
1787*4882a593Smuzhiyun
1788*4882a593Smuzhiyun IWL_WARN(trans, "RF_KILL bit toggled to %s.\n",
1789*4882a593Smuzhiyun hw_rfkill ? "disable radio" : "enable radio");
1790*4882a593Smuzhiyun
1791*4882a593Smuzhiyun isr_stats->rfkill++;
1792*4882a593Smuzhiyun
1793*4882a593Smuzhiyun if (prev != report)
1794*4882a593Smuzhiyun iwl_trans_pcie_rf_kill(trans, report);
1795*4882a593Smuzhiyun mutex_unlock(&trans_pcie->mutex);
1796*4882a593Smuzhiyun
1797*4882a593Smuzhiyun if (hw_rfkill) {
1798*4882a593Smuzhiyun if (test_and_clear_bit(STATUS_SYNC_HCMD_ACTIVE,
1799*4882a593Smuzhiyun &trans->status))
1800*4882a593Smuzhiyun IWL_DEBUG_RF_KILL(trans,
1801*4882a593Smuzhiyun "Rfkill while SYNC HCMD in flight\n");
1802*4882a593Smuzhiyun wake_up(&trans_pcie->wait_command_queue);
1803*4882a593Smuzhiyun } else {
1804*4882a593Smuzhiyun clear_bit(STATUS_RFKILL_HW, &trans->status);
1805*4882a593Smuzhiyun if (trans_pcie->opmode_down)
1806*4882a593Smuzhiyun clear_bit(STATUS_RFKILL_OPMODE, &trans->status);
1807*4882a593Smuzhiyun }
1808*4882a593Smuzhiyun }
1809*4882a593Smuzhiyun
iwl_pcie_irq_handler(int irq,void * dev_id)1810*4882a593Smuzhiyun irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id)
1811*4882a593Smuzhiyun {
1812*4882a593Smuzhiyun struct iwl_trans *trans = dev_id;
1813*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1814*4882a593Smuzhiyun struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
1815*4882a593Smuzhiyun u32 inta = 0;
1816*4882a593Smuzhiyun u32 handled = 0;
1817*4882a593Smuzhiyun
1818*4882a593Smuzhiyun lock_map_acquire(&trans->sync_cmd_lockdep_map);
1819*4882a593Smuzhiyun
1820*4882a593Smuzhiyun spin_lock(&trans_pcie->irq_lock);
1821*4882a593Smuzhiyun
1822*4882a593Smuzhiyun /* dram interrupt table not set yet,
1823*4882a593Smuzhiyun * use legacy interrupt.
1824*4882a593Smuzhiyun */
1825*4882a593Smuzhiyun if (likely(trans_pcie->use_ict))
1826*4882a593Smuzhiyun inta = iwl_pcie_int_cause_ict(trans);
1827*4882a593Smuzhiyun else
1828*4882a593Smuzhiyun inta = iwl_pcie_int_cause_non_ict(trans);
1829*4882a593Smuzhiyun
1830*4882a593Smuzhiyun if (iwl_have_debug_level(IWL_DL_ISR)) {
1831*4882a593Smuzhiyun IWL_DEBUG_ISR(trans,
1832*4882a593Smuzhiyun "ISR inta 0x%08x, enabled 0x%08x(sw), enabled(hw) 0x%08x, fh 0x%08x\n",
1833*4882a593Smuzhiyun inta, trans_pcie->inta_mask,
1834*4882a593Smuzhiyun iwl_read32(trans, CSR_INT_MASK),
1835*4882a593Smuzhiyun iwl_read32(trans, CSR_FH_INT_STATUS));
1836*4882a593Smuzhiyun if (inta & (~trans_pcie->inta_mask))
1837*4882a593Smuzhiyun IWL_DEBUG_ISR(trans,
1838*4882a593Smuzhiyun "We got a masked interrupt (0x%08x)\n",
1839*4882a593Smuzhiyun inta & (~trans_pcie->inta_mask));
1840*4882a593Smuzhiyun }
1841*4882a593Smuzhiyun
1842*4882a593Smuzhiyun inta &= trans_pcie->inta_mask;
1843*4882a593Smuzhiyun
1844*4882a593Smuzhiyun /*
1845*4882a593Smuzhiyun * Ignore interrupt if there's nothing in NIC to service.
1846*4882a593Smuzhiyun * This may be due to IRQ shared with another device,
1847*4882a593Smuzhiyun * or due to sporadic interrupts thrown from our NIC.
1848*4882a593Smuzhiyun */
1849*4882a593Smuzhiyun if (unlikely(!inta)) {
1850*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "Ignore interrupt, inta == 0\n");
1851*4882a593Smuzhiyun /*
1852*4882a593Smuzhiyun * Re-enable interrupts here since we don't
1853*4882a593Smuzhiyun * have anything to service
1854*4882a593Smuzhiyun */
1855*4882a593Smuzhiyun if (test_bit(STATUS_INT_ENABLED, &trans->status))
1856*4882a593Smuzhiyun _iwl_enable_interrupts(trans);
1857*4882a593Smuzhiyun spin_unlock(&trans_pcie->irq_lock);
1858*4882a593Smuzhiyun lock_map_release(&trans->sync_cmd_lockdep_map);
1859*4882a593Smuzhiyun return IRQ_NONE;
1860*4882a593Smuzhiyun }
1861*4882a593Smuzhiyun
1862*4882a593Smuzhiyun if (unlikely(inta == 0xFFFFFFFF || (inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1863*4882a593Smuzhiyun /*
1864*4882a593Smuzhiyun * Hardware disappeared. It might have
1865*4882a593Smuzhiyun * already raised an interrupt.
1866*4882a593Smuzhiyun */
1867*4882a593Smuzhiyun IWL_WARN(trans, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
1868*4882a593Smuzhiyun spin_unlock(&trans_pcie->irq_lock);
1869*4882a593Smuzhiyun goto out;
1870*4882a593Smuzhiyun }
1871*4882a593Smuzhiyun
1872*4882a593Smuzhiyun /* Ack/clear/reset pending uCode interrupts.
1873*4882a593Smuzhiyun * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1874*4882a593Smuzhiyun */
1875*4882a593Smuzhiyun /* There is a hardware bug in the interrupt mask function that some
1876*4882a593Smuzhiyun * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if
1877*4882a593Smuzhiyun * they are disabled in the CSR_INT_MASK register. Furthermore the
1878*4882a593Smuzhiyun * ICT interrupt handling mechanism has another bug that might cause
1879*4882a593Smuzhiyun * these unmasked interrupts fail to be detected. We workaround the
1880*4882a593Smuzhiyun * hardware bugs here by ACKing all the possible interrupts so that
1881*4882a593Smuzhiyun * interrupt coalescing can still be achieved.
1882*4882a593Smuzhiyun */
1883*4882a593Smuzhiyun iwl_write32(trans, CSR_INT, inta | ~trans_pcie->inta_mask);
1884*4882a593Smuzhiyun
1885*4882a593Smuzhiyun if (iwl_have_debug_level(IWL_DL_ISR))
1886*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "inta 0x%08x, enabled 0x%08x\n",
1887*4882a593Smuzhiyun inta, iwl_read32(trans, CSR_INT_MASK));
1888*4882a593Smuzhiyun
1889*4882a593Smuzhiyun spin_unlock(&trans_pcie->irq_lock);
1890*4882a593Smuzhiyun
1891*4882a593Smuzhiyun /* Now service all interrupt bits discovered above. */
1892*4882a593Smuzhiyun if (inta & CSR_INT_BIT_HW_ERR) {
1893*4882a593Smuzhiyun IWL_ERR(trans, "Hardware error detected. Restarting.\n");
1894*4882a593Smuzhiyun
1895*4882a593Smuzhiyun /* Tell the device to stop sending interrupts */
1896*4882a593Smuzhiyun iwl_disable_interrupts(trans);
1897*4882a593Smuzhiyun
1898*4882a593Smuzhiyun isr_stats->hw++;
1899*4882a593Smuzhiyun iwl_pcie_irq_handle_error(trans);
1900*4882a593Smuzhiyun
1901*4882a593Smuzhiyun handled |= CSR_INT_BIT_HW_ERR;
1902*4882a593Smuzhiyun
1903*4882a593Smuzhiyun goto out;
1904*4882a593Smuzhiyun }
1905*4882a593Smuzhiyun
1906*4882a593Smuzhiyun /* NIC fires this, but we don't use it, redundant with WAKEUP */
1907*4882a593Smuzhiyun if (inta & CSR_INT_BIT_SCD) {
1908*4882a593Smuzhiyun IWL_DEBUG_ISR(trans,
1909*4882a593Smuzhiyun "Scheduler finished to transmit the frame/frames.\n");
1910*4882a593Smuzhiyun isr_stats->sch++;
1911*4882a593Smuzhiyun }
1912*4882a593Smuzhiyun
1913*4882a593Smuzhiyun /* Alive notification via Rx interrupt will do the real work */
1914*4882a593Smuzhiyun if (inta & CSR_INT_BIT_ALIVE) {
1915*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "Alive interrupt\n");
1916*4882a593Smuzhiyun isr_stats->alive++;
1917*4882a593Smuzhiyun if (trans->trans_cfg->gen2) {
1918*4882a593Smuzhiyun /*
1919*4882a593Smuzhiyun * We can restock, since firmware configured
1920*4882a593Smuzhiyun * the RFH
1921*4882a593Smuzhiyun */
1922*4882a593Smuzhiyun iwl_pcie_rxmq_restock(trans, trans_pcie->rxq);
1923*4882a593Smuzhiyun }
1924*4882a593Smuzhiyun
1925*4882a593Smuzhiyun handled |= CSR_INT_BIT_ALIVE;
1926*4882a593Smuzhiyun }
1927*4882a593Smuzhiyun
1928*4882a593Smuzhiyun /* Safely ignore these bits for debug checks below */
1929*4882a593Smuzhiyun inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1930*4882a593Smuzhiyun
1931*4882a593Smuzhiyun /* HW RF KILL switch toggled */
1932*4882a593Smuzhiyun if (inta & CSR_INT_BIT_RF_KILL) {
1933*4882a593Smuzhiyun iwl_pcie_handle_rfkill_irq(trans);
1934*4882a593Smuzhiyun handled |= CSR_INT_BIT_RF_KILL;
1935*4882a593Smuzhiyun }
1936*4882a593Smuzhiyun
1937*4882a593Smuzhiyun /* Chip got too hot and stopped itself */
1938*4882a593Smuzhiyun if (inta & CSR_INT_BIT_CT_KILL) {
1939*4882a593Smuzhiyun IWL_ERR(trans, "Microcode CT kill error detected.\n");
1940*4882a593Smuzhiyun isr_stats->ctkill++;
1941*4882a593Smuzhiyun handled |= CSR_INT_BIT_CT_KILL;
1942*4882a593Smuzhiyun }
1943*4882a593Smuzhiyun
1944*4882a593Smuzhiyun /* Error detected by uCode */
1945*4882a593Smuzhiyun if (inta & CSR_INT_BIT_SW_ERR) {
1946*4882a593Smuzhiyun IWL_ERR(trans, "Microcode SW error detected. "
1947*4882a593Smuzhiyun " Restarting 0x%X.\n", inta);
1948*4882a593Smuzhiyun isr_stats->sw++;
1949*4882a593Smuzhiyun iwl_pcie_irq_handle_error(trans);
1950*4882a593Smuzhiyun handled |= CSR_INT_BIT_SW_ERR;
1951*4882a593Smuzhiyun }
1952*4882a593Smuzhiyun
1953*4882a593Smuzhiyun /* uCode wakes up after power-down sleep */
1954*4882a593Smuzhiyun if (inta & CSR_INT_BIT_WAKEUP) {
1955*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "Wakeup interrupt\n");
1956*4882a593Smuzhiyun iwl_pcie_rxq_check_wrptr(trans);
1957*4882a593Smuzhiyun iwl_pcie_txq_check_wrptrs(trans);
1958*4882a593Smuzhiyun
1959*4882a593Smuzhiyun isr_stats->wakeup++;
1960*4882a593Smuzhiyun
1961*4882a593Smuzhiyun handled |= CSR_INT_BIT_WAKEUP;
1962*4882a593Smuzhiyun }
1963*4882a593Smuzhiyun
1964*4882a593Smuzhiyun /* All uCode command responses, including Tx command responses,
1965*4882a593Smuzhiyun * Rx "responses" (frame-received notification), and other
1966*4882a593Smuzhiyun * notifications from uCode come through here*/
1967*4882a593Smuzhiyun if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
1968*4882a593Smuzhiyun CSR_INT_BIT_RX_PERIODIC)) {
1969*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "Rx interrupt\n");
1970*4882a593Smuzhiyun if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1971*4882a593Smuzhiyun handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1972*4882a593Smuzhiyun iwl_write32(trans, CSR_FH_INT_STATUS,
1973*4882a593Smuzhiyun CSR_FH_INT_RX_MASK);
1974*4882a593Smuzhiyun }
1975*4882a593Smuzhiyun if (inta & CSR_INT_BIT_RX_PERIODIC) {
1976*4882a593Smuzhiyun handled |= CSR_INT_BIT_RX_PERIODIC;
1977*4882a593Smuzhiyun iwl_write32(trans,
1978*4882a593Smuzhiyun CSR_INT, CSR_INT_BIT_RX_PERIODIC);
1979*4882a593Smuzhiyun }
1980*4882a593Smuzhiyun /* Sending RX interrupt require many steps to be done in the
1981*4882a593Smuzhiyun * the device:
1982*4882a593Smuzhiyun * 1- write interrupt to current index in ICT table.
1983*4882a593Smuzhiyun * 2- dma RX frame.
1984*4882a593Smuzhiyun * 3- update RX shared data to indicate last write index.
1985*4882a593Smuzhiyun * 4- send interrupt.
1986*4882a593Smuzhiyun * This could lead to RX race, driver could receive RX interrupt
1987*4882a593Smuzhiyun * but the shared data changes does not reflect this;
1988*4882a593Smuzhiyun * periodic interrupt will detect any dangling Rx activity.
1989*4882a593Smuzhiyun */
1990*4882a593Smuzhiyun
1991*4882a593Smuzhiyun /* Disable periodic interrupt; we use it as just a one-shot. */
1992*4882a593Smuzhiyun iwl_write8(trans, CSR_INT_PERIODIC_REG,
1993*4882a593Smuzhiyun CSR_INT_PERIODIC_DIS);
1994*4882a593Smuzhiyun
1995*4882a593Smuzhiyun /*
1996*4882a593Smuzhiyun * Enable periodic interrupt in 8 msec only if we received
1997*4882a593Smuzhiyun * real RX interrupt (instead of just periodic int), to catch
1998*4882a593Smuzhiyun * any dangling Rx interrupt. If it was just the periodic
1999*4882a593Smuzhiyun * interrupt, there was no dangling Rx activity, and no need
2000*4882a593Smuzhiyun * to extend the periodic interrupt; one-shot is enough.
2001*4882a593Smuzhiyun */
2002*4882a593Smuzhiyun if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
2003*4882a593Smuzhiyun iwl_write8(trans, CSR_INT_PERIODIC_REG,
2004*4882a593Smuzhiyun CSR_INT_PERIODIC_ENA);
2005*4882a593Smuzhiyun
2006*4882a593Smuzhiyun isr_stats->rx++;
2007*4882a593Smuzhiyun
2008*4882a593Smuzhiyun local_bh_disable();
2009*4882a593Smuzhiyun iwl_pcie_rx_handle(trans, 0);
2010*4882a593Smuzhiyun local_bh_enable();
2011*4882a593Smuzhiyun }
2012*4882a593Smuzhiyun
2013*4882a593Smuzhiyun /* This "Tx" DMA channel is used only for loading uCode */
2014*4882a593Smuzhiyun if (inta & CSR_INT_BIT_FH_TX) {
2015*4882a593Smuzhiyun iwl_write32(trans, CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK);
2016*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "uCode load interrupt\n");
2017*4882a593Smuzhiyun isr_stats->tx++;
2018*4882a593Smuzhiyun handled |= CSR_INT_BIT_FH_TX;
2019*4882a593Smuzhiyun /* Wake up uCode load routine, now that load is complete */
2020*4882a593Smuzhiyun trans_pcie->ucode_write_complete = true;
2021*4882a593Smuzhiyun wake_up(&trans_pcie->ucode_write_waitq);
2022*4882a593Smuzhiyun }
2023*4882a593Smuzhiyun
2024*4882a593Smuzhiyun if (inta & ~handled) {
2025*4882a593Smuzhiyun IWL_ERR(trans, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
2026*4882a593Smuzhiyun isr_stats->unhandled++;
2027*4882a593Smuzhiyun }
2028*4882a593Smuzhiyun
2029*4882a593Smuzhiyun if (inta & ~(trans_pcie->inta_mask)) {
2030*4882a593Smuzhiyun IWL_WARN(trans, "Disabled INTA bits 0x%08x were pending\n",
2031*4882a593Smuzhiyun inta & ~trans_pcie->inta_mask);
2032*4882a593Smuzhiyun }
2033*4882a593Smuzhiyun
2034*4882a593Smuzhiyun spin_lock(&trans_pcie->irq_lock);
2035*4882a593Smuzhiyun /* only Re-enable all interrupt if disabled by irq */
2036*4882a593Smuzhiyun if (test_bit(STATUS_INT_ENABLED, &trans->status))
2037*4882a593Smuzhiyun _iwl_enable_interrupts(trans);
2038*4882a593Smuzhiyun /* we are loading the firmware, enable FH_TX interrupt only */
2039*4882a593Smuzhiyun else if (handled & CSR_INT_BIT_FH_TX)
2040*4882a593Smuzhiyun iwl_enable_fw_load_int(trans);
2041*4882a593Smuzhiyun /* Re-enable RF_KILL if it occurred */
2042*4882a593Smuzhiyun else if (handled & CSR_INT_BIT_RF_KILL)
2043*4882a593Smuzhiyun iwl_enable_rfkill_int(trans);
2044*4882a593Smuzhiyun /* Re-enable the ALIVE / Rx interrupt if it occurred */
2045*4882a593Smuzhiyun else if (handled & (CSR_INT_BIT_ALIVE | CSR_INT_BIT_FH_RX))
2046*4882a593Smuzhiyun iwl_enable_fw_load_int_ctx_info(trans);
2047*4882a593Smuzhiyun spin_unlock(&trans_pcie->irq_lock);
2048*4882a593Smuzhiyun
2049*4882a593Smuzhiyun out:
2050*4882a593Smuzhiyun lock_map_release(&trans->sync_cmd_lockdep_map);
2051*4882a593Smuzhiyun return IRQ_HANDLED;
2052*4882a593Smuzhiyun }
2053*4882a593Smuzhiyun
2054*4882a593Smuzhiyun /******************************************************************************
2055*4882a593Smuzhiyun *
2056*4882a593Smuzhiyun * ICT functions
2057*4882a593Smuzhiyun *
2058*4882a593Smuzhiyun ******************************************************************************/
2059*4882a593Smuzhiyun
2060*4882a593Smuzhiyun /* Free dram table */
iwl_pcie_free_ict(struct iwl_trans * trans)2061*4882a593Smuzhiyun void iwl_pcie_free_ict(struct iwl_trans *trans)
2062*4882a593Smuzhiyun {
2063*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2064*4882a593Smuzhiyun
2065*4882a593Smuzhiyun if (trans_pcie->ict_tbl) {
2066*4882a593Smuzhiyun dma_free_coherent(trans->dev, ICT_SIZE,
2067*4882a593Smuzhiyun trans_pcie->ict_tbl,
2068*4882a593Smuzhiyun trans_pcie->ict_tbl_dma);
2069*4882a593Smuzhiyun trans_pcie->ict_tbl = NULL;
2070*4882a593Smuzhiyun trans_pcie->ict_tbl_dma = 0;
2071*4882a593Smuzhiyun }
2072*4882a593Smuzhiyun }
2073*4882a593Smuzhiyun
2074*4882a593Smuzhiyun /*
2075*4882a593Smuzhiyun * allocate dram shared table, it is an aligned memory
2076*4882a593Smuzhiyun * block of ICT_SIZE.
2077*4882a593Smuzhiyun * also reset all data related to ICT table interrupt.
2078*4882a593Smuzhiyun */
iwl_pcie_alloc_ict(struct iwl_trans * trans)2079*4882a593Smuzhiyun int iwl_pcie_alloc_ict(struct iwl_trans *trans)
2080*4882a593Smuzhiyun {
2081*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2082*4882a593Smuzhiyun
2083*4882a593Smuzhiyun trans_pcie->ict_tbl =
2084*4882a593Smuzhiyun dma_alloc_coherent(trans->dev, ICT_SIZE,
2085*4882a593Smuzhiyun &trans_pcie->ict_tbl_dma, GFP_KERNEL);
2086*4882a593Smuzhiyun if (!trans_pcie->ict_tbl)
2087*4882a593Smuzhiyun return -ENOMEM;
2088*4882a593Smuzhiyun
2089*4882a593Smuzhiyun /* just an API sanity check ... it is guaranteed to be aligned */
2090*4882a593Smuzhiyun if (WARN_ON(trans_pcie->ict_tbl_dma & (ICT_SIZE - 1))) {
2091*4882a593Smuzhiyun iwl_pcie_free_ict(trans);
2092*4882a593Smuzhiyun return -EINVAL;
2093*4882a593Smuzhiyun }
2094*4882a593Smuzhiyun
2095*4882a593Smuzhiyun return 0;
2096*4882a593Smuzhiyun }
2097*4882a593Smuzhiyun
2098*4882a593Smuzhiyun /* Device is going up inform it about using ICT interrupt table,
2099*4882a593Smuzhiyun * also we need to tell the driver to start using ICT interrupt.
2100*4882a593Smuzhiyun */
iwl_pcie_reset_ict(struct iwl_trans * trans)2101*4882a593Smuzhiyun void iwl_pcie_reset_ict(struct iwl_trans *trans)
2102*4882a593Smuzhiyun {
2103*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2104*4882a593Smuzhiyun u32 val;
2105*4882a593Smuzhiyun
2106*4882a593Smuzhiyun if (!trans_pcie->ict_tbl)
2107*4882a593Smuzhiyun return;
2108*4882a593Smuzhiyun
2109*4882a593Smuzhiyun spin_lock(&trans_pcie->irq_lock);
2110*4882a593Smuzhiyun _iwl_disable_interrupts(trans);
2111*4882a593Smuzhiyun
2112*4882a593Smuzhiyun memset(trans_pcie->ict_tbl, 0, ICT_SIZE);
2113*4882a593Smuzhiyun
2114*4882a593Smuzhiyun val = trans_pcie->ict_tbl_dma >> ICT_SHIFT;
2115*4882a593Smuzhiyun
2116*4882a593Smuzhiyun val |= CSR_DRAM_INT_TBL_ENABLE |
2117*4882a593Smuzhiyun CSR_DRAM_INIT_TBL_WRAP_CHECK |
2118*4882a593Smuzhiyun CSR_DRAM_INIT_TBL_WRITE_POINTER;
2119*4882a593Smuzhiyun
2120*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "CSR_DRAM_INT_TBL_REG =0x%x\n", val);
2121*4882a593Smuzhiyun
2122*4882a593Smuzhiyun iwl_write32(trans, CSR_DRAM_INT_TBL_REG, val);
2123*4882a593Smuzhiyun trans_pcie->use_ict = true;
2124*4882a593Smuzhiyun trans_pcie->ict_index = 0;
2125*4882a593Smuzhiyun iwl_write32(trans, CSR_INT, trans_pcie->inta_mask);
2126*4882a593Smuzhiyun _iwl_enable_interrupts(trans);
2127*4882a593Smuzhiyun spin_unlock(&trans_pcie->irq_lock);
2128*4882a593Smuzhiyun }
2129*4882a593Smuzhiyun
2130*4882a593Smuzhiyun /* Device is going down disable ict interrupt usage */
iwl_pcie_disable_ict(struct iwl_trans * trans)2131*4882a593Smuzhiyun void iwl_pcie_disable_ict(struct iwl_trans *trans)
2132*4882a593Smuzhiyun {
2133*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2134*4882a593Smuzhiyun
2135*4882a593Smuzhiyun spin_lock(&trans_pcie->irq_lock);
2136*4882a593Smuzhiyun trans_pcie->use_ict = false;
2137*4882a593Smuzhiyun spin_unlock(&trans_pcie->irq_lock);
2138*4882a593Smuzhiyun }
2139*4882a593Smuzhiyun
iwl_pcie_isr(int irq,void * data)2140*4882a593Smuzhiyun irqreturn_t iwl_pcie_isr(int irq, void *data)
2141*4882a593Smuzhiyun {
2142*4882a593Smuzhiyun struct iwl_trans *trans = data;
2143*4882a593Smuzhiyun
2144*4882a593Smuzhiyun if (!trans)
2145*4882a593Smuzhiyun return IRQ_NONE;
2146*4882a593Smuzhiyun
2147*4882a593Smuzhiyun /* Disable (but don't clear!) interrupts here to avoid
2148*4882a593Smuzhiyun * back-to-back ISRs and sporadic interrupts from our NIC.
2149*4882a593Smuzhiyun * If we have something to service, the tasklet will re-enable ints.
2150*4882a593Smuzhiyun * If we *don't* have something, we'll re-enable before leaving here.
2151*4882a593Smuzhiyun */
2152*4882a593Smuzhiyun iwl_write32(trans, CSR_INT_MASK, 0x00000000);
2153*4882a593Smuzhiyun
2154*4882a593Smuzhiyun return IRQ_WAKE_THREAD;
2155*4882a593Smuzhiyun }
2156*4882a593Smuzhiyun
iwl_pcie_msix_isr(int irq,void * data)2157*4882a593Smuzhiyun irqreturn_t iwl_pcie_msix_isr(int irq, void *data)
2158*4882a593Smuzhiyun {
2159*4882a593Smuzhiyun return IRQ_WAKE_THREAD;
2160*4882a593Smuzhiyun }
2161*4882a593Smuzhiyun
iwl_pcie_irq_msix_handler(int irq,void * dev_id)2162*4882a593Smuzhiyun irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id)
2163*4882a593Smuzhiyun {
2164*4882a593Smuzhiyun struct msix_entry *entry = dev_id;
2165*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = iwl_pcie_get_trans_pcie(entry);
2166*4882a593Smuzhiyun struct iwl_trans *trans = trans_pcie->trans;
2167*4882a593Smuzhiyun struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
2168*4882a593Smuzhiyun u32 inta_fh, inta_hw;
2169*4882a593Smuzhiyun
2170*4882a593Smuzhiyun lock_map_acquire(&trans->sync_cmd_lockdep_map);
2171*4882a593Smuzhiyun
2172*4882a593Smuzhiyun spin_lock(&trans_pcie->irq_lock);
2173*4882a593Smuzhiyun inta_fh = iwl_read32(trans, CSR_MSIX_FH_INT_CAUSES_AD);
2174*4882a593Smuzhiyun inta_hw = iwl_read32(trans, CSR_MSIX_HW_INT_CAUSES_AD);
2175*4882a593Smuzhiyun /*
2176*4882a593Smuzhiyun * Clear causes registers to avoid being handling the same cause.
2177*4882a593Smuzhiyun */
2178*4882a593Smuzhiyun iwl_write32(trans, CSR_MSIX_FH_INT_CAUSES_AD, inta_fh);
2179*4882a593Smuzhiyun iwl_write32(trans, CSR_MSIX_HW_INT_CAUSES_AD, inta_hw);
2180*4882a593Smuzhiyun spin_unlock(&trans_pcie->irq_lock);
2181*4882a593Smuzhiyun
2182*4882a593Smuzhiyun trace_iwlwifi_dev_irq_msix(trans->dev, entry, true, inta_fh, inta_hw);
2183*4882a593Smuzhiyun
2184*4882a593Smuzhiyun if (unlikely(!(inta_fh | inta_hw))) {
2185*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "Ignore interrupt, inta == 0\n");
2186*4882a593Smuzhiyun lock_map_release(&trans->sync_cmd_lockdep_map);
2187*4882a593Smuzhiyun return IRQ_NONE;
2188*4882a593Smuzhiyun }
2189*4882a593Smuzhiyun
2190*4882a593Smuzhiyun if (iwl_have_debug_level(IWL_DL_ISR)) {
2191*4882a593Smuzhiyun IWL_DEBUG_ISR(trans,
2192*4882a593Smuzhiyun "ISR inta_fh 0x%08x, enabled (sw) 0x%08x (hw) 0x%08x\n",
2193*4882a593Smuzhiyun inta_fh, trans_pcie->fh_mask,
2194*4882a593Smuzhiyun iwl_read32(trans, CSR_MSIX_FH_INT_MASK_AD));
2195*4882a593Smuzhiyun if (inta_fh & ~trans_pcie->fh_mask)
2196*4882a593Smuzhiyun IWL_DEBUG_ISR(trans,
2197*4882a593Smuzhiyun "We got a masked interrupt (0x%08x)\n",
2198*4882a593Smuzhiyun inta_fh & ~trans_pcie->fh_mask);
2199*4882a593Smuzhiyun }
2200*4882a593Smuzhiyun
2201*4882a593Smuzhiyun inta_fh &= trans_pcie->fh_mask;
2202*4882a593Smuzhiyun
2203*4882a593Smuzhiyun if ((trans_pcie->shared_vec_mask & IWL_SHARED_IRQ_NON_RX) &&
2204*4882a593Smuzhiyun inta_fh & MSIX_FH_INT_CAUSES_Q0) {
2205*4882a593Smuzhiyun local_bh_disable();
2206*4882a593Smuzhiyun iwl_pcie_rx_handle(trans, 0);
2207*4882a593Smuzhiyun local_bh_enable();
2208*4882a593Smuzhiyun }
2209*4882a593Smuzhiyun
2210*4882a593Smuzhiyun if ((trans_pcie->shared_vec_mask & IWL_SHARED_IRQ_FIRST_RSS) &&
2211*4882a593Smuzhiyun inta_fh & MSIX_FH_INT_CAUSES_Q1) {
2212*4882a593Smuzhiyun local_bh_disable();
2213*4882a593Smuzhiyun iwl_pcie_rx_handle(trans, 1);
2214*4882a593Smuzhiyun local_bh_enable();
2215*4882a593Smuzhiyun }
2216*4882a593Smuzhiyun
2217*4882a593Smuzhiyun /* This "Tx" DMA channel is used only for loading uCode */
2218*4882a593Smuzhiyun if (inta_fh & MSIX_FH_INT_CAUSES_D2S_CH0_NUM) {
2219*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "uCode load interrupt\n");
2220*4882a593Smuzhiyun isr_stats->tx++;
2221*4882a593Smuzhiyun /*
2222*4882a593Smuzhiyun * Wake up uCode load routine,
2223*4882a593Smuzhiyun * now that load is complete
2224*4882a593Smuzhiyun */
2225*4882a593Smuzhiyun trans_pcie->ucode_write_complete = true;
2226*4882a593Smuzhiyun wake_up(&trans_pcie->ucode_write_waitq);
2227*4882a593Smuzhiyun }
2228*4882a593Smuzhiyun
2229*4882a593Smuzhiyun /* Error detected by uCode */
2230*4882a593Smuzhiyun if ((inta_fh & MSIX_FH_INT_CAUSES_FH_ERR) ||
2231*4882a593Smuzhiyun (inta_hw & MSIX_HW_INT_CAUSES_REG_SW_ERR)) {
2232*4882a593Smuzhiyun IWL_ERR(trans,
2233*4882a593Smuzhiyun "Microcode SW error detected. Restarting 0x%X.\n",
2234*4882a593Smuzhiyun inta_fh);
2235*4882a593Smuzhiyun isr_stats->sw++;
2236*4882a593Smuzhiyun iwl_pcie_irq_handle_error(trans);
2237*4882a593Smuzhiyun }
2238*4882a593Smuzhiyun
2239*4882a593Smuzhiyun /* After checking FH register check HW register */
2240*4882a593Smuzhiyun if (iwl_have_debug_level(IWL_DL_ISR)) {
2241*4882a593Smuzhiyun IWL_DEBUG_ISR(trans,
2242*4882a593Smuzhiyun "ISR inta_hw 0x%08x, enabled (sw) 0x%08x (hw) 0x%08x\n",
2243*4882a593Smuzhiyun inta_hw, trans_pcie->hw_mask,
2244*4882a593Smuzhiyun iwl_read32(trans, CSR_MSIX_HW_INT_MASK_AD));
2245*4882a593Smuzhiyun if (inta_hw & ~trans_pcie->hw_mask)
2246*4882a593Smuzhiyun IWL_DEBUG_ISR(trans,
2247*4882a593Smuzhiyun "We got a masked interrupt 0x%08x\n",
2248*4882a593Smuzhiyun inta_hw & ~trans_pcie->hw_mask);
2249*4882a593Smuzhiyun }
2250*4882a593Smuzhiyun
2251*4882a593Smuzhiyun inta_hw &= trans_pcie->hw_mask;
2252*4882a593Smuzhiyun
2253*4882a593Smuzhiyun /* Alive notification via Rx interrupt will do the real work */
2254*4882a593Smuzhiyun if (inta_hw & MSIX_HW_INT_CAUSES_REG_ALIVE) {
2255*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "Alive interrupt\n");
2256*4882a593Smuzhiyun isr_stats->alive++;
2257*4882a593Smuzhiyun if (trans->trans_cfg->gen2) {
2258*4882a593Smuzhiyun /* We can restock, since firmware configured the RFH */
2259*4882a593Smuzhiyun iwl_pcie_rxmq_restock(trans, trans_pcie->rxq);
2260*4882a593Smuzhiyun }
2261*4882a593Smuzhiyun }
2262*4882a593Smuzhiyun
2263*4882a593Smuzhiyun /*
2264*4882a593Smuzhiyun * In some rare cases when the HW is in a bad state, we may
2265*4882a593Smuzhiyun * get this interrupt too early, when prph_info is still NULL.
2266*4882a593Smuzhiyun * So make sure that it's not NULL to prevent crashing.
2267*4882a593Smuzhiyun */
2268*4882a593Smuzhiyun if (inta_hw & MSIX_HW_INT_CAUSES_REG_WAKEUP && trans_pcie->prph_info) {
2269*4882a593Smuzhiyun u32 sleep_notif =
2270*4882a593Smuzhiyun le32_to_cpu(trans_pcie->prph_info->sleep_notif);
2271*4882a593Smuzhiyun if (sleep_notif == IWL_D3_SLEEP_STATUS_SUSPEND ||
2272*4882a593Smuzhiyun sleep_notif == IWL_D3_SLEEP_STATUS_RESUME) {
2273*4882a593Smuzhiyun IWL_DEBUG_ISR(trans,
2274*4882a593Smuzhiyun "Sx interrupt: sleep notification = 0x%x\n",
2275*4882a593Smuzhiyun sleep_notif);
2276*4882a593Smuzhiyun trans_pcie->sx_complete = true;
2277*4882a593Smuzhiyun wake_up(&trans_pcie->sx_waitq);
2278*4882a593Smuzhiyun } else {
2279*4882a593Smuzhiyun /* uCode wakes up after power-down sleep */
2280*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "Wakeup interrupt\n");
2281*4882a593Smuzhiyun iwl_pcie_rxq_check_wrptr(trans);
2282*4882a593Smuzhiyun iwl_pcie_txq_check_wrptrs(trans);
2283*4882a593Smuzhiyun
2284*4882a593Smuzhiyun isr_stats->wakeup++;
2285*4882a593Smuzhiyun }
2286*4882a593Smuzhiyun }
2287*4882a593Smuzhiyun
2288*4882a593Smuzhiyun if (inta_hw & MSIX_HW_INT_CAUSES_REG_IML) {
2289*4882a593Smuzhiyun /* Reflect IML transfer status */
2290*4882a593Smuzhiyun int res = iwl_read32(trans, CSR_IML_RESP_ADDR);
2291*4882a593Smuzhiyun
2292*4882a593Smuzhiyun IWL_DEBUG_ISR(trans, "IML transfer status: %d\n", res);
2293*4882a593Smuzhiyun if (res == IWL_IMAGE_RESP_FAIL) {
2294*4882a593Smuzhiyun isr_stats->sw++;
2295*4882a593Smuzhiyun iwl_pcie_irq_handle_error(trans);
2296*4882a593Smuzhiyun }
2297*4882a593Smuzhiyun }
2298*4882a593Smuzhiyun
2299*4882a593Smuzhiyun /* Chip got too hot and stopped itself */
2300*4882a593Smuzhiyun if (inta_hw & MSIX_HW_INT_CAUSES_REG_CT_KILL) {
2301*4882a593Smuzhiyun IWL_ERR(trans, "Microcode CT kill error detected.\n");
2302*4882a593Smuzhiyun isr_stats->ctkill++;
2303*4882a593Smuzhiyun }
2304*4882a593Smuzhiyun
2305*4882a593Smuzhiyun /* HW RF KILL switch toggled */
2306*4882a593Smuzhiyun if (inta_hw & MSIX_HW_INT_CAUSES_REG_RF_KILL)
2307*4882a593Smuzhiyun iwl_pcie_handle_rfkill_irq(trans);
2308*4882a593Smuzhiyun
2309*4882a593Smuzhiyun if (inta_hw & MSIX_HW_INT_CAUSES_REG_HW_ERR) {
2310*4882a593Smuzhiyun IWL_ERR(trans,
2311*4882a593Smuzhiyun "Hardware error detected. Restarting.\n");
2312*4882a593Smuzhiyun
2313*4882a593Smuzhiyun isr_stats->hw++;
2314*4882a593Smuzhiyun trans->dbg.hw_error = true;
2315*4882a593Smuzhiyun iwl_pcie_irq_handle_error(trans);
2316*4882a593Smuzhiyun }
2317*4882a593Smuzhiyun
2318*4882a593Smuzhiyun iwl_pcie_clear_irq(trans, entry);
2319*4882a593Smuzhiyun
2320*4882a593Smuzhiyun lock_map_release(&trans->sync_cmd_lockdep_map);
2321*4882a593Smuzhiyun
2322*4882a593Smuzhiyun return IRQ_HANDLED;
2323*4882a593Smuzhiyun }
2324