Loading...
1/*
2 * Copyright (c) 2014 Redpine Signals Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 *
16 */
17
18#include <linux/firmware.h>
19#include <net/rsi_91x.h>
20#include "rsi_sdio.h"
21#include "rsi_common.h"
22
23/**
24 * rsi_sdio_master_access_msword() - This function sets the AHB master access
25 * MS word in the SDIO slave registers.
26 * @adapter: Pointer to the adapter structure.
27 * @ms_word: ms word need to be initialized.
28 *
29 * Return: status: 0 on success, -1 on failure.
30 */
31int rsi_sdio_master_access_msword(struct rsi_hw *adapter, u16 ms_word)
32{
33 u8 byte;
34 u8 function = 0;
35 int status = 0;
36
37 byte = (u8)(ms_word & 0x00FF);
38
39 rsi_dbg(INIT_ZONE,
40 "%s: MASTER_ACCESS_MSBYTE:0x%x\n", __func__, byte);
41
42 status = rsi_sdio_write_register(adapter,
43 function,
44 SDIO_MASTER_ACCESS_MSBYTE,
45 &byte);
46 if (status) {
47 rsi_dbg(ERR_ZONE,
48 "%s: fail to access MASTER_ACCESS_MSBYTE\n",
49 __func__);
50 return -1;
51 }
52
53 byte = (u8)(ms_word >> 8);
54
55 rsi_dbg(INIT_ZONE, "%s:MASTER_ACCESS_LSBYTE:0x%x\n", __func__, byte);
56 status = rsi_sdio_write_register(adapter,
57 function,
58 SDIO_MASTER_ACCESS_LSBYTE,
59 &byte);
60 return status;
61}
62
63static void rsi_rx_handler(struct rsi_hw *adapter);
64
65void rsi_sdio_rx_thread(struct rsi_common *common)
66{
67 struct rsi_hw *adapter = common->priv;
68 struct rsi_91x_sdiodev *sdev = adapter->rsi_dev;
69
70 do {
71 rsi_wait_event(&sdev->rx_thread.event, EVENT_WAIT_FOREVER);
72 rsi_reset_event(&sdev->rx_thread.event);
73 rsi_rx_handler(adapter);
74 } while (!atomic_read(&sdev->rx_thread.thread_done));
75
76 rsi_dbg(INFO_ZONE, "%s: Terminated SDIO RX thread\n", __func__);
77 atomic_inc(&sdev->rx_thread.thread_done);
78 kthread_complete_and_exit(&sdev->rx_thread.completion, 0);
79}
80
81/**
82 * rsi_process_pkt() - This Function reads rx_blocks register and figures out
83 * the size of the rx pkt.
84 * @common: Pointer to the driver private structure.
85 *
86 * Return: 0 on success, -1 on failure.
87 */
88static int rsi_process_pkt(struct rsi_common *common)
89{
90 struct rsi_hw *adapter = common->priv;
91 struct rsi_91x_sdiodev *dev = adapter->rsi_dev;
92 u8 num_blks = 0;
93 u32 rcv_pkt_len = 0;
94 int status = 0;
95 u8 value = 0;
96
97 num_blks = ((adapter->interrupt_status & 1) |
98 ((adapter->interrupt_status >> RECV_NUM_BLOCKS) << 1));
99
100 if (!num_blks) {
101 status = rsi_sdio_read_register(adapter,
102 SDIO_RX_NUM_BLOCKS_REG,
103 &value);
104 if (status) {
105 rsi_dbg(ERR_ZONE,
106 "%s: Failed to read pkt length from the card:\n",
107 __func__);
108 return status;
109 }
110 num_blks = value & 0x1f;
111 }
112
113 if (dev->write_fail == 2)
114 rsi_sdio_ack_intr(common->priv, (1 << MSDU_PKT_PENDING));
115
116 if (unlikely(!num_blks)) {
117 dev->write_fail = 2;
118 return -1;
119 }
120
121 rcv_pkt_len = (num_blks * 256);
122
123 status = rsi_sdio_host_intf_read_pkt(adapter, dev->pktbuffer,
124 rcv_pkt_len);
125 if (status) {
126 rsi_dbg(ERR_ZONE, "%s: Failed to read packet from card\n",
127 __func__);
128 return status;
129 }
130
131 status = rsi_read_pkt(common, dev->pktbuffer, rcv_pkt_len);
132 if (status) {
133 rsi_dbg(ERR_ZONE, "Failed to read the packet\n");
134 return status;
135 }
136
137 return 0;
138}
139
140/**
141 * rsi_init_sdio_slave_regs() - This function does the actual initialization
142 * of SDBUS slave registers.
143 * @adapter: Pointer to the adapter structure.
144 *
145 * Return: status: 0 on success, -1 on failure.
146 */
147int rsi_init_sdio_slave_regs(struct rsi_hw *adapter)
148{
149 struct rsi_91x_sdiodev *dev = adapter->rsi_dev;
150 u8 function = 0;
151 u8 byte;
152 int status = 0;
153
154 if (dev->next_read_delay) {
155 byte = dev->next_read_delay;
156 status = rsi_sdio_write_register(adapter,
157 function,
158 SDIO_NXT_RD_DELAY2,
159 &byte);
160 if (status) {
161 rsi_dbg(ERR_ZONE,
162 "%s: Failed to write SDIO_NXT_RD_DELAY2\n",
163 __func__);
164 return -1;
165 }
166 }
167
168 if (dev->sdio_high_speed_enable) {
169 rsi_dbg(INIT_ZONE, "%s: Enabling SDIO High speed\n", __func__);
170 byte = 0x3;
171
172 status = rsi_sdio_write_register(adapter,
173 function,
174 SDIO_REG_HIGH_SPEED,
175 &byte);
176 if (status) {
177 rsi_dbg(ERR_ZONE,
178 "%s: Failed to enable SDIO high speed\n",
179 __func__);
180 return -1;
181 }
182 }
183
184 /* This tells SDIO FIFO when to start read to host */
185 rsi_dbg(INIT_ZONE, "%s: Initializing SDIO read start level\n", __func__);
186 byte = 0x24;
187
188 status = rsi_sdio_write_register(adapter,
189 function,
190 SDIO_READ_START_LVL,
191 &byte);
192 if (status) {
193 rsi_dbg(ERR_ZONE,
194 "%s: Failed to write SDIO_READ_START_LVL\n", __func__);
195 return -1;
196 }
197
198 rsi_dbg(INIT_ZONE, "%s: Initializing FIFO ctrl registers\n", __func__);
199 byte = (128 - 32);
200
201 status = rsi_sdio_write_register(adapter,
202 function,
203 SDIO_READ_FIFO_CTL,
204 &byte);
205 if (status) {
206 rsi_dbg(ERR_ZONE,
207 "%s: Failed to write SDIO_READ_FIFO_CTL\n", __func__);
208 return -1;
209 }
210
211 byte = 32;
212 status = rsi_sdio_write_register(adapter,
213 function,
214 SDIO_WRITE_FIFO_CTL,
215 &byte);
216 if (status) {
217 rsi_dbg(ERR_ZONE,
218 "%s: Failed to write SDIO_WRITE_FIFO_CTL\n", __func__);
219 return -1;
220 }
221
222 return 0;
223}
224
225/**
226 * rsi_rx_handler() - Read and process SDIO interrupts.
227 * @adapter: Pointer to the adapter structure.
228 *
229 * Return: None.
230 */
231static void rsi_rx_handler(struct rsi_hw *adapter)
232{
233 struct rsi_common *common = adapter->priv;
234 struct rsi_91x_sdiodev *dev = adapter->rsi_dev;
235 int status;
236 u8 isr_status = 0;
237 u8 fw_status = 0;
238
239 dev->rx_info.sdio_int_counter++;
240
241 do {
242 mutex_lock(&common->rx_lock);
243 status = rsi_sdio_read_register(common->priv,
244 RSI_FN1_INT_REGISTER,
245 &isr_status);
246 if (status) {
247 rsi_dbg(ERR_ZONE,
248 "%s: Failed to Read Intr Status Register\n",
249 __func__);
250 mutex_unlock(&common->rx_lock);
251 return;
252 }
253 adapter->interrupt_status = isr_status;
254
255 if (isr_status == 0) {
256 rsi_set_event(&common->tx_thread.event);
257 dev->rx_info.sdio_intr_status_zero++;
258 mutex_unlock(&common->rx_lock);
259 return;
260 }
261
262 rsi_dbg(ISR_ZONE, "%s: Intr_status = %x %d %d\n",
263 __func__, isr_status, (1 << MSDU_PKT_PENDING),
264 (1 << FW_ASSERT_IND));
265
266 if (isr_status & BIT(PKT_BUFF_AVAILABLE)) {
267 status = rsi_sdio_check_buffer_status(adapter, 0);
268 if (status < 0)
269 rsi_dbg(ERR_ZONE,
270 "%s: Failed to check buffer status\n",
271 __func__);
272 rsi_sdio_ack_intr(common->priv,
273 BIT(PKT_BUFF_AVAILABLE));
274 rsi_set_event(&common->tx_thread.event);
275
276 rsi_dbg(ISR_ZONE, "%s: ==> BUFFER_AVAILABLE <==\n",
277 __func__);
278 dev->buff_status_updated = true;
279
280 isr_status &= ~BIT(PKT_BUFF_AVAILABLE);
281 }
282
283 if (isr_status & BIT(FW_ASSERT_IND)) {
284 rsi_dbg(ERR_ZONE, "%s: ==> FIRMWARE Assert <==\n",
285 __func__);
286 status = rsi_sdio_read_register(common->priv,
287 SDIO_FW_STATUS_REG,
288 &fw_status);
289 if (status) {
290 rsi_dbg(ERR_ZONE,
291 "%s: Failed to read f/w reg\n",
292 __func__);
293 } else {
294 rsi_dbg(ERR_ZONE,
295 "%s: Firmware Status is 0x%x\n",
296 __func__, fw_status);
297 rsi_sdio_ack_intr(common->priv,
298 BIT(FW_ASSERT_IND));
299 }
300
301 common->fsm_state = FSM_CARD_NOT_READY;
302
303 isr_status &= ~BIT(FW_ASSERT_IND);
304 }
305
306 if (isr_status & BIT(MSDU_PKT_PENDING)) {
307 rsi_dbg(ISR_ZONE, "Pkt pending interrupt\n");
308 dev->rx_info.total_sdio_msdu_pending_intr++;
309
310 status = rsi_process_pkt(common);
311 if (status) {
312 rsi_dbg(ERR_ZONE, "%s: Failed to read pkt\n",
313 __func__);
314 mutex_unlock(&common->rx_lock);
315 return;
316 }
317
318 isr_status &= ~BIT(MSDU_PKT_PENDING);
319 }
320
321 if (isr_status) {
322 rsi_sdio_ack_intr(common->priv, isr_status);
323 dev->rx_info.total_sdio_unknown_intr++;
324 isr_status = 0;
325 rsi_dbg(ISR_ZONE, "Unknown Interrupt %x\n",
326 isr_status);
327 }
328
329 mutex_unlock(&common->rx_lock);
330 } while (1);
331}
332
333/* This function is used to read buffer status register and
334 * set relevant fields in rsi_91x_sdiodev struct.
335 */
336int rsi_sdio_check_buffer_status(struct rsi_hw *adapter, u8 q_num)
337{
338 struct rsi_common *common = adapter->priv;
339 struct rsi_91x_sdiodev *dev = adapter->rsi_dev;
340 u8 buf_status = 0;
341 int status = 0;
342 static int counter = 4;
343
344 if (!dev->buff_status_updated && counter) {
345 counter--;
346 goto out;
347 }
348
349 dev->buff_status_updated = false;
350 status = rsi_sdio_read_register(common->priv,
351 RSI_DEVICE_BUFFER_STATUS_REGISTER,
352 &buf_status);
353
354 if (status) {
355 rsi_dbg(ERR_ZONE,
356 "%s: Failed to read status register\n", __func__);
357 return -1;
358 }
359
360 if (buf_status & (BIT(PKT_MGMT_BUFF_FULL))) {
361 if (!dev->rx_info.mgmt_buffer_full)
362 dev->rx_info.mgmt_buf_full_counter++;
363 dev->rx_info.mgmt_buffer_full = true;
364 } else {
365 dev->rx_info.mgmt_buffer_full = false;
366 }
367
368 if (buf_status & (BIT(PKT_BUFF_FULL))) {
369 if (!dev->rx_info.buffer_full)
370 dev->rx_info.buf_full_counter++;
371 dev->rx_info.buffer_full = true;
372 } else {
373 dev->rx_info.buffer_full = false;
374 }
375
376 if (buf_status & (BIT(PKT_BUFF_SEMI_FULL))) {
377 if (!dev->rx_info.semi_buffer_full)
378 dev->rx_info.buf_semi_full_counter++;
379 dev->rx_info.semi_buffer_full = true;
380 } else {
381 dev->rx_info.semi_buffer_full = false;
382 }
383
384 if (dev->rx_info.mgmt_buffer_full || dev->rx_info.buf_full_counter)
385 counter = 1;
386 else
387 counter = 4;
388
389out:
390 if ((q_num == MGMT_SOFT_Q) && (dev->rx_info.mgmt_buffer_full))
391 return QUEUE_FULL;
392
393 if ((q_num < MGMT_SOFT_Q) && (dev->rx_info.buffer_full))
394 return QUEUE_FULL;
395
396 return QUEUE_NOT_FULL;
397}
398
399/**
400 * rsi_sdio_determine_event_timeout() - This Function determines the event
401 * timeout duration.
402 * @adapter: Pointer to the adapter structure.
403 *
404 * Return: timeout duration is returned.
405 */
406int rsi_sdio_determine_event_timeout(struct rsi_hw *adapter)
407{
408 struct rsi_91x_sdiodev *dev = adapter->rsi_dev;
409
410 /* Once buffer full is seen, event timeout to occur every 2 msecs */
411 if (dev->rx_info.buffer_full)
412 return 2;
413
414 return EVENT_WAIT_FOREVER;
415}
1/*
2 * Copyright (c) 2014 Redpine Signals Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 *
16 */
17
18#include <linux/firmware.h>
19#include <net/rsi_91x.h>
20#include "rsi_sdio.h"
21#include "rsi_common.h"
22
23/**
24 * rsi_sdio_master_access_msword() - This function sets the AHB master access
25 * MS word in the SDIO slave registers.
26 * @adapter: Pointer to the adapter structure.
27 * @ms_word: ms word need to be initialized.
28 *
29 * Return: status: 0 on success, -1 on failure.
30 */
31int rsi_sdio_master_access_msword(struct rsi_hw *adapter, u16 ms_word)
32{
33 u8 byte;
34 u8 function = 0;
35 int status = 0;
36
37 byte = (u8)(ms_word & 0x00FF);
38
39 rsi_dbg(INIT_ZONE,
40 "%s: MASTER_ACCESS_MSBYTE:0x%x\n", __func__, byte);
41
42 status = rsi_sdio_write_register(adapter,
43 function,
44 SDIO_MASTER_ACCESS_MSBYTE,
45 &byte);
46 if (status) {
47 rsi_dbg(ERR_ZONE,
48 "%s: fail to access MASTER_ACCESS_MSBYTE\n",
49 __func__);
50 return -1;
51 }
52
53 byte = (u8)(ms_word >> 8);
54
55 rsi_dbg(INIT_ZONE, "%s:MASTER_ACCESS_LSBYTE:0x%x\n", __func__, byte);
56 status = rsi_sdio_write_register(adapter,
57 function,
58 SDIO_MASTER_ACCESS_LSBYTE,
59 &byte);
60 return status;
61}
62
63static void rsi_rx_handler(struct rsi_hw *adapter);
64
65void rsi_sdio_rx_thread(struct rsi_common *common)
66{
67 struct rsi_hw *adapter = common->priv;
68 struct rsi_91x_sdiodev *sdev = adapter->rsi_dev;
69
70 do {
71 rsi_wait_event(&sdev->rx_thread.event, EVENT_WAIT_FOREVER);
72 rsi_reset_event(&sdev->rx_thread.event);
73 rsi_rx_handler(adapter);
74 } while (!atomic_read(&sdev->rx_thread.thread_done));
75
76 rsi_dbg(INFO_ZONE, "%s: Terminated SDIO RX thread\n", __func__);
77 atomic_inc(&sdev->rx_thread.thread_done);
78 kthread_complete_and_exit(&sdev->rx_thread.completion, 0);
79}
80
81/**
82 * rsi_process_pkt() - This Function reads rx_blocks register and figures out
83 * the size of the rx pkt.
84 * @common: Pointer to the driver private structure.
85 *
86 * Return: 0 on success, -1 on failure.
87 */
88static int rsi_process_pkt(struct rsi_common *common)
89{
90 struct rsi_hw *adapter = common->priv;
91 struct rsi_91x_sdiodev *dev =
92 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
93 u8 num_blks = 0;
94 u32 rcv_pkt_len = 0;
95 int status = 0;
96 u8 value = 0;
97
98 num_blks = ((adapter->interrupt_status & 1) |
99 ((adapter->interrupt_status >> RECV_NUM_BLOCKS) << 1));
100
101 if (!num_blks) {
102 status = rsi_sdio_read_register(adapter,
103 SDIO_RX_NUM_BLOCKS_REG,
104 &value);
105 if (status) {
106 rsi_dbg(ERR_ZONE,
107 "%s: Failed to read pkt length from the card:\n",
108 __func__);
109 return status;
110 }
111 num_blks = value & 0x1f;
112 }
113
114 if (dev->write_fail == 2)
115 rsi_sdio_ack_intr(common->priv, (1 << MSDU_PKT_PENDING));
116
117 if (unlikely(!num_blks)) {
118 dev->write_fail = 2;
119 return -1;
120 }
121
122 rcv_pkt_len = (num_blks * 256);
123
124 status = rsi_sdio_host_intf_read_pkt(adapter, dev->pktbuffer,
125 rcv_pkt_len);
126 if (status) {
127 rsi_dbg(ERR_ZONE, "%s: Failed to read packet from card\n",
128 __func__);
129 return status;
130 }
131
132 status = rsi_read_pkt(common, dev->pktbuffer, rcv_pkt_len);
133 if (status) {
134 rsi_dbg(ERR_ZONE, "Failed to read the packet\n");
135 return status;
136 }
137
138 return 0;
139}
140
141/**
142 * rsi_init_sdio_slave_regs() - This function does the actual initialization
143 * of SDBUS slave registers.
144 * @adapter: Pointer to the adapter structure.
145 *
146 * Return: status: 0 on success, -1 on failure.
147 */
148int rsi_init_sdio_slave_regs(struct rsi_hw *adapter)
149{
150 struct rsi_91x_sdiodev *dev =
151 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
152 u8 function = 0;
153 u8 byte;
154 int status = 0;
155
156 if (dev->next_read_delay) {
157 byte = dev->next_read_delay;
158 status = rsi_sdio_write_register(adapter,
159 function,
160 SDIO_NXT_RD_DELAY2,
161 &byte);
162 if (status) {
163 rsi_dbg(ERR_ZONE,
164 "%s: Failed to write SDIO_NXT_RD_DELAY2\n",
165 __func__);
166 return -1;
167 }
168 }
169
170 if (dev->sdio_high_speed_enable) {
171 rsi_dbg(INIT_ZONE, "%s: Enabling SDIO High speed\n", __func__);
172 byte = 0x3;
173
174 status = rsi_sdio_write_register(adapter,
175 function,
176 SDIO_REG_HIGH_SPEED,
177 &byte);
178 if (status) {
179 rsi_dbg(ERR_ZONE,
180 "%s: Failed to enable SDIO high speed\n",
181 __func__);
182 return -1;
183 }
184 }
185
186 /* This tells SDIO FIFO when to start read to host */
187 rsi_dbg(INIT_ZONE, "%s: Initializing SDIO read start level\n", __func__);
188 byte = 0x24;
189
190 status = rsi_sdio_write_register(adapter,
191 function,
192 SDIO_READ_START_LVL,
193 &byte);
194 if (status) {
195 rsi_dbg(ERR_ZONE,
196 "%s: Failed to write SDIO_READ_START_LVL\n", __func__);
197 return -1;
198 }
199
200 rsi_dbg(INIT_ZONE, "%s: Initializing FIFO ctrl registers\n", __func__);
201 byte = (128 - 32);
202
203 status = rsi_sdio_write_register(adapter,
204 function,
205 SDIO_READ_FIFO_CTL,
206 &byte);
207 if (status) {
208 rsi_dbg(ERR_ZONE,
209 "%s: Failed to write SDIO_READ_FIFO_CTL\n", __func__);
210 return -1;
211 }
212
213 byte = 32;
214 status = rsi_sdio_write_register(adapter,
215 function,
216 SDIO_WRITE_FIFO_CTL,
217 &byte);
218 if (status) {
219 rsi_dbg(ERR_ZONE,
220 "%s: Failed to write SDIO_WRITE_FIFO_CTL\n", __func__);
221 return -1;
222 }
223
224 return 0;
225}
226
227/**
228 * rsi_rx_handler() - Read and process SDIO interrupts.
229 * @adapter: Pointer to the adapter structure.
230 *
231 * Return: None.
232 */
233static void rsi_rx_handler(struct rsi_hw *adapter)
234{
235 struct rsi_common *common = adapter->priv;
236 struct rsi_91x_sdiodev *dev =
237 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
238 int status;
239 u8 isr_status = 0;
240 u8 fw_status = 0;
241
242 dev->rx_info.sdio_int_counter++;
243
244 do {
245 mutex_lock(&common->rx_lock);
246 status = rsi_sdio_read_register(common->priv,
247 RSI_FN1_INT_REGISTER,
248 &isr_status);
249 if (status) {
250 rsi_dbg(ERR_ZONE,
251 "%s: Failed to Read Intr Status Register\n",
252 __func__);
253 mutex_unlock(&common->rx_lock);
254 return;
255 }
256 adapter->interrupt_status = isr_status;
257
258 if (isr_status == 0) {
259 rsi_set_event(&common->tx_thread.event);
260 dev->rx_info.sdio_intr_status_zero++;
261 mutex_unlock(&common->rx_lock);
262 return;
263 }
264
265 rsi_dbg(ISR_ZONE, "%s: Intr_status = %x %d %d\n",
266 __func__, isr_status, (1 << MSDU_PKT_PENDING),
267 (1 << FW_ASSERT_IND));
268
269 if (isr_status & BIT(PKT_BUFF_AVAILABLE)) {
270 status = rsi_sdio_check_buffer_status(adapter, 0);
271 if (status < 0)
272 rsi_dbg(ERR_ZONE,
273 "%s: Failed to check buffer status\n",
274 __func__);
275 rsi_sdio_ack_intr(common->priv,
276 BIT(PKT_BUFF_AVAILABLE));
277 rsi_set_event(&common->tx_thread.event);
278
279 rsi_dbg(ISR_ZONE, "%s: ==> BUFFER_AVAILABLE <==\n",
280 __func__);
281 dev->buff_status_updated = true;
282
283 isr_status &= ~BIT(PKT_BUFF_AVAILABLE);
284 }
285
286 if (isr_status & BIT(FW_ASSERT_IND)) {
287 rsi_dbg(ERR_ZONE, "%s: ==> FIRMWARE Assert <==\n",
288 __func__);
289 status = rsi_sdio_read_register(common->priv,
290 SDIO_FW_STATUS_REG,
291 &fw_status);
292 if (status) {
293 rsi_dbg(ERR_ZONE,
294 "%s: Failed to read f/w reg\n",
295 __func__);
296 } else {
297 rsi_dbg(ERR_ZONE,
298 "%s: Firmware Status is 0x%x\n",
299 __func__, fw_status);
300 rsi_sdio_ack_intr(common->priv,
301 BIT(FW_ASSERT_IND));
302 }
303
304 common->fsm_state = FSM_CARD_NOT_READY;
305
306 isr_status &= ~BIT(FW_ASSERT_IND);
307 }
308
309 if (isr_status & BIT(MSDU_PKT_PENDING)) {
310 rsi_dbg(ISR_ZONE, "Pkt pending interrupt\n");
311 dev->rx_info.total_sdio_msdu_pending_intr++;
312
313 status = rsi_process_pkt(common);
314 if (status) {
315 rsi_dbg(ERR_ZONE, "%s: Failed to read pkt\n",
316 __func__);
317 mutex_unlock(&common->rx_lock);
318 return;
319 }
320
321 isr_status &= ~BIT(MSDU_PKT_PENDING);
322 }
323
324 if (isr_status) {
325 rsi_sdio_ack_intr(common->priv, isr_status);
326 dev->rx_info.total_sdio_unknown_intr++;
327 isr_status = 0;
328 rsi_dbg(ISR_ZONE, "Unknown Interrupt %x\n",
329 isr_status);
330 }
331
332 mutex_unlock(&common->rx_lock);
333 } while (1);
334}
335
336/* This function is used to read buffer status register and
337 * set relevant fields in rsi_91x_sdiodev struct.
338 */
339int rsi_sdio_check_buffer_status(struct rsi_hw *adapter, u8 q_num)
340{
341 struct rsi_common *common = adapter->priv;
342 struct rsi_91x_sdiodev *dev =
343 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
344 u8 buf_status = 0;
345 int status = 0;
346 static int counter = 4;
347
348 if (!dev->buff_status_updated && counter) {
349 counter--;
350 goto out;
351 }
352
353 dev->buff_status_updated = false;
354 status = rsi_sdio_read_register(common->priv,
355 RSI_DEVICE_BUFFER_STATUS_REGISTER,
356 &buf_status);
357
358 if (status) {
359 rsi_dbg(ERR_ZONE,
360 "%s: Failed to read status register\n", __func__);
361 return -1;
362 }
363
364 if (buf_status & (BIT(PKT_MGMT_BUFF_FULL))) {
365 if (!dev->rx_info.mgmt_buffer_full)
366 dev->rx_info.mgmt_buf_full_counter++;
367 dev->rx_info.mgmt_buffer_full = true;
368 } else {
369 dev->rx_info.mgmt_buffer_full = false;
370 }
371
372 if (buf_status & (BIT(PKT_BUFF_FULL))) {
373 if (!dev->rx_info.buffer_full)
374 dev->rx_info.buf_full_counter++;
375 dev->rx_info.buffer_full = true;
376 } else {
377 dev->rx_info.buffer_full = false;
378 }
379
380 if (buf_status & (BIT(PKT_BUFF_SEMI_FULL))) {
381 if (!dev->rx_info.semi_buffer_full)
382 dev->rx_info.buf_semi_full_counter++;
383 dev->rx_info.semi_buffer_full = true;
384 } else {
385 dev->rx_info.semi_buffer_full = false;
386 }
387
388 if (dev->rx_info.mgmt_buffer_full || dev->rx_info.buf_full_counter)
389 counter = 1;
390 else
391 counter = 4;
392
393out:
394 if ((q_num == MGMT_SOFT_Q) && (dev->rx_info.mgmt_buffer_full))
395 return QUEUE_FULL;
396
397 if ((q_num < MGMT_SOFT_Q) && (dev->rx_info.buffer_full))
398 return QUEUE_FULL;
399
400 return QUEUE_NOT_FULL;
401}
402
403/**
404 * rsi_sdio_determine_event_timeout() - This Function determines the event
405 * timeout duration.
406 * @adapter: Pointer to the adapter structure.
407 *
408 * Return: timeout duration is returned.
409 */
410int rsi_sdio_determine_event_timeout(struct rsi_hw *adapter)
411{
412 struct rsi_91x_sdiodev *dev =
413 (struct rsi_91x_sdiodev *)adapter->rsi_dev;
414
415 /* Once buffer full is seen, event timeout to occur every 2 msecs */
416 if (dev->rx_info.buffer_full)
417 return 2;
418
419 return EVENT_WAIT_FOREVER;
420}