xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/ath/ath6kl/hif.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2007-2011 Atheros Communications Inc.
3*4882a593Smuzhiyun  * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Permission to use, copy, modify, and/or distribute this software for any
6*4882a593Smuzhiyun  * purpose with or without fee is hereby granted, provided that the above
7*4882a593Smuzhiyun  * copyright notice and this permission notice appear in all copies.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*4882a593Smuzhiyun  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*4882a593Smuzhiyun  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*4882a593Smuzhiyun  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*4882a593Smuzhiyun  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*4882a593Smuzhiyun  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*4882a593Smuzhiyun  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun #include "hif.h"
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include <linux/export.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #include "core.h"
22*4882a593Smuzhiyun #include "target.h"
23*4882a593Smuzhiyun #include "hif-ops.h"
24*4882a593Smuzhiyun #include "debug.h"
25*4882a593Smuzhiyun #include "trace.h"
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #define MAILBOX_FOR_BLOCK_SIZE          1
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #define ATH6KL_TIME_QUANTUM	10  /* in ms */
30*4882a593Smuzhiyun 
ath6kl_hif_cp_scat_dma_buf(struct hif_scatter_req * req,bool from_dma)31*4882a593Smuzhiyun static int ath6kl_hif_cp_scat_dma_buf(struct hif_scatter_req *req,
32*4882a593Smuzhiyun 				      bool from_dma)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun 	u8 *buf;
35*4882a593Smuzhiyun 	int i;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	buf = req->virt_dma_buf;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun 	for (i = 0; i < req->scat_entries; i++) {
40*4882a593Smuzhiyun 		if (from_dma)
41*4882a593Smuzhiyun 			memcpy(req->scat_list[i].buf, buf,
42*4882a593Smuzhiyun 			       req->scat_list[i].len);
43*4882a593Smuzhiyun 		else
44*4882a593Smuzhiyun 			memcpy(buf, req->scat_list[i].buf,
45*4882a593Smuzhiyun 			       req->scat_list[i].len);
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun 		buf += req->scat_list[i].len;
48*4882a593Smuzhiyun 	}
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	return 0;
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
ath6kl_hif_rw_comp_handler(void * context,int status)53*4882a593Smuzhiyun int ath6kl_hif_rw_comp_handler(void *context, int status)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun 	struct htc_packet *packet = context;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_HIF, "hif rw completion pkt 0x%p status %d\n",
58*4882a593Smuzhiyun 		   packet, status);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun 	packet->status = status;
61*4882a593Smuzhiyun 	packet->completion(packet->context, packet);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	return 0;
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun EXPORT_SYMBOL(ath6kl_hif_rw_comp_handler);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #define REGISTER_DUMP_COUNT     60
68*4882a593Smuzhiyun #define REGISTER_DUMP_LEN_MAX   60
69*4882a593Smuzhiyun 
ath6kl_hif_dump_fw_crash(struct ath6kl * ar)70*4882a593Smuzhiyun static void ath6kl_hif_dump_fw_crash(struct ath6kl *ar)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun 	__le32 regdump_val[REGISTER_DUMP_LEN_MAX];
73*4882a593Smuzhiyun 	u32 i, address, regdump_addr = 0;
74*4882a593Smuzhiyun 	int ret;
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	/* the reg dump pointer is copied to the host interest area */
77*4882a593Smuzhiyun 	address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_failure_state));
78*4882a593Smuzhiyun 	address = TARG_VTOP(ar->target_type, address);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	/* read RAM location through diagnostic window */
81*4882a593Smuzhiyun 	ret = ath6kl_diag_read32(ar, address, &regdump_addr);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	if (ret || !regdump_addr) {
84*4882a593Smuzhiyun 		ath6kl_warn("failed to get ptr to register dump area: %d\n",
85*4882a593Smuzhiyun 			    ret);
86*4882a593Smuzhiyun 		return;
87*4882a593Smuzhiyun 	}
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ, "register dump data address 0x%x\n",
90*4882a593Smuzhiyun 		   regdump_addr);
91*4882a593Smuzhiyun 	regdump_addr = TARG_VTOP(ar->target_type, regdump_addr);
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	/* fetch register dump data */
94*4882a593Smuzhiyun 	ret = ath6kl_diag_read(ar, regdump_addr, (u8 *)&regdump_val[0],
95*4882a593Smuzhiyun 				  REGISTER_DUMP_COUNT * (sizeof(u32)));
96*4882a593Smuzhiyun 	if (ret) {
97*4882a593Smuzhiyun 		ath6kl_warn("failed to get register dump: %d\n", ret);
98*4882a593Smuzhiyun 		return;
99*4882a593Smuzhiyun 	}
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	ath6kl_info("crash dump:\n");
102*4882a593Smuzhiyun 	ath6kl_info("hw 0x%x fw %s\n", ar->wiphy->hw_version,
103*4882a593Smuzhiyun 		    ar->wiphy->fw_version);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 	BUILD_BUG_ON(REGISTER_DUMP_COUNT % 4);
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	for (i = 0; i < REGISTER_DUMP_COUNT; i += 4) {
108*4882a593Smuzhiyun 		ath6kl_info("%d: 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x\n",
109*4882a593Smuzhiyun 			    i,
110*4882a593Smuzhiyun 			    le32_to_cpu(regdump_val[i]),
111*4882a593Smuzhiyun 			    le32_to_cpu(regdump_val[i + 1]),
112*4882a593Smuzhiyun 			    le32_to_cpu(regdump_val[i + 2]),
113*4882a593Smuzhiyun 			    le32_to_cpu(regdump_val[i + 3]));
114*4882a593Smuzhiyun 	}
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun 
ath6kl_hif_proc_dbg_intr(struct ath6kl_device * dev)117*4882a593Smuzhiyun static int ath6kl_hif_proc_dbg_intr(struct ath6kl_device *dev)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun 	u32 dummy;
120*4882a593Smuzhiyun 	int ret;
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	ath6kl_warn("firmware crashed\n");
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	/*
125*4882a593Smuzhiyun 	 * read counter to clear the interrupt, the debug error interrupt is
126*4882a593Smuzhiyun 	 * counter 0.
127*4882a593Smuzhiyun 	 */
128*4882a593Smuzhiyun 	ret = hif_read_write_sync(dev->ar, COUNT_DEC_ADDRESS,
129*4882a593Smuzhiyun 				     (u8 *)&dummy, 4, HIF_RD_SYNC_BYTE_INC);
130*4882a593Smuzhiyun 	if (ret)
131*4882a593Smuzhiyun 		ath6kl_warn("Failed to clear debug interrupt: %d\n", ret);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	ath6kl_hif_dump_fw_crash(dev->ar);
134*4882a593Smuzhiyun 	ath6kl_read_fwlogs(dev->ar);
135*4882a593Smuzhiyun 	ath6kl_recovery_err_notify(dev->ar, ATH6KL_FW_ASSERT);
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	return ret;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun /* mailbox recv message polling */
ath6kl_hif_poll_mboxmsg_rx(struct ath6kl_device * dev,u32 * lk_ahd,int timeout)141*4882a593Smuzhiyun int ath6kl_hif_poll_mboxmsg_rx(struct ath6kl_device *dev, u32 *lk_ahd,
142*4882a593Smuzhiyun 			      int timeout)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun 	struct ath6kl_irq_proc_registers *rg;
145*4882a593Smuzhiyun 	int status = 0, i;
146*4882a593Smuzhiyun 	u8 htc_mbox = 1 << HTC_MAILBOX;
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	for (i = timeout / ATH6KL_TIME_QUANTUM; i > 0; i--) {
149*4882a593Smuzhiyun 		/* this is the standard HIF way, load the reg table */
150*4882a593Smuzhiyun 		status = hif_read_write_sync(dev->ar, HOST_INT_STATUS_ADDRESS,
151*4882a593Smuzhiyun 					     (u8 *) &dev->irq_proc_reg,
152*4882a593Smuzhiyun 					     sizeof(dev->irq_proc_reg),
153*4882a593Smuzhiyun 					     HIF_RD_SYNC_BYTE_INC);
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 		if (status) {
156*4882a593Smuzhiyun 			ath6kl_err("failed to read reg table\n");
157*4882a593Smuzhiyun 			return status;
158*4882a593Smuzhiyun 		}
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 		/* check for MBOX data and valid lookahead */
161*4882a593Smuzhiyun 		if (dev->irq_proc_reg.host_int_status & htc_mbox) {
162*4882a593Smuzhiyun 			if (dev->irq_proc_reg.rx_lkahd_valid &
163*4882a593Smuzhiyun 			    htc_mbox) {
164*4882a593Smuzhiyun 				/*
165*4882a593Smuzhiyun 				 * Mailbox has a message and the look ahead
166*4882a593Smuzhiyun 				 * is valid.
167*4882a593Smuzhiyun 				 */
168*4882a593Smuzhiyun 				rg = &dev->irq_proc_reg;
169*4882a593Smuzhiyun 				*lk_ahd =
170*4882a593Smuzhiyun 					le32_to_cpu(rg->rx_lkahd[HTC_MAILBOX]);
171*4882a593Smuzhiyun 				break;
172*4882a593Smuzhiyun 			}
173*4882a593Smuzhiyun 		}
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 		/* delay a little  */
176*4882a593Smuzhiyun 		mdelay(ATH6KL_TIME_QUANTUM);
177*4882a593Smuzhiyun 		ath6kl_dbg(ATH6KL_DBG_HIF, "hif retry mbox poll try %d\n", i);
178*4882a593Smuzhiyun 	}
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun 	if (i == 0) {
181*4882a593Smuzhiyun 		ath6kl_err("timeout waiting for recv message\n");
182*4882a593Smuzhiyun 		status = -ETIME;
183*4882a593Smuzhiyun 		/* check if the target asserted */
184*4882a593Smuzhiyun 		if (dev->irq_proc_reg.counter_int_status &
185*4882a593Smuzhiyun 		    ATH6KL_TARGET_DEBUG_INTR_MASK)
186*4882a593Smuzhiyun 			/*
187*4882a593Smuzhiyun 			 * Target failure handler will be called in case of
188*4882a593Smuzhiyun 			 * an assert.
189*4882a593Smuzhiyun 			 */
190*4882a593Smuzhiyun 			ath6kl_hif_proc_dbg_intr(dev);
191*4882a593Smuzhiyun 	}
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun 	return status;
194*4882a593Smuzhiyun }
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun /*
197*4882a593Smuzhiyun  * Disable packet reception (used in case the host runs out of buffers)
198*4882a593Smuzhiyun  * using the interrupt enable registers through the host I/F
199*4882a593Smuzhiyun  */
ath6kl_hif_rx_control(struct ath6kl_device * dev,bool enable_rx)200*4882a593Smuzhiyun int ath6kl_hif_rx_control(struct ath6kl_device *dev, bool enable_rx)
201*4882a593Smuzhiyun {
202*4882a593Smuzhiyun 	struct ath6kl_irq_enable_reg regs;
203*4882a593Smuzhiyun 	int status = 0;
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_HIF, "hif rx %s\n",
206*4882a593Smuzhiyun 		   enable_rx ? "enable" : "disable");
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	/* take the lock to protect interrupt enable shadows */
209*4882a593Smuzhiyun 	spin_lock_bh(&dev->lock);
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun 	if (enable_rx)
212*4882a593Smuzhiyun 		dev->irq_en_reg.int_status_en |=
213*4882a593Smuzhiyun 			SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
214*4882a593Smuzhiyun 	else
215*4882a593Smuzhiyun 		dev->irq_en_reg.int_status_en &=
216*4882a593Smuzhiyun 		    ~SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun 	memcpy(&regs, &dev->irq_en_reg, sizeof(regs));
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun 	spin_unlock_bh(&dev->lock);
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	status = hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
223*4882a593Smuzhiyun 				     &regs.int_status_en,
224*4882a593Smuzhiyun 				     sizeof(struct ath6kl_irq_enable_reg),
225*4882a593Smuzhiyun 				     HIF_WR_SYNC_BYTE_INC);
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun 	return status;
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun 
ath6kl_hif_submit_scat_req(struct ath6kl_device * dev,struct hif_scatter_req * scat_req,bool read)230*4882a593Smuzhiyun int ath6kl_hif_submit_scat_req(struct ath6kl_device *dev,
231*4882a593Smuzhiyun 			      struct hif_scatter_req *scat_req, bool read)
232*4882a593Smuzhiyun {
233*4882a593Smuzhiyun 	int status = 0;
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	if (read) {
236*4882a593Smuzhiyun 		scat_req->req = HIF_RD_SYNC_BLOCK_FIX;
237*4882a593Smuzhiyun 		scat_req->addr = dev->ar->mbox_info.htc_addr;
238*4882a593Smuzhiyun 	} else {
239*4882a593Smuzhiyun 		scat_req->req = HIF_WR_ASYNC_BLOCK_INC;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 		scat_req->addr =
242*4882a593Smuzhiyun 			(scat_req->len > HIF_MBOX_WIDTH) ?
243*4882a593Smuzhiyun 			dev->ar->mbox_info.htc_ext_addr :
244*4882a593Smuzhiyun 			dev->ar->mbox_info.htc_addr;
245*4882a593Smuzhiyun 	}
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_HIF,
248*4882a593Smuzhiyun 		   "hif submit scatter request entries %d len %d mbox 0x%x %s %s\n",
249*4882a593Smuzhiyun 		   scat_req->scat_entries, scat_req->len,
250*4882a593Smuzhiyun 		   scat_req->addr, !read ? "async" : "sync",
251*4882a593Smuzhiyun 		   (read) ? "rd" : "wr");
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 	if (!read && scat_req->virt_scat) {
254*4882a593Smuzhiyun 		status = ath6kl_hif_cp_scat_dma_buf(scat_req, false);
255*4882a593Smuzhiyun 		if (status) {
256*4882a593Smuzhiyun 			scat_req->status = status;
257*4882a593Smuzhiyun 			scat_req->complete(dev->ar->htc_target, scat_req);
258*4882a593Smuzhiyun 			return 0;
259*4882a593Smuzhiyun 		}
260*4882a593Smuzhiyun 	}
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun 	status = ath6kl_hif_scat_req_rw(dev->ar, scat_req);
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun 	if (read) {
265*4882a593Smuzhiyun 		/* in sync mode, we can touch the scatter request */
266*4882a593Smuzhiyun 		scat_req->status = status;
267*4882a593Smuzhiyun 		if (!status && scat_req->virt_scat)
268*4882a593Smuzhiyun 			scat_req->status =
269*4882a593Smuzhiyun 				ath6kl_hif_cp_scat_dma_buf(scat_req, true);
270*4882a593Smuzhiyun 	}
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun 	return status;
273*4882a593Smuzhiyun }
274*4882a593Smuzhiyun 
ath6kl_hif_proc_counter_intr(struct ath6kl_device * dev)275*4882a593Smuzhiyun static int ath6kl_hif_proc_counter_intr(struct ath6kl_device *dev)
276*4882a593Smuzhiyun {
277*4882a593Smuzhiyun 	u8 counter_int_status;
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ, "counter interrupt\n");
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun 	counter_int_status = dev->irq_proc_reg.counter_int_status &
282*4882a593Smuzhiyun 			     dev->irq_en_reg.cntr_int_status_en;
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ,
285*4882a593Smuzhiyun 		   "valid interrupt source(s) in COUNTER_INT_STATUS: 0x%x\n",
286*4882a593Smuzhiyun 		counter_int_status);
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun 	/*
289*4882a593Smuzhiyun 	 * NOTE: other modules like GMBOX may use the counter interrupt for
290*4882a593Smuzhiyun 	 * credit flow control on other counters, we only need to check for
291*4882a593Smuzhiyun 	 * the debug assertion counter interrupt.
292*4882a593Smuzhiyun 	 */
293*4882a593Smuzhiyun 	if (counter_int_status & ATH6KL_TARGET_DEBUG_INTR_MASK)
294*4882a593Smuzhiyun 		return ath6kl_hif_proc_dbg_intr(dev);
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun 	return 0;
297*4882a593Smuzhiyun }
298*4882a593Smuzhiyun 
ath6kl_hif_proc_err_intr(struct ath6kl_device * dev)299*4882a593Smuzhiyun static int ath6kl_hif_proc_err_intr(struct ath6kl_device *dev)
300*4882a593Smuzhiyun {
301*4882a593Smuzhiyun 	int status;
302*4882a593Smuzhiyun 	u8 error_int_status;
303*4882a593Smuzhiyun 	u8 reg_buf[4];
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ, "error interrupt\n");
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun 	error_int_status = dev->irq_proc_reg.error_int_status & 0x0F;
308*4882a593Smuzhiyun 	if (!error_int_status) {
309*4882a593Smuzhiyun 		WARN_ON(1);
310*4882a593Smuzhiyun 		return -EIO;
311*4882a593Smuzhiyun 	}
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ,
314*4882a593Smuzhiyun 		   "valid interrupt source(s) in ERROR_INT_STATUS: 0x%x\n",
315*4882a593Smuzhiyun 		   error_int_status);
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun 	if (MS(ERROR_INT_STATUS_WAKEUP, error_int_status))
318*4882a593Smuzhiyun 		ath6kl_dbg(ATH6KL_DBG_IRQ, "error : wakeup\n");
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun 	if (MS(ERROR_INT_STATUS_RX_UNDERFLOW, error_int_status))
321*4882a593Smuzhiyun 		ath6kl_err("rx underflow\n");
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun 	if (MS(ERROR_INT_STATUS_TX_OVERFLOW, error_int_status))
324*4882a593Smuzhiyun 		ath6kl_err("tx overflow\n");
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun 	/* Clear the interrupt */
327*4882a593Smuzhiyun 	dev->irq_proc_reg.error_int_status &= ~error_int_status;
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun 	/* set W1C value to clear the interrupt, this hits the register first */
330*4882a593Smuzhiyun 	reg_buf[0] = error_int_status;
331*4882a593Smuzhiyun 	reg_buf[1] = 0;
332*4882a593Smuzhiyun 	reg_buf[2] = 0;
333*4882a593Smuzhiyun 	reg_buf[3] = 0;
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun 	status = hif_read_write_sync(dev->ar, ERROR_INT_STATUS_ADDRESS,
336*4882a593Smuzhiyun 				     reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun 	WARN_ON(status);
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun 	return status;
341*4882a593Smuzhiyun }
342*4882a593Smuzhiyun 
ath6kl_hif_proc_cpu_intr(struct ath6kl_device * dev)343*4882a593Smuzhiyun static int ath6kl_hif_proc_cpu_intr(struct ath6kl_device *dev)
344*4882a593Smuzhiyun {
345*4882a593Smuzhiyun 	int status;
346*4882a593Smuzhiyun 	u8 cpu_int_status;
347*4882a593Smuzhiyun 	u8 reg_buf[4];
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ, "cpu interrupt\n");
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	cpu_int_status = dev->irq_proc_reg.cpu_int_status &
352*4882a593Smuzhiyun 			 dev->irq_en_reg.cpu_int_status_en;
353*4882a593Smuzhiyun 	if (!cpu_int_status) {
354*4882a593Smuzhiyun 		WARN_ON(1);
355*4882a593Smuzhiyun 		return -EIO;
356*4882a593Smuzhiyun 	}
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ,
359*4882a593Smuzhiyun 		   "valid interrupt source(s) in CPU_INT_STATUS: 0x%x\n",
360*4882a593Smuzhiyun 		cpu_int_status);
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun 	/* Clear the interrupt */
363*4882a593Smuzhiyun 	dev->irq_proc_reg.cpu_int_status &= ~cpu_int_status;
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun 	/*
366*4882a593Smuzhiyun 	 * Set up the register transfer buffer to hit the register 4 times ,
367*4882a593Smuzhiyun 	 * this is done to make the access 4-byte aligned to mitigate issues
368*4882a593Smuzhiyun 	 * with host bus interconnects that restrict bus transfer lengths to
369*4882a593Smuzhiyun 	 * be a multiple of 4-bytes.
370*4882a593Smuzhiyun 	 */
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun 	/* set W1C value to clear the interrupt, this hits the register first */
373*4882a593Smuzhiyun 	reg_buf[0] = cpu_int_status;
374*4882a593Smuzhiyun 	/* the remaining are set to zero which have no-effect  */
375*4882a593Smuzhiyun 	reg_buf[1] = 0;
376*4882a593Smuzhiyun 	reg_buf[2] = 0;
377*4882a593Smuzhiyun 	reg_buf[3] = 0;
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun 	status = hif_read_write_sync(dev->ar, CPU_INT_STATUS_ADDRESS,
380*4882a593Smuzhiyun 				     reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun 	WARN_ON(status);
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun 	return status;
385*4882a593Smuzhiyun }
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun /* process pending interrupts synchronously */
proc_pending_irqs(struct ath6kl_device * dev,bool * done)388*4882a593Smuzhiyun static int proc_pending_irqs(struct ath6kl_device *dev, bool *done)
389*4882a593Smuzhiyun {
390*4882a593Smuzhiyun 	struct ath6kl_irq_proc_registers *rg;
391*4882a593Smuzhiyun 	int status = 0;
392*4882a593Smuzhiyun 	u8 host_int_status = 0;
393*4882a593Smuzhiyun 	u32 lk_ahd = 0;
394*4882a593Smuzhiyun 	u8 htc_mbox = 1 << HTC_MAILBOX;
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ, "proc_pending_irqs: (dev: 0x%p)\n", dev);
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun 	/*
399*4882a593Smuzhiyun 	 * NOTE: HIF implementation guarantees that the context of this
400*4882a593Smuzhiyun 	 * call allows us to perform SYNCHRONOUS I/O, that is we can block,
401*4882a593Smuzhiyun 	 * sleep or call any API that can block or switch thread/task
402*4882a593Smuzhiyun 	 * contexts. This is a fully schedulable context.
403*4882a593Smuzhiyun 	 */
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun 	/*
406*4882a593Smuzhiyun 	 * Process pending intr only when int_status_en is clear, it may
407*4882a593Smuzhiyun 	 * result in unnecessary bus transaction otherwise. Target may be
408*4882a593Smuzhiyun 	 * unresponsive at the time.
409*4882a593Smuzhiyun 	 */
410*4882a593Smuzhiyun 	if (dev->irq_en_reg.int_status_en) {
411*4882a593Smuzhiyun 		/*
412*4882a593Smuzhiyun 		 * Read the first 28 bytes of the HTC register table. This
413*4882a593Smuzhiyun 		 * will yield us the value of different int status
414*4882a593Smuzhiyun 		 * registers and the lookahead registers.
415*4882a593Smuzhiyun 		 *
416*4882a593Smuzhiyun 		 *    length = sizeof(int_status) + sizeof(cpu_int_status)
417*4882a593Smuzhiyun 		 *             + sizeof(error_int_status) +
418*4882a593Smuzhiyun 		 *             sizeof(counter_int_status) +
419*4882a593Smuzhiyun 		 *             sizeof(mbox_frame) + sizeof(rx_lkahd_valid)
420*4882a593Smuzhiyun 		 *             + sizeof(hole) + sizeof(rx_lkahd) +
421*4882a593Smuzhiyun 		 *             sizeof(int_status_en) +
422*4882a593Smuzhiyun 		 *             sizeof(cpu_int_status_en) +
423*4882a593Smuzhiyun 		 *             sizeof(err_int_status_en) +
424*4882a593Smuzhiyun 		 *             sizeof(cntr_int_status_en);
425*4882a593Smuzhiyun 		 */
426*4882a593Smuzhiyun 		status = hif_read_write_sync(dev->ar, HOST_INT_STATUS_ADDRESS,
427*4882a593Smuzhiyun 					     (u8 *) &dev->irq_proc_reg,
428*4882a593Smuzhiyun 					     sizeof(dev->irq_proc_reg),
429*4882a593Smuzhiyun 					     HIF_RD_SYNC_BYTE_INC);
430*4882a593Smuzhiyun 		if (status)
431*4882a593Smuzhiyun 			goto out;
432*4882a593Smuzhiyun 
433*4882a593Smuzhiyun 		ath6kl_dump_registers(dev, &dev->irq_proc_reg,
434*4882a593Smuzhiyun 				      &dev->irq_en_reg);
435*4882a593Smuzhiyun 		trace_ath6kl_sdio_irq(&dev->irq_en_reg,
436*4882a593Smuzhiyun 				      sizeof(dev->irq_en_reg));
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun 		/* Update only those registers that are enabled */
439*4882a593Smuzhiyun 		host_int_status = dev->irq_proc_reg.host_int_status &
440*4882a593Smuzhiyun 				  dev->irq_en_reg.int_status_en;
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun 		/* Look at mbox status */
443*4882a593Smuzhiyun 		if (host_int_status & htc_mbox) {
444*4882a593Smuzhiyun 			/*
445*4882a593Smuzhiyun 			 * Mask out pending mbox value, we use "lookAhead as
446*4882a593Smuzhiyun 			 * the real flag for mbox processing.
447*4882a593Smuzhiyun 			 */
448*4882a593Smuzhiyun 			host_int_status &= ~htc_mbox;
449*4882a593Smuzhiyun 			if (dev->irq_proc_reg.rx_lkahd_valid &
450*4882a593Smuzhiyun 			    htc_mbox) {
451*4882a593Smuzhiyun 				rg = &dev->irq_proc_reg;
452*4882a593Smuzhiyun 				lk_ahd = le32_to_cpu(rg->rx_lkahd[HTC_MAILBOX]);
453*4882a593Smuzhiyun 				if (!lk_ahd)
454*4882a593Smuzhiyun 					ath6kl_err("lookAhead is zero!\n");
455*4882a593Smuzhiyun 			}
456*4882a593Smuzhiyun 		}
457*4882a593Smuzhiyun 	}
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun 	if (!host_int_status && !lk_ahd) {
460*4882a593Smuzhiyun 		*done = true;
461*4882a593Smuzhiyun 		goto out;
462*4882a593Smuzhiyun 	}
463*4882a593Smuzhiyun 
464*4882a593Smuzhiyun 	if (lk_ahd) {
465*4882a593Smuzhiyun 		int fetched = 0;
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun 		ath6kl_dbg(ATH6KL_DBG_IRQ,
468*4882a593Smuzhiyun 			   "pending mailbox msg, lk_ahd: 0x%X\n", lk_ahd);
469*4882a593Smuzhiyun 		/*
470*4882a593Smuzhiyun 		 * Mailbox Interrupt, the HTC layer may issue async
471*4882a593Smuzhiyun 		 * requests to empty the mailbox. When emptying the recv
472*4882a593Smuzhiyun 		 * mailbox we use the async handler above called from the
473*4882a593Smuzhiyun 		 * completion routine of the callers read request. This can
474*4882a593Smuzhiyun 		 * improve performance by reducing context switching when
475*4882a593Smuzhiyun 		 * we rapidly pull packets.
476*4882a593Smuzhiyun 		 */
477*4882a593Smuzhiyun 		status = ath6kl_htc_rxmsg_pending_handler(dev->htc_cnxt,
478*4882a593Smuzhiyun 							  lk_ahd, &fetched);
479*4882a593Smuzhiyun 		if (status)
480*4882a593Smuzhiyun 			goto out;
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun 		if (!fetched)
483*4882a593Smuzhiyun 			/*
484*4882a593Smuzhiyun 			 * HTC could not pull any messages out due to lack
485*4882a593Smuzhiyun 			 * of resources.
486*4882a593Smuzhiyun 			 */
487*4882a593Smuzhiyun 			dev->htc_cnxt->chk_irq_status_cnt = 0;
488*4882a593Smuzhiyun 	}
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun 	/* now handle the rest of them */
491*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ,
492*4882a593Smuzhiyun 		   "valid interrupt source(s) for other interrupts: 0x%x\n",
493*4882a593Smuzhiyun 		   host_int_status);
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun 	if (MS(HOST_INT_STATUS_CPU, host_int_status)) {
496*4882a593Smuzhiyun 		/* CPU Interrupt */
497*4882a593Smuzhiyun 		status = ath6kl_hif_proc_cpu_intr(dev);
498*4882a593Smuzhiyun 		if (status)
499*4882a593Smuzhiyun 			goto out;
500*4882a593Smuzhiyun 	}
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun 	if (MS(HOST_INT_STATUS_ERROR, host_int_status)) {
503*4882a593Smuzhiyun 		/* Error Interrupt */
504*4882a593Smuzhiyun 		status = ath6kl_hif_proc_err_intr(dev);
505*4882a593Smuzhiyun 		if (status)
506*4882a593Smuzhiyun 			goto out;
507*4882a593Smuzhiyun 	}
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun 	if (MS(HOST_INT_STATUS_COUNTER, host_int_status))
510*4882a593Smuzhiyun 		/* Counter Interrupt */
511*4882a593Smuzhiyun 		status = ath6kl_hif_proc_counter_intr(dev);
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun out:
514*4882a593Smuzhiyun 	/*
515*4882a593Smuzhiyun 	 * An optimization to bypass reading the IRQ status registers
516*4882a593Smuzhiyun 	 * unecessarily which can re-wake the target, if upper layers
517*4882a593Smuzhiyun 	 * determine that we are in a low-throughput mode, we can rely on
518*4882a593Smuzhiyun 	 * taking another interrupt rather than re-checking the status
519*4882a593Smuzhiyun 	 * registers which can re-wake the target.
520*4882a593Smuzhiyun 	 *
521*4882a593Smuzhiyun 	 * NOTE : for host interfaces that makes use of detecting pending
522*4882a593Smuzhiyun 	 * mbox messages at hif can not use this optimization due to
523*4882a593Smuzhiyun 	 * possible side effects, SPI requires the host to drain all
524*4882a593Smuzhiyun 	 * messages from the mailbox before exiting the ISR routine.
525*4882a593Smuzhiyun 	 */
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ,
528*4882a593Smuzhiyun 		   "bypassing irq status re-check, forcing done\n");
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun 	if (!dev->htc_cnxt->chk_irq_status_cnt)
531*4882a593Smuzhiyun 		*done = true;
532*4882a593Smuzhiyun 
533*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_IRQ,
534*4882a593Smuzhiyun 		   "proc_pending_irqs: (done:%d, status=%d\n", *done, status);
535*4882a593Smuzhiyun 
536*4882a593Smuzhiyun 	return status;
537*4882a593Smuzhiyun }
538*4882a593Smuzhiyun 
539*4882a593Smuzhiyun /* interrupt handler, kicks off all interrupt processing */
ath6kl_hif_intr_bh_handler(struct ath6kl * ar)540*4882a593Smuzhiyun int ath6kl_hif_intr_bh_handler(struct ath6kl *ar)
541*4882a593Smuzhiyun {
542*4882a593Smuzhiyun 	struct ath6kl_device *dev = ar->htc_target->dev;
543*4882a593Smuzhiyun 	unsigned long timeout;
544*4882a593Smuzhiyun 	int status = 0;
545*4882a593Smuzhiyun 	bool done = false;
546*4882a593Smuzhiyun 
547*4882a593Smuzhiyun 	/*
548*4882a593Smuzhiyun 	 * Reset counter used to flag a re-scan of IRQ status registers on
549*4882a593Smuzhiyun 	 * the target.
550*4882a593Smuzhiyun 	 */
551*4882a593Smuzhiyun 	dev->htc_cnxt->chk_irq_status_cnt = 0;
552*4882a593Smuzhiyun 
553*4882a593Smuzhiyun 	/*
554*4882a593Smuzhiyun 	 * IRQ processing is synchronous, interrupt status registers can be
555*4882a593Smuzhiyun 	 * re-read.
556*4882a593Smuzhiyun 	 */
557*4882a593Smuzhiyun 	timeout = jiffies + msecs_to_jiffies(ATH6KL_HIF_COMMUNICATION_TIMEOUT);
558*4882a593Smuzhiyun 	while (time_before(jiffies, timeout) && !done) {
559*4882a593Smuzhiyun 		status = proc_pending_irqs(dev, &done);
560*4882a593Smuzhiyun 		if (status)
561*4882a593Smuzhiyun 			break;
562*4882a593Smuzhiyun 	}
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun 	return status;
565*4882a593Smuzhiyun }
566*4882a593Smuzhiyun EXPORT_SYMBOL(ath6kl_hif_intr_bh_handler);
567*4882a593Smuzhiyun 
ath6kl_hif_enable_intrs(struct ath6kl_device * dev)568*4882a593Smuzhiyun static int ath6kl_hif_enable_intrs(struct ath6kl_device *dev)
569*4882a593Smuzhiyun {
570*4882a593Smuzhiyun 	struct ath6kl_irq_enable_reg regs;
571*4882a593Smuzhiyun 	int status;
572*4882a593Smuzhiyun 
573*4882a593Smuzhiyun 	spin_lock_bh(&dev->lock);
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun 	/* Enable all but ATH6KL CPU interrupts */
576*4882a593Smuzhiyun 	dev->irq_en_reg.int_status_en =
577*4882a593Smuzhiyun 			SM(INT_STATUS_ENABLE_ERROR, 0x01) |
578*4882a593Smuzhiyun 			SM(INT_STATUS_ENABLE_CPU, 0x01) |
579*4882a593Smuzhiyun 			SM(INT_STATUS_ENABLE_COUNTER, 0x01);
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun 	/*
582*4882a593Smuzhiyun 	 * NOTE: There are some cases where HIF can do detection of
583*4882a593Smuzhiyun 	 * pending mbox messages which is disabled now.
584*4882a593Smuzhiyun 	 */
585*4882a593Smuzhiyun 	dev->irq_en_reg.int_status_en |= SM(INT_STATUS_ENABLE_MBOX_DATA, 0x01);
586*4882a593Smuzhiyun 
587*4882a593Smuzhiyun 	/* Set up the CPU Interrupt status Register */
588*4882a593Smuzhiyun 	dev->irq_en_reg.cpu_int_status_en = 0;
589*4882a593Smuzhiyun 
590*4882a593Smuzhiyun 	/* Set up the Error Interrupt status Register */
591*4882a593Smuzhiyun 	dev->irq_en_reg.err_int_status_en =
592*4882a593Smuzhiyun 		SM(ERROR_STATUS_ENABLE_RX_UNDERFLOW, 0x01) |
593*4882a593Smuzhiyun 		SM(ERROR_STATUS_ENABLE_TX_OVERFLOW, 0x1);
594*4882a593Smuzhiyun 
595*4882a593Smuzhiyun 	/*
596*4882a593Smuzhiyun 	 * Enable Counter interrupt status register to get fatal errors for
597*4882a593Smuzhiyun 	 * debugging.
598*4882a593Smuzhiyun 	 */
599*4882a593Smuzhiyun 	dev->irq_en_reg.cntr_int_status_en = SM(COUNTER_INT_STATUS_ENABLE_BIT,
600*4882a593Smuzhiyun 						ATH6KL_TARGET_DEBUG_INTR_MASK);
601*4882a593Smuzhiyun 	memcpy(&regs, &dev->irq_en_reg, sizeof(regs));
602*4882a593Smuzhiyun 
603*4882a593Smuzhiyun 	spin_unlock_bh(&dev->lock);
604*4882a593Smuzhiyun 
605*4882a593Smuzhiyun 	status = hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
606*4882a593Smuzhiyun 				     &regs.int_status_en, sizeof(regs),
607*4882a593Smuzhiyun 				     HIF_WR_SYNC_BYTE_INC);
608*4882a593Smuzhiyun 
609*4882a593Smuzhiyun 	if (status)
610*4882a593Smuzhiyun 		ath6kl_err("failed to update interrupt ctl reg err: %d\n",
611*4882a593Smuzhiyun 			   status);
612*4882a593Smuzhiyun 
613*4882a593Smuzhiyun 	return status;
614*4882a593Smuzhiyun }
615*4882a593Smuzhiyun 
ath6kl_hif_disable_intrs(struct ath6kl_device * dev)616*4882a593Smuzhiyun int ath6kl_hif_disable_intrs(struct ath6kl_device *dev)
617*4882a593Smuzhiyun {
618*4882a593Smuzhiyun 	struct ath6kl_irq_enable_reg regs;
619*4882a593Smuzhiyun 
620*4882a593Smuzhiyun 	spin_lock_bh(&dev->lock);
621*4882a593Smuzhiyun 	/* Disable all interrupts */
622*4882a593Smuzhiyun 	dev->irq_en_reg.int_status_en = 0;
623*4882a593Smuzhiyun 	dev->irq_en_reg.cpu_int_status_en = 0;
624*4882a593Smuzhiyun 	dev->irq_en_reg.err_int_status_en = 0;
625*4882a593Smuzhiyun 	dev->irq_en_reg.cntr_int_status_en = 0;
626*4882a593Smuzhiyun 	memcpy(&regs, &dev->irq_en_reg, sizeof(regs));
627*4882a593Smuzhiyun 	spin_unlock_bh(&dev->lock);
628*4882a593Smuzhiyun 
629*4882a593Smuzhiyun 	return hif_read_write_sync(dev->ar, INT_STATUS_ENABLE_ADDRESS,
630*4882a593Smuzhiyun 				   &regs.int_status_en, sizeof(regs),
631*4882a593Smuzhiyun 				   HIF_WR_SYNC_BYTE_INC);
632*4882a593Smuzhiyun }
633*4882a593Smuzhiyun 
634*4882a593Smuzhiyun /* enable device interrupts */
ath6kl_hif_unmask_intrs(struct ath6kl_device * dev)635*4882a593Smuzhiyun int ath6kl_hif_unmask_intrs(struct ath6kl_device *dev)
636*4882a593Smuzhiyun {
637*4882a593Smuzhiyun 	int status = 0;
638*4882a593Smuzhiyun 
639*4882a593Smuzhiyun 	/*
640*4882a593Smuzhiyun 	 * Make sure interrupt are disabled before unmasking at the HIF
641*4882a593Smuzhiyun 	 * layer. The rationale here is that between device insertion
642*4882a593Smuzhiyun 	 * (where we clear the interrupts the first time) and when HTC
643*4882a593Smuzhiyun 	 * is finally ready to handle interrupts, other software can perform
644*4882a593Smuzhiyun 	 * target "soft" resets. The ATH6KL interrupt enables reset back to an
645*4882a593Smuzhiyun 	 * "enabled" state when this happens.
646*4882a593Smuzhiyun 	 */
647*4882a593Smuzhiyun 	ath6kl_hif_disable_intrs(dev);
648*4882a593Smuzhiyun 
649*4882a593Smuzhiyun 	/* unmask the host controller interrupts */
650*4882a593Smuzhiyun 	ath6kl_hif_irq_enable(dev->ar);
651*4882a593Smuzhiyun 	status = ath6kl_hif_enable_intrs(dev);
652*4882a593Smuzhiyun 
653*4882a593Smuzhiyun 	return status;
654*4882a593Smuzhiyun }
655*4882a593Smuzhiyun 
656*4882a593Smuzhiyun /* disable all device interrupts */
ath6kl_hif_mask_intrs(struct ath6kl_device * dev)657*4882a593Smuzhiyun int ath6kl_hif_mask_intrs(struct ath6kl_device *dev)
658*4882a593Smuzhiyun {
659*4882a593Smuzhiyun 	/*
660*4882a593Smuzhiyun 	 * Mask the interrupt at the HIF layer to avoid any stray interrupt
661*4882a593Smuzhiyun 	 * taken while we zero out our shadow registers in
662*4882a593Smuzhiyun 	 * ath6kl_hif_disable_intrs().
663*4882a593Smuzhiyun 	 */
664*4882a593Smuzhiyun 	ath6kl_hif_irq_disable(dev->ar);
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun 	return ath6kl_hif_disable_intrs(dev);
667*4882a593Smuzhiyun }
668*4882a593Smuzhiyun 
ath6kl_hif_setup(struct ath6kl_device * dev)669*4882a593Smuzhiyun int ath6kl_hif_setup(struct ath6kl_device *dev)
670*4882a593Smuzhiyun {
671*4882a593Smuzhiyun 	int status = 0;
672*4882a593Smuzhiyun 
673*4882a593Smuzhiyun 	spin_lock_init(&dev->lock);
674*4882a593Smuzhiyun 
675*4882a593Smuzhiyun 	/*
676*4882a593Smuzhiyun 	 * NOTE: we actually get the block size of a mailbox other than 0,
677*4882a593Smuzhiyun 	 * for SDIO the block size on mailbox 0 is artificially set to 1.
678*4882a593Smuzhiyun 	 * So we use the block size that is set for the other 3 mailboxes.
679*4882a593Smuzhiyun 	 */
680*4882a593Smuzhiyun 	dev->htc_cnxt->block_sz = dev->ar->mbox_info.block_size;
681*4882a593Smuzhiyun 
682*4882a593Smuzhiyun 	/* must be a power of 2 */
683*4882a593Smuzhiyun 	if ((dev->htc_cnxt->block_sz & (dev->htc_cnxt->block_sz - 1)) != 0) {
684*4882a593Smuzhiyun 		WARN_ON(1);
685*4882a593Smuzhiyun 		status = -EINVAL;
686*4882a593Smuzhiyun 		goto fail_setup;
687*4882a593Smuzhiyun 	}
688*4882a593Smuzhiyun 
689*4882a593Smuzhiyun 	/* assemble mask, used for padding to a block */
690*4882a593Smuzhiyun 	dev->htc_cnxt->block_mask = dev->htc_cnxt->block_sz - 1;
691*4882a593Smuzhiyun 
692*4882a593Smuzhiyun 	ath6kl_dbg(ATH6KL_DBG_HIF, "hif block size %d mbox addr 0x%x\n",
693*4882a593Smuzhiyun 		   dev->htc_cnxt->block_sz, dev->ar->mbox_info.htc_addr);
694*4882a593Smuzhiyun 
695*4882a593Smuzhiyun 	status = ath6kl_hif_disable_intrs(dev);
696*4882a593Smuzhiyun 
697*4882a593Smuzhiyun fail_setup:
698*4882a593Smuzhiyun 	return status;
699*4882a593Smuzhiyun }
700