23 #undef CSR_WIFI_HIP_NOISY
36 #define UNIFI_DEFAULT_HOST_IDLE_TIMEOUT 5
42 #define UNIFI_DEFAULT_WAKE_TIMEOUT 1000
65 #ifdef CSR_WIFI_HIP_NOISY
69 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
83 #define UNIFI_DEBUG_GBUFFER_SIZE 8192
84 static char unifi_debug_output[UNIFI_DEBUG_GBUFFER_SIZE];
85 static char *unifi_dbgbuf_ptr = unifi_debug_output;
86 static char *unifi_dbgbuf_start = unifi_debug_output;
88 static void append_char(
char c)
91 *unifi_dbgbuf_ptr++ =
c;
93 if ((unifi_dbgbuf_ptr - unifi_debug_output) >= UNIFI_DEBUG_GBUFFER_SIZE)
95 unifi_dbgbuf_ptr = unifi_debug_output;
100 void unifi_debug_string_to_buf(
const char *
str)
109 unifi_dbgbuf_start = unifi_dbgbuf_ptr + 1;
110 if ((unifi_dbgbuf_start - unifi_debug_output) >= UNIFI_DEBUG_GBUFFER_SIZE)
112 unifi_dbgbuf_start = unifi_debug_output;
117 void unifi_debug_log_to_buf(
const char *
fmt, ...)
119 #define DEBUG_BUFFER_SIZE 80
120 static char s[DEBUG_BUFFER_SIZE];
124 vsnprintf(s, DEBUG_BUFFER_SIZE, fmt, args);
127 unifi_debug_string_to_buf(s);
132 static void CsrUInt16ToHex(
u16 number,
char *str)
137 for (index = 0; index < 4; index++)
139 currentValue = (
u16) (number & 0x000F);
141 str[3 -
index] = (
char) (currentValue > 9 ? currentValue + 55 : currentValue +
'0');
162 void unifi_debug_hex_to_buf(
const char *buff,
u16 length)
167 for (i = 0; i <
length; i = i + 2)
169 CsrUInt16ToHex(*((
u16 *)(buff + i)), s);
170 unifi_debug_string_to_buf(s);
175 void unifi_debug_buf_dump(
void)
177 s32 offset = unifi_dbgbuf_ptr - unifi_debug_output;
180 dump_str(unifi_debug_output + offset, UNIFI_DEBUG_GBUFFER_SIZE - offset);
181 dump_str(unifi_debug_output, offset);
187 #ifdef CSR_PRE_ALLOC_NET_DATA
188 #define NETDATA_PRE_ALLOC_BUF_SIZE 8000
192 unifi_warning(card->ospriv,
"prealloc_netdata_free: IN: w=%d r=%d\n", card->prealloc_netdata_w, card->prealloc_netdata_r);
194 while (card->bulk_data_desc_list[card->prealloc_netdata_r].data_length != 0)
196 unifi_warning(card->ospriv,
"prealloc_netdata_free: r=%d\n", card->prealloc_netdata_r);
199 card->prealloc_netdata_r++;
200 card->prealloc_netdata_r %= BULK_DATA_PRE_ALLOC_NUM;
202 card->prealloc_netdata_r = card->prealloc_netdata_w = 0;
204 unifi_warning(card->ospriv,
"prealloc_netdata_free: OUT: w=%d r=%d\n", card->prealloc_netdata_w, card->prealloc_netdata_r);
212 unifi_trace(card->ospriv,
UDBG5,
"prealloc_netdata_alloc: IN: w=%d r=%d\n", card->prealloc_netdata_w, card->prealloc_netdata_r);
214 while (card->bulk_data_desc_list[card->prealloc_netdata_w].data_length == 0)
216 r =
unifi_net_data_malloc(card->ospriv, &card->bulk_data_desc_list[card->prealloc_netdata_w], NETDATA_PRE_ALLOC_BUF_SIZE);
219 unifi_error(card->ospriv,
"prealloc_netdata_alloc: Failed to allocate t-h bulk data\n");
222 card->prealloc_netdata_w++;
223 card->prealloc_netdata_w %= BULK_DATA_PRE_ALLOC_NUM;
225 unifi_trace(card->ospriv,
UDBG5,
"prealloc_netdata_alloc: OUT: w=%d r=%d\n", card->prealloc_netdata_w, card->prealloc_netdata_r);
235 unifi_trace(card->ospriv,
UDBG5,
"prealloc_netdata_get: IN: w=%d r=%d\n", card->prealloc_netdata_w, card->prealloc_netdata_r);
237 if (card->bulk_data_desc_list[card->prealloc_netdata_r].data_length == 0)
239 unifi_error(card->ospriv,
"prealloc_netdata_get: data_length = 0\n");
242 if ((size > NETDATA_PRE_ALLOC_BUF_SIZE) || (card->bulk_data_desc_list[card->prealloc_netdata_r].data_length == 0))
244 unifi_warning(card->ospriv,
"prealloc_netdata_get: Calling net_data_malloc\n");
249 unifi_error(card->ospriv,
"prealloc_netdata_get: Failed to allocate t-h bulk data\n");
255 *bulk_data_slot = card->bulk_data_desc_list[card->prealloc_netdata_r];
256 card->bulk_data_desc_list[card->prealloc_netdata_r].os_data_ptr =
NULL;
257 card->bulk_data_desc_list[card->prealloc_netdata_r].os_net_buf_ptr =
NULL;
258 card->bulk_data_desc_list[card->prealloc_netdata_r].net_buf_length = 0;
259 card->bulk_data_desc_list[card->prealloc_netdata_r].data_length = 0;
261 card->prealloc_netdata_r++;
262 card->prealloc_netdata_r %= BULK_DATA_PRE_ALLOC_NUM;
264 unifi_trace(card->ospriv,
UDBG5,
"prealloc_netdata_get: OUT: w=%d r=%d\n", card->prealloc_netdata_w, card->prealloc_netdata_r);
295 card->bh_reason_unifi = 1;
320 card->low_power_mode = low_power_mode;
321 card->periodic_wake_mode = periodic_wake_mode;
324 "unifi_configure_low_power_mode: new mode = %s, wake_host = %s\n",
351 unifi_error(card->ospriv,
"Attempt to set mode to TORPID when lower power mode is disabled\n");
380 u16 data_slots_used = 0;
384 r = process_clock_request(card);
387 unifi_error(card->ospriv,
"Error setting maximum SDIO clock\n");
435 reason_unifi = card->bh_reason_unifi;
450 "UNIFI_HOST_STATE_%s: Set state to AWAKE.\n",
460 else if (reason_unifi)
478 card->bh_reason_host = 0;
494 unifi_error(card->ospriv,
"UniFi did not wake up on time...\n");
511 if (card->bh_reason_unifi || card->bh_reason_host)
544 unifi_error(card->ospriv,
"Failed to disable SDIO interrupts. unifi_bh queues error.\n");
552 r = process_bh(card);
572 #ifndef CSR_WIFI_HIP_TA_DISABLE
578 "Traffic is not periodic, set timer for TORPID.\n");
580 #ifndef CSR_WIFI_HIP_TA_DISABLE
585 "Traffic is periodic, set unifi to TORPID immediately.\n");
606 unifi_error(card->ospriv,
"Failed to enable SDIO interrupt\n");
615 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_SDIO_TRACE)
616 unifi_debug_buf_dump();
619 if (card->bh_reason_unifi)
625 "unifi_bh: state=%d %c, clock=%dkHz, interrupt=%d host=%d, power_save=%s\n",
628 card->sdio_clock_speed / 1000,
629 card->bh_reason_unifi, card->bh_reason_host,
663 if (!card->request_max_clock)
697 card->request_max_clock = 0;
737 r = handle_host_protocol(card, &more);
743 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_DATA_PLANE_PROFILE)
744 unifi_debug_log_to_buf(
"c52=%d c53=%d tx=%d txc=%d rx=%d s=%d t=%d fc=%d\n",
745 card->cmd_prof.cmd52_count,
746 card->cmd_prof.cmd53_count,
747 card->cmd_prof.tx_count,
748 card->cmd_prof.tx_cfm_count,
749 card->cmd_prof.rx_count,
750 card->cmd_prof.sdio_cmd_signal,
751 card->cmd_prof.sdio_cmd_to_host,
752 card->cmd_prof.sdio_cmd_from_host_and_clear
755 card->cmd_prof.cmd52_count = card->cmd_prof.cmd53_count = 0;
756 card->cmd_prof.tx_count = card->cmd_prof.tx_cfm_count = card->cmd_prof.rx_count = 0;
758 card->cmd_prof.cmd52_f0_r_count = 0;
759 card->cmd_prof.cmd52_f0_w_count = 0;
760 card->cmd_prof.cmd52_r8or16_count = 0;
761 card->cmd_prof.cmd52_w8or16_count = 0;
762 card->cmd_prof.cmd52_r16_count = 0;
763 card->cmd_prof.cmd52_w16_count = 0;
764 card->cmd_prof.cmd52_r32_count = 0;
766 card->cmd_prof.sdio_cmd_signal = 0;
767 card->cmd_prof.sdio_cmd_clear_slot = 0;
768 card->cmd_prof.sdio_cmd_to_host = 0;
769 card->cmd_prof.sdio_cmd_from_host = 0;
770 card->cmd_prof.sdio_cmd_from_host_and_clear = 0;
774 }
while (more || card->bh_reason_unifi || card->bh_reason_host);
780 unifi_error(card->ospriv,
"Failed to acknowledge interrupt.\n");
789 r = handle_host_protocol(card, &more);
795 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_DATA_PLANE_PROFILE)
796 unifi_debug_log_to_buf(
"c52=%d c53=%d tx=%d txc=%d rx=%d s=%d t=%d fc=%d\n",
797 card->cmd_prof.cmd52_count,
798 card->cmd_prof.cmd53_count,
799 card->cmd_prof.tx_count,
800 card->cmd_prof.tx_cfm_count,
801 card->cmd_prof.rx_count,
802 card->cmd_prof.sdio_cmd_signal,
803 card->cmd_prof.sdio_cmd_to_host,
804 card->cmd_prof.sdio_cmd_from_host_and_clear
807 card->cmd_prof.cmd52_count = card->cmd_prof.cmd53_count = 0;
808 card->cmd_prof.tx_count = card->cmd_prof.tx_cfm_count = card->cmd_prof.rx_count = 0;
810 card->cmd_prof.cmd52_f0_r_count = 0;
811 card->cmd_prof.cmd52_f0_w_count = 0;
812 card->cmd_prof.cmd52_r8or16_count = 0;
813 card->cmd_prof.cmd52_w8or16_count = 0;
814 card->cmd_prof.cmd52_r16_count = 0;
815 card->cmd_prof.cmd52_w16_count = 0;
816 card->cmd_prof.cmd52_r32_count = 0;
818 card->cmd_prof.sdio_cmd_signal = 0;
819 card->cmd_prof.sdio_cmd_clear_slot = 0;
820 card->cmd_prof.sdio_cmd_to_host = 0;
821 card->cmd_prof.sdio_cmd_from_host = 0;
822 card->cmd_prof.sdio_cmd_from_host_and_clear = 0;
830 }
while (more || card->bh_reason_unifi || card->bh_reason_host);
832 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_DATA_PLANE_PROFILE)
835 unifi_debug_log_to_buf(
"proc=%d\n",
836 card->cmd_prof.process_count);
866 *processed_something =
FALSE;
868 #ifdef CSR_WIFI_HIP_NOISY
869 unifi_error(card->ospriv,
" ======================== \n");
872 #ifdef CSR_WIFI_HIP_DATA_PLANE_PROFILE
873 card->cmd_prof.process_count++;
876 card->bh_reason_unifi = card->bh_reason_host = 0;
877 card->generate_interrupt = 0;
883 r = read_to_host_signals(card, &done);
886 unifi_error(card->ospriv,
"Error occured reading to-host signals\n");
891 *processed_something =
TRUE;
899 r = process_to_host_signals(card, &done);
902 unifi_error(card->ospriv,
"Error occured processing to-host signals\n");
908 r = process_fh_cmd_queue(card, &done);
911 unifi_error(card->ospriv,
"Error occured processing from-host signals\n");
916 *processed_something =
TRUE;
919 r = process_fh_traffic_queue(card, &done);
922 unifi_error(card->ospriv,
"Error occured processing from-host data signals\n");
927 *processed_something =
TRUE;
931 r = flush_fh_buffer(card);
934 unifi_error(card->ospriv,
"Failed to copy from-host signals to UniFi\n");
942 if (card->generate_interrupt)
947 unifi_error(card->ospriv,
"Failed to notify UniFi that queues have been modified.\n");
952 #ifdef CSR_WIFI_RX_PATH_SPLIT
953 #ifdef CSR_WIFI_RX_PATH_SPLIT_DONT_USE_WQ
959 restart_packet_flow(card);
961 #ifdef CSR_PRE_ALLOC_NET_DATA
962 r = prealloc_netdata_alloc(card);
965 unifi_error(card->ospriv,
"prealloc_netdata failed\n");
982 #define GET_CHUNKS_FOR(SIG_FRAG_SIZE, LENGTH) (((LENGTH) + ((SIG_FRAG_SIZE)-1)) / (SIG_FRAG_SIZE))
1003 s32 count_thw, count_thr;
1004 s32 unread_chunks, unread_bytes;
1013 unifi_error(card->ospriv,
"Failed to read to-host sig written count\n");
1016 card->to_host_signals_w = count_thw;
1018 count_thr = card->to_host_signals_r;
1020 if (count_thw == count_thr)
1026 (((count_thw - count_thr) + 128) % 128) - card->th_buffer.count;
1028 if (unread_chunks == 0)
1033 unread_bytes = card->config_data.sig_frag_size * unread_chunks;
1037 card->config_data.tohost_sigbuf_handle,
1038 card->th_buffer.ptr,
1043 unifi_error(card->ospriv,
"Failed to read ToHost signal\n");
1047 card->th_buffer.ptr += unread_bytes;
1048 card->th_buffer.count += (
u16)unread_chunks;
1077 card->to_host_signals_r =
1078 (card->to_host_signals_r + (card->th_buffer.count - pending)) % 128;
1079 card->th_buffer.count = pending;
1083 (
u8)card->to_host_signals_r);
1086 unifi_error(card->ospriv,
"Failed to update to-host signals read\n");
1093 unifi_error(card->ospriv,
"Failed to notify UniFi that we processed to-host signals.\n");
1097 card->generate_interrupt = 0;
1172 u16 bytes_transferred = 0;
1177 pending = card->th_buffer.count;
1192 bufptr = card->th_buffer.buf;
1196 s16 f_flush_count = 0;
1203 cmd = bufptr[1] >> 4;
1204 sig_len = bufptr[0] + ((bufptr[1] & 0x0F) << 8);
1206 #ifdef CSR_WIFI_HIP_NOISY
1207 unifi_error(card->ospriv,
"Received UniFi msg cmd=%d, len=%d\n",
1211 if ((sig_len == 0) &&
1214 unifi_error(card->ospriv,
"incomplete signal or command: has size zero\n");
1224 chunks_in_buf =
GET_CHUNKS_FOR(card->config_data.sig_frag_size, (
u16)(sig_len + 2));
1231 if (chunks_in_buf > (
u16)pending)
1233 unifi_error(card->ospriv,
"incomplete signal (0x%x?): need %d chunks, got %d\n",
1235 chunks_in_buf, pending);
1237 card->to_host_signals_w,
1238 card->to_host_signals_r);
1247 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_DATA_PLANE_PROFILE)
1248 card->cmd_prof.sdio_cmd_signal++;
1260 if (data_len > card->config_data.data_slot_size)
1263 "Bulk Data length (%d) exceeds Maximum Bulk Data length (%d)\n",
1264 data_len, card->config_data.data_slot_size);
1278 if (slot >= card->config_data.num_tohost_data_slots)
1280 unifi_error(card->ospriv,
"!!!bad slot number in to-host signal: %d, sig 0x%X\n",
1302 (*card->udi_hook)(card->ospriv, bufptr + 2, sig_len,
1306 #ifdef CSR_WIFI_HIP_DATA_PLANE_PROFILE
1309 card->cmd_prof.tx_cfm_count++;
1317 card->cmd_prof.rx_count++;
1337 unifi_trace(card->ospriv,
UDBG4,
"process_to_host_signals signal ID=%x host Tag=%x status=%x\n",
1344 if (status && (card->fh_slot_host_tag_record))
1346 u16 num_fh_slots = card->config_data.num_fromhost_data_slots;
1351 for (i = 0; i < num_fh_slots; i++)
1353 if (card->fh_slot_host_tag_record[i] == host_tag)
1355 #ifdef CSR_WIFI_REQUEUE_PACKET_TO_HAL
1357 r = unifi_reque_ma_packet_request(card->ospriv, host_tag, status, &card->from_host_data[i].bd);
1361 unifi_trace(card->ospriv,
UDBG5,
"process_to_host_signals: Failed to requeue Packet(hTag:%x) back to HAL \n", host_tag);
1366 CardClearFromHostDataSlotWithoutFreeingBulkData(card, i);
1370 unifi_trace(card->ospriv,
UDBG4,
"process_to_host_signals Clear slot=%x host tag=%x\n", i, host_tag);
1399 #ifndef CSR_WIFI_DEFER_TH_FLUSH
1414 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_DATA_PLANE_PROFILE)
1415 card->cmd_prof.sdio_cmd_clear_slot++;
1420 unifi_error(card->ospriv,
"process_to_host_signals: clear slot, bad data len: 0x%X at offset %d\n",
1421 sig_len, bufptr - card->th_buffer.buf);
1425 r = process_clear_slot_command(card, bufptr);
1428 unifi_error(card->ospriv,
"Failed to process clear slot\n");
1440 unifi_error(card->ospriv,
"process_to_host_signals: bulk data, bad data len: 0x%X at offset %d\n",
1441 sig_len, bufptr - card->th_buffer.buf);
1445 r = process_bulk_data_command(card, bufptr, cmd, sig_len);
1448 unifi_error(card->ospriv,
"Failed to process bulk cmd\n");
1452 bytes_transferred += sig_len;
1456 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_DATA_PLANE_PROFILE)
1457 card->cmd_prof.sdio_cmd_from_host_and_clear++;
1459 #ifndef CSR_WIFI_DEFER_TH_FLUSH
1463 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_DATA_PLANE_PROFILE)
1466 card->cmd_prof.sdio_cmd_from_host++;
1470 card->cmd_prof.sdio_cmd_to_host++;
1479 unifi_error(card->ospriv,
"Unrecognised to-host command: %d\n", cmd);
1483 bufptr += chunks_in_buf * card->config_data.sig_frag_size;
1484 pending -= chunks_in_buf;
1493 r = update_to_host_signals_r(card, pending);
1498 bytes_transferred = 0;
1504 unifi_warning(card->ospriv,
"proc_th_sigs: %d unprocessed\n", pending);
1508 if (card->th_buffer.count != pending)
1510 r = update_to_host_signals_r(card, pending);
1522 remaining = card->th_buffer.ptr -
bufptr;
1525 unifi_error(card->ospriv,
"Processing TH signals overran the buffer\n");
1531 u8 *
d = card->th_buffer.buf;
1539 card->th_buffer.ptr = card->th_buffer.buf + remaining;
1572 slot = data_slot & 0x7FFF;
1574 #ifdef CSR_WIFI_HIP_NOISY
1575 unifi_error(card->ospriv,
"CMD clear data slot 0x%04x\n", data_slot);
1580 if (slot >= card->config_data.num_tohost_data_slots)
1583 "Invalid to-host data slot in SDIO_CMD_CLEAR_SLOT: %d\n",
1588 unifi_warning(card->ospriv,
"Unexpected clear to-host data slot cmd: 0x%04x\n",
1593 if (slot >= card->config_data.num_fromhost_data_slots)
1596 "Invalid from-host data slot in SDIO_CMD_CLEAR_SLOT: %d\n",
1641 #ifdef CSR_WIFI_ALIGNMENT_WORKAROUND
1642 u8 *host_bulk_data_slot;
1650 read_unpack_cmd(cmdptr, &bdcmd);
1652 unifi_trace(card->ospriv,
UDBG4,
"Processing bulk data cmd %d %s, len=%d, slot=0x%X\n",
1661 if (card->sdio_io_block_pad)
1663 len = (len + card->sdio_io_block_size - 1) & ~(card->sdio_io_block_size - 1);
1664 unifi_trace(card->ospriv,
UDBG4,
"Rounded bulk data length up to %d\n", len);
1680 if (slot >= card->config_data.num_tohost_data_slots)
1683 "Invalid to-host data slot in SDIO bulk xfr req: %d\n",
1689 #ifdef CSR_PRE_ALLOC_NET_DATA
1690 r = prealloc_netdata_get(card, &card->to_host_data[slot], len);
1696 unifi_error(card->ospriv,
"Failed to allocate t-h bulk data\n");
1700 bdslot = &card->to_host_data[
slot];
1706 unifi_error(card->ospriv,
"Failed to align t-h bulk data buffer for DMA\n");
1714 if (slot >= card->config_data.num_fromhost_data_slots)
1717 "Invalid from-host data slot in SDIO bulk xfr req: %d\n",
1721 bdslot = &card->from_host_data[
slot].bd;
1730 "Bulk %c %s len=%d, handle %d - slot=%d %p+(%d)\n",
1736 #ifdef CSR_WIFI_HIP_NOISY
1737 unifi_error(card->ospriv,
"Bulk %s len=%d, handle %d - slot=%d %p+(%d)\n",
1747 unifi_error(card->ospriv,
"Null os_data_ptr - Bulk %s handle %d - slot=%d o=(%d)\n",
1755 #ifdef CSR_WIFI_ALIGNMENT_WORKAROUND
1763 if (!host_bulk_data_slot)
1765 unifi_error(card->ospriv,
" failed to allocate request_data before unifi_bulk_rw\n");
1769 memcpy((
void *)host_bulk_data_slot,
1774 (
void *)host_bulk_data_slot,
1795 "Failed: %s hlen=%d, slen=%d, handle %d - slot=%d %p+0x%X\n",
1808 if (slot >= card->config_data.num_fromhost_data_slots)
1811 "Invalid from-host data slot in SDIO_CMD_FROM_HOST_AND_CLEAR: %d\n",
1816 #ifdef CSR_WIFI_ALIGNMENT_WORKAROUND
1820 kfree(host_bulk_data_slot);
1824 if (card->fh_slot_host_tag_record)
1826 unifi_trace(card->ospriv,
UDBG5,
"CopyFromHostAndClearSlot Reset entry for slot=%d\n", slot);
1861 u32 occupied_fh, slots_fh;
1864 count_fhw = card->from_host_signals_w;
1865 count_fhr = card->from_host_signals_r;
1866 slots_fh = card->config_data.num_fromhost_sig_frags;
1869 occupied_fh = (count_fhw - count_fhr) % 128;
1871 if (slots_fh < occupied_fh)
1877 *space_fh = slots_fh - occupied_fh;
1880 if ((occupied_fh != 0) && (*space_fh < needed))
1885 unifi_error(card->ospriv,
"Failed to read from-host sig read count\n");
1888 card->from_host_signals_r = count_fhr;
1890 occupied_fh = (count_fhw - count_fhr) % 128;
1891 *space_fh = slots_fh - occupied_fh;
1902 #define ROUND_UP_NEEDED_CHUNKS(_card, _needed_chunks) \
1904 u16 _chunks_per_block; \
1905 u16 _chunks_in_last_block; \
1907 if (_card->sdio_io_block_pad) \
1909 _chunks_per_block = _card->sdio_io_block_size / _card->config_data.sig_frag_size; \
1910 _chunks_in_last_block = _needed_chunks % _chunks_per_block; \
1911 if (_chunks_in_last_block != 0) \
1913 _needed_chunks = _needed_chunks + (_chunks_per_block - _chunks_in_last_block); \
1919 #define ROUND_UP_SPACE_CHUNKS(_card, _space_chunks) \
1921 u16 _chunks_per_block; \
1923 if (_card->sdio_io_block_pad) \
1925 _chunks_per_block = _card->sdio_io_block_size / _card->config_data.sig_frag_size; \
1926 _space_chunks = ((_space_chunks / _chunks_per_block) * _chunks_per_block); \
1961 q_t *sigq = &card->fh_command_queue;
1975 if (pending_sigs == 0)
1999 needed_chunks = pending_chunks + card->fh_buffer.count;
2004 r = check_fh_sig_slots(card, needed_chunks, &space_chunks);
2008 unifi_error(card->ospriv,
"Failed to read fh sig count\n");
2012 #ifdef CSR_WIFI_HIP_NOISY
2013 unifi_error(card->ospriv,
"proc_fh: %d chunks free, need %d\n",
2014 space_chunks, needed_chunks);
2022 if (needed_chunks > (
u16)space_chunks)
2031 if ((
u16)space_chunks <= card->fh_buffer.count)
2037 unifi_error(card->ospriv,
"not enough room to send signals, need %d chunks, %d free\n",
2038 card->fh_buffer.count, space_chunks);
2039 card->generate_interrupt = 1;
2042 pending_chunks = (
u16)(space_chunks - card->fh_buffer.count);
2045 while (pending_sigs-- && pending_chunks > 0)
2049 u16 sig_chunks, total_length, free_chunks_in_fh_buffer;
2052 u16 signal_length = 0;
2065 unifi_error(card->ospriv,
"process_fh_queue: Bad len: %d\n", signal_length);
2070 sig_chunks =
GET_CHUNKS_FOR(card->config_data.sig_frag_size, (
u16)(signal_length + 2));
2072 free_chunks_in_fh_buffer =
GET_CHUNKS_FOR(card->config_data.sig_frag_size,
2074 if (free_chunks_in_fh_buffer < sig_chunks)
2077 unifi_notice(card->ospriv,
"proc_fh_cmd_q: no room in fh buffer for 0x%.4X, deferring\n",
2082 packed_sigptr = csptr->
sigbuf;
2087 unifi_notice(card->ospriv,
"proc_fh_cmd_q: no fh data slots for 0x%.4X, deferring\n",
2110 #ifdef CSR_WIFI_HIP_NOISY
2111 unifi_error(card->ospriv,
"Sending signal 0x%.4X\n",
2117 total_length = sig_chunks * card->config_data.sig_frag_size;
2119 card->fh_buffer.ptr[0] = (
u8)(signal_length & 0xff);
2120 card->fh_buffer.ptr[1] =
2123 memcpy(card->fh_buffer.ptr + 2, packed_sigptr, signal_length);
2124 memset(card->fh_buffer.ptr + 2 + signal_length, 0,
2125 total_length - (2 + signal_length));
2127 #ifdef CSR_WIFI_HIP_NOISY
2128 unifi_error(card->ospriv,
"proc_fh: fh_buffer %d bytes \n",
2130 dump(card->fh_buffer.ptr, signal_length + 2);
2134 card->fh_buffer.ptr += total_length;
2135 card->fh_buffer.count += sig_chunks;
2137 #ifdef CSR_WIFI_HIP_NOISY
2138 unifi_error(card->ospriv,
"Added %d to fh buf, len now %d, count %d\n",
2140 card->fh_buffer.ptr - card->fh_buffer.buf,
2141 card->fh_buffer.count);
2145 pending_chunks -= sig_chunks;
2152 (*card->udi_hook)(card->ospriv, packed_sigptr, signal_length,
2189 q_t *sigq = card->fh_traffic_queue;
2194 u16 pending_sigs = 0;
2195 u16 pending_chunks = 0;
2209 unifi_trace(card->ospriv,
UDBG5,
"proc_fh%d: %d pending\n", n, pending_sigs);
2227 if (pending_sigs == 0)
2237 needed_chunks = pending_chunks + card->fh_buffer.count;
2242 r = check_fh_sig_slots(card, needed_chunks, &space_chunks);
2246 unifi_error(card->ospriv,
"Failed to read fh sig count\n");
2250 #ifdef CSR_WIFI_HIP_NOISY
2252 "process_fh_traffic_queue: %d chunks free, need %d\n",
2253 space_chunks, needed_chunks);
2259 if (needed_chunks > (
u16)space_chunks)
2264 if ((
u16)space_chunks <= card->fh_buffer.count)
2270 unifi_error(card->ospriv,
"not enough room to send signals, need %d chunks, %d free\n",
2271 card->fh_buffer.count, space_chunks);
2272 card->generate_interrupt = 1;
2276 pending_chunks = (
u16)space_chunks - card->fh_buffer.count;
2290 u16 sig_chunks, total_length, free_chunks_in_fh_buffer;
2293 u16 signal_length = 0;
2313 unifi_error(card->ospriv,
"process_fh_traffic_queue: Bad len: %d\n", signal_length);
2318 sig_chunks =
GET_CHUNKS_FOR(card->config_data.sig_frag_size, (
u16)(signal_length + 2));
2319 free_chunks_in_fh_buffer =
GET_CHUNKS_FOR(card->config_data.sig_frag_size,
2321 if (free_chunks_in_fh_buffer < sig_chunks)
2324 unifi_notice(card->ospriv,
"process_fh_traffic_queue: no more chunks.\n");
2328 packed_sigptr = csptr->
sigbuf;
2339 unifi_error(card->ospriv,
"MA-PACKET.req with empty bulk data (%d bytes in %p)\n",
2341 dump(packed_sigptr, signal_length);
2363 if (card->fh_slot_host_tag_record)
2370 "process_fh_traffic_queue signal ID =%x fh slot=%x Host tag =%x\n",
2372 card->fh_slot_host_tag_record[slot_num] = host_tag;
2378 #ifdef CSR_WIFI_HIP_DATA_PLANE_PROFILE
2383 card->cmd_prof.tx_count++;
2389 #ifdef CSR_WIFI_HIP_NOISY
2390 unifi_error(card->ospriv,
"Sending signal 0x%.4X\n",
2395 total_length = sig_chunks * card->config_data.sig_frag_size;
2397 card->fh_buffer.ptr[0] = (
u8)(signal_length & 0xff);
2398 card->fh_buffer.ptr[1] =
2401 memcpy(card->fh_buffer.ptr + 2, packed_sigptr, signal_length);
2402 memset(card->fh_buffer.ptr + 2 + signal_length, 0,
2403 total_length - (2 + signal_length));
2405 #ifdef CSR_WIFI_HIP_NOISY
2406 unifi_error(card->ospriv,
"proc_fh: fh_buffer %d bytes \n",
2408 dump(card->fh_buffer.ptr, signal_length + 2);
2412 card->fh_buffer.ptr += total_length;
2413 card->fh_buffer.count += sig_chunks;
2415 #ifdef CSR_WIFI_HIP_NOISY
2416 unifi_error(card->ospriv,
"Added %d to fh buf, len now %d, count %d\n",
2418 card->fh_buffer.ptr - card->fh_buffer.buf,
2419 card->fh_buffer.count);
2424 pending_chunks -= sig_chunks;
2431 (*card->udi_hook)(card->ospriv, packed_sigptr, signal_length,
2441 }
while ((pending_sigs > 0) && (pending_chunks > 0) && (q_no >= 0));
2466 u16 chunks_in_last_block;
2470 len = card->fh_buffer.ptr - card->fh_buffer.buf;
2472 #ifdef CSR_WIFI_HIP_NOISY
2473 unifi_error(card->ospriv,
"fh_buffer is at %p, ptr= %p\n",
2474 card->fh_buffer.buf, card->fh_buffer.ptr);
2482 #ifdef CSR_WIFI_HIP_NOISY
2485 dump(card->fh_buffer.buf, len);
2490 if (card->sdio_io_block_pad)
2493 sig_units = card->config_data.sig_frag_size;
2494 data_round = card->sdio_io_block_size;
2496 if (data_round > sig_units)
2498 chunks_in_last_block = (len % data_round) / sig_units;
2500 if (chunks_in_last_block != 0)
2502 padding_chunks = (data_round / sig_units) - chunks_in_last_block;
2504 memset(card->fh_buffer.ptr, 0, padding_chunks * sig_units);
2505 for (i = 0; i < padding_chunks; i++)
2508 card->fh_buffer.ptr += sig_units;
2511 card->fh_buffer.count += padding_chunks;
2512 len += padding_chunks * sig_units;
2518 card->config_data.fromhost_sigbuf_handle,
2519 card->fh_buffer.buf,
2527 unifi_error(card->ospriv,
"Failed to write fh signals: %u bytes, error %d\n", len, r);
2532 card->from_host_signals_w =
2533 (card->from_host_signals_w + card->fh_buffer.count) % 128
u;
2535 (
u8)card->from_host_signals_w);
2538 unifi_error(card->ospriv,
"Failed to write fh signal count %u with error %d\n",
2539 card->from_host_signals_w, r);
2542 card->generate_interrupt = 1;
2545 card->fh_buffer.ptr = card->fh_buffer.buf;
2546 card->fh_buffer.count = 0;
2548 #ifdef CSR_WIFI_HIP_NOISY
2549 unifi_error(card->ospriv,
"END flush: fh len %d, count %d\n",
2550 card->fh_buffer.ptr - card->fh_buffer.buf,
2551 card->fh_buffer.count);
2573 static void restart_packet_flow(
card_t *card)
2586 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_DATA_PLANE_PROFILE)
2587 unifi_debug_log_to_buf(
"U");