24 #include <linux/slab.h>
34 #define MAILBOX1_TIMEOUT 10
35 #define MAILBOX1_ATTEMPTS 200
37 #define MAILBOX2_TIMEOUT 5
38 #define MAILBOX2_ATTEMPTS 10
40 #define RESET_SETTLE_DELAY 25
83 card->ospriv = ospriv;
85 card->unifi_interrupt_seq = 1;
88 card->proc_select = (
u32)(-1);
89 card->dmem_page = (
u32)(-1);
90 card->pmem_page = (
u32)(-1);
92 card->bh_reason_host = 0;
93 card->bh_reason_unifi = 0;
95 for (i = 0; i <
sizeof(card->tx_q_paused_flag) /
sizeof(card->tx_q_paused_flag[0]); i++)
97 card->tx_q_paused_flag[
i] = 0;
99 card->memory_resources_allocated = 0;
115 card->fh_command_queue.q_body = card->fh_command_q_body;
120 card->fh_traffic_queue[
i].q_body = card->fh_traffic_q_body[
i];
128 card->request_coredump_on_reset = 0;
129 card->dump_next_write =
NULL;
130 card->dump_cur_read =
NULL;
131 card->dump_buf =
NULL;
141 if (*((
u8 *)&val) == 0x01)
143 card->lsb =
sizeof(
void *) - 1;
189 r = unifi_hip_init(card);
197 unifi_error(card->ospriv,
"Failed to start host protocol.\n");
263 r = unifi_reset_hardware(card);
270 unifi_error(card->ospriv,
"Failed to reset UniFi\n");
280 unifi_error(card->ospriv,
"Failed to set power save mode\n");
290 card->proc_select = (
u32)(-1);
291 card->dmem_page = (
u32)(-1);
292 card->pmem_page = (
u32)(-1);
300 unifi_error(card->ospriv,
"Failed to write SHARED_DMEM_PAGE\n");
311 unifi_error(card->ospriv,
"Failed to write PROG_MEM2_PAGE\n");
327 r = firmware_present_in_flash(card);
338 unifi_error(card->ospriv,
"Probe for Flash failed\n");
391 unifi_error(card->ospriv,
"Failed to download firmware\n");
430 r = card_hw_init(card);
437 unifi_error(card->ospriv,
"Failed to establish communication with UniFi\n");
441 #ifdef CSR_PRE_ALLOC_NET_DATA
443 prealloc_netdata_free(card);
450 r = card_init_slots(card);
457 unifi_error(card->ospriv,
"Init slots failed: %d\n", r);
512 const u8 *cfg_data_buf)
609 s16 search_4slut_again;
627 search_4slut_again = 0;
637 unifi_error(card->ospriv,
"Firmware hasn't started\n");
673 unifi_error(card->ospriv,
"Failed to read SLUT finger print\n");
680 unifi_error(card->ospriv,
"Failed to find Symbol lookup table fingerprint\n");
691 while (!search_4slut_again)
721 unifi_trace(card->ospriv,
UDBG3,
" found SLUT id %02d.%08lx\n", slut.id, slut.obj);
725 cfg_data = &card->config_data;
741 unifi_error(card->ospriv,
"Failed to read config data\n");
746 _build_sdio_config_data(cfg_data, cfg_data_buf);
755 unifi_error(card->ospriv,
"need to be (queues * x + 2) (UNIFI_RESERVED_COMMAND_SLOTS for commands)\n");
761 if (card->sdio_io_block_pad)
771 "Configuration error: Block size of %d exceeds f/w data_slot_round of %d\n",
781 if ((card->sdio_io_block_size % cfg_data->
sig_frag_size) != 0)
783 unifi_error(card->ospriv,
"Configuration error: Can not pad to-host signals.\n");
788 unifi_info(card->ospriv,
"SDIO block size %d requires %d padding chunks\n",
797 unifi_error(card->ospriv,
"Failed to write To-Host Signal Padding Fragments\n");
820 unifi_error(card->ospriv,
"Failed to read build id\n");
830 sizeof(card->build_id_string));
837 unifi_error(card->ospriv,
"Failed to read build string\n");
855 unifi_error(card->ospriv,
"Failed to write loader load image command\n");
873 unifi_error(card->ospriv,
"Failed to patch firmware\n");
884 unifi_error(card->ospriv,
"Failed to write loader restart command\n");
894 search_4slut_again = 1;
898 card->panic_data_phy_addr = slut.obj;
902 card->panic_data_mac_addr = slut.obj;
910 }
while (search_4slut_again);
913 if (cfg_data ==
NULL)
915 unifi_error(card->ospriv,
"Failed to find SDIO_SLOT_CONFIG Symbol\n");
931 unifi_error(card->ospriv,
"Failed to read init flag at %08lx\n",
932 card->init_flag_addr);
936 if (initialised != 0)
946 major = (cfg_data->
version >> 8) & 0xFF;
947 minor = cfg_data->
version & 0xFF;
948 unifi_info(card->ospriv,
"UniFi f/w protocol version %d.%d (driver %d.%d)\n",
952 unifi_info(card->ospriv,
"Firmware build %u: %s\n",
953 card->build_id, card->build_id_string);
957 unifi_error(card->ospriv,
"UniFi f/w protocol major version (%d) is different from driver (v%d.%d)\n",
959 #ifndef CSR_WIFI_DISABLE_HIP_VERSION_CHECK
966 unifi_error(card->ospriv,
"UniFi f/w protocol version (v%d.%d) is older than minimum required by driver (v%d.%d).\n",
969 #ifndef CSR_WIFI_DISABLE_HIP_VERSION_CHECK
1012 unifi_trace(card->ospriv,
UDBG1,
"waiting for reset to complete, attempt %d\n", i);
1019 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_SDIO_TRACE)
1023 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_SDIO_TRACE)
1026 unifi_debug_log_to_buf(
"error=%X\n", csrResult);
1030 unifi_debug_log_to_buf(
"%X\n", io_enable);
1054 s16 enabled = io_enable & (1 << card->function);
1059 "Reset complete (function %d is disabled) in ~ %u msecs\n",
1067 unifi_error(card->ospriv,
"CsrSdioFunctionEnable failed %d\n", r);
1075 unifi_error(card->ospriv,
"read HIP_HANDSHAKE failed %d\n", r);
1080 unifi_error(card->ospriv,
"MAILBOX2 non-zero after reset (mbox2 = %04x)\n", mbox2);
1091 if (i > MAILBOX2_ATTEMPTS / 4)
1093 unifi_trace(card->ospriv,
UDBG1,
"Failed to read CCCR IO Ready register while polling for reset\n");
1098 unifi_trace(card->ospriv,
UDBG1,
"Failed to read CCCR IO Enable register while polling for reset\n");
1106 unifi_trace(card->ospriv,
UDBG1,
"Timeout waiting for UniFi to complete reset\n");
1144 "Function reset method not supported for chip_id=%d\n",
1153 unifi_trace(card->ospriv,
UDBG1,
"waiting for disable to complete, attempt %d\n", i);
1160 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_SDIO_TRACE)
1164 #if defined (CSR_WIFI_HIP_DEBUG_OFFLINE) && defined (CSR_WIFI_HIP_SDIO_TRACE)
1167 unifi_debug_log_to_buf(
"error=%X\n", csrResult);
1171 unifi_debug_log_to_buf(
"%X\n", io_enable);
1180 s16 enabled = io_enable & (1 << card->function);
1185 "Disable complete (function %d is disabled) in ~ %u msecs\n",
1198 if (i > (MAILBOX2_ATTEMPTS / 4))
1201 "Failed to read CCCR IO Ready register while polling for disable\n");
1209 unifi_trace(card->ospriv,
UDBG1,
"Timeout waiting for UniFi to complete disable\n");
1251 unifi_trace(card->ospriv,
UDBG1,
"waiting for MAILBOX1 to be non-zero...\n");
1262 unifi_warning(card->ospriv,
"Failed to read UniFi Mailbox1 register\n");
1267 unifi_trace(card->ospriv,
UDBG1,
"MAILBOX1 ready (0x%04X) in %u millisecs\n",
1279 unifi_error(card->ospriv,
"Failed to read UniFi Mailbox1 register for second time\n");
1289 if ((i % 100) == 99)
1291 unifi_trace(card->ospriv,
UDBG2,
"MAILBOX1 not ready (0x%X), still trying...\n", mbox1);
1297 unifi_trace(card->ospriv,
UDBG1,
"Timeout waiting for firmware to start, Mailbox1 still 0 after %d ms\n",
1314 unifi_error(card->ospriv,
"Failed to write f/w startup handshake to MAILBOX2\n");
1332 unifi_error(card->ospriv,
"Failed to read UniFi Mailbox0 register\n");
1337 *paddr = (((
u32)mbox1 << 16) | mbox0);
1366 if (!card->panic_data_phy_addr || !card->panic_data_mac_addr)
1380 unifi_info(card->ospriv,
"Unable to read panic codes");
1414 if (!card->chip_version)
1416 unifi_info(card->ospriv,
"Unknown chip version\n");
1428 unifi_error(card->ospriv,
"unifi_set_host_state() failed %d\n", r);
1433 for (i = 0; i < 3; i++)
1438 unifi_info(card->ospriv,
"Failed to read valid chip version sr=%d (0x%04x want 0x%04x) try %d\n",
1439 sr, data_u16, card->chip_version, i);
1445 unifi_error(card->ospriv,
"CsrSdioMaxBusClockFrequencySet() failed1 %d\n", sr);
1453 unifi_info(card->ospriv,
"Try function enable\n");
1458 unifi_error(card->ospriv,
"CsrSdioFunctionEnable failed %d (HIP %d)\n", sr, r);
1474 unifi_error(card->ospriv,
"unifi_set_host_state() failed2 %d\n", r);
1483 unifi_error(card->ospriv,
"CsrSdioMaxBusClockFrequencySet() failed2 %d\n", sr);
1502 unifi_error(card->ospriv,
"unifi_card_hard_reset() failed %d\n", r);
1509 unifi_info(card->ospriv,
"Read chip version 0x%x after %d retries\n", data_u16, i);
1544 if (!card->panic_data_phy_addr || !card->panic_data_mac_addr)
1553 unifi_error(card->ospriv,
"capture_panic: unifi_read16 %08x failed %d\n", card->panic_data_phy_addr, r);
1561 unifi_error(card->ospriv,
"capture_panic: unifi_read16 %08x failed %d\n", card->panic_data_phy_addr + 2, r);
1563 unifi_error(card->ospriv,
"Last UniFi PHY PANIC %04x arg %04x\n", p_code, p_arg);
1564 card->last_phy_panic_code = p_code;
1565 card->last_phy_panic_arg = p_arg;
1572 unifi_error(card->ospriv,
"capture_panic: unifi_read16 %08x failed %d\n", card->panic_data_mac_addr, r);
1580 unifi_error(card->ospriv,
"capture_panic: unifi_read16 %08x failed %d\n", card->panic_data_mac_addr + 2, r);
1582 unifi_error(card->ospriv,
"Last UniFi MAC PANIC %04x arg %04x\n", p_code, p_arg);
1583 card->last_mac_panic_code = p_code;
1584 card->last_mac_panic_arg = p_arg;
1613 card->fh_command_queue.q_rd_ptr = 0;
1614 card->fh_command_queue.q_wr_ptr = 0;
1619 card->fh_traffic_queue[
i].q_rd_ptr = 0;
1620 card->fh_traffic_queue[
i].q_wr_ptr = 0;
1624 #ifndef CSR_WIFI_HIP_TA_DISABLE
1628 cfg_data = &card->config_data;
1634 if (card->fh_buffer.buf ==
NULL)
1636 unifi_error(card->ospriv,
"Failed to allocate memory for F-H signals\n");
1641 card->fh_buffer.ptr = card->fh_buffer.buf;
1642 card->fh_buffer.count = 0;
1645 if (card->th_buffer.buf ==
NULL)
1647 unifi_error(card->ospriv,
"Failed to allocate memory for T-H signals\n");
1652 card->th_buffer.ptr = card->th_buffer.buf;
1653 card->th_buffer.count = 0;
1665 unifi_trace(card->ospriv,
UDBG3,
"Alloc from-host resources, %d slots.\n", n);
1667 if (card->from_host_data ==
NULL)
1669 unifi_error(card->ospriv,
"Failed to allocate memory for F-H bulk data array\n");
1675 for (i = 0; i <
n; i++)
1683 if (card->fh_slot_host_tag_record ==
NULL)
1685 unifi_error(card->ospriv,
"Failed to allocate memory for F-H slot host tag mapping array\n");
1691 for (i = 0; i <
n; i++)
1700 unifi_trace(card->ospriv,
UDBG3,
"Alloc to-host resources, %d slots.\n", n);
1702 if (card->to_host_data ==
NULL)
1704 unifi_error(card->ospriv,
"Failed to allocate memory for T-H bulk data array\n");
1710 for (i = 0; i <
n; i++)
1737 card->memory_resources_allocated = 1;
1782 static void card_free_memory_resources(
card_t *card)
1792 kfree(card->to_host_data);
1793 card->to_host_data =
NULL;
1795 kfree(card->from_host_data);
1796 card->from_host_data =
NULL;
1799 kfree(card->fh_slot_host_tag_record);
1800 card->fh_slot_host_tag_record =
NULL;
1802 kfree(card->fh_buffer.buf);
1803 card->fh_buffer.ptr = card->fh_buffer.buf =
NULL;
1804 card->fh_buffer.bufsize = 0;
1805 card->fh_buffer.count = 0;
1807 kfree(card->th_buffer.buf);
1808 card->th_buffer.ptr = card->th_buffer.buf =
NULL;
1809 card->th_buffer.bufsize = 0;
1810 card->th_buffer.count = 0;
1813 card->memory_resources_allocated = 0;
1819 static void card_init_soft_queues(
card_t *card)
1825 unifi_trace(card->ospriv,
UDBG1,
"Initialising internal signal queues.\n");
1827 card->fh_command_queue.q_rd_ptr = 0;
1828 card->fh_command_queue.q_wr_ptr = 0;
1833 card->fh_traffic_queue[
i].q_rd_ptr = 0;
1834 card->fh_traffic_queue[
i].q_wr_ptr = 0;
1838 #ifndef CSR_WIFI_HIP_TA_DISABLE
1865 if (card->to_host_data)
1872 n = card->config_data.num_tohost_data_slots;
1873 unifi_trace(card->ospriv,
UDBG3,
"Freeing to-host resources, %d slots.\n", n);
1874 for (i = 0; i <
n; i++)
1876 unifi_free_bulk_data(card, &card->to_host_data[i]);
1884 if (card->from_host_data)
1887 n = card->config_data.num_fromhost_data_slots;
1888 unifi_trace(card->ospriv,
UDBG3,
"Freeing from-host resources, %d slots.\n", n);
1889 for (i = 0; i <
n; i++)
1891 unifi_free_bulk_data(card, &card->from_host_data[i].bd);
1896 card->dynamic_slot_data.from_host_used_slots[
i] = 0;
1897 card->dynamic_slot_data.from_host_max_slots[
i] = 0;
1898 card->dynamic_slot_data.from_host_reserved_slots[
i] = 0;
1912 unifi_free_bulk_data(card, &card->fh_command_q_body[i].bulkdata[r]);
1923 unifi_free_bulk_data(card, &card->fh_traffic_q_body[n][i].bulkdata[r]);
1928 card_init_soft_queues(card);
1955 #ifdef CSR_PRE_ALLOC_NET_DATA
1956 prealloc_netdata_free(card);
1959 card_free_memory_resources(card);
1964 unifi_error(card->ospriv,
"Caller should call unifi_coredump_free()\n");
1995 if (card->memory_resources_allocated == 1)
1997 card_free_memory_resources(card);
2002 card_init_soft_queues(card);
2005 r = card_allocate_memory_resources(card);
2008 unifi_error(card->ospriv,
"Failed to allocate card memory resources.\n");
2009 card_free_memory_resources(card);
2014 if (card->sdio_ctrl_addr == 0)
2016 unifi_error(card->ospriv,
"Failed to find config struct!\n");
2025 card->from_host_data_head = 0;
2039 unifi_error(card->ospriv,
"Failed to read from-host sig written count\n");
2043 card->from_host_signals_w = (
s16)s;
2053 unifi_error(card->ospriv,
"Failed to read to-host sig read count\n");
2057 card->to_host_signals_r = (
s16)s;
2068 unifi_error(card->ospriv,
"Failed to write initialised flag\n");
2078 card->dynamic_slot_data.from_host_max_slots[
i] = card->config_data.num_fromhost_data_slots -
2080 card->dynamic_slot_data.queue_stable[
i] =
FALSE;
2112 if (card->udi_hook ==
NULL)
2114 card->udi_hook = udi_fn;
2143 if (card->udi_hook == udi_fn)
2145 card->udi_hook =
NULL;
2152 static void CardReassignDynamicReservation(
card_t *card)
2159 card->dynamic_slot_data.packets_txed[0],
2160 card->dynamic_slot_data.packets_txed[1],
2161 card->dynamic_slot_data.packets_txed[2],
2162 card->dynamic_slot_data.packets_txed[3]);
2167 card->dynamic_slot_data.queue_stable[
i] =
FALSE;
2168 card->dynamic_slot_data.from_host_reserved_slots[
i] = 0;
2169 card->dynamic_slot_data.from_host_max_slots[
i] = card->config_data.num_fromhost_data_slots -
2171 card->dynamic_slot_data.packets_txed[
i] = 0;
2173 unifi_trace(card->ospriv,
UDBG5,
"CardReassignDynamicReservation: queue %d reserved %d Max %d\n", i,
2174 card->dynamic_slot_data.from_host_reserved_slots[i],
2175 card->dynamic_slot_data.from_host_max_slots[i]);
2178 card->dynamic_slot_data.total_packets_txed = 0;
2203 u16 q_len, active_queues = 0, excess_queue_slots, div_extra_slots,
2204 queue_fair_share, reserved_slots = 0,
q, excess_need_queues = 0, unmovable_slots = 0;
2212 sigq = &card->fh_traffic_queue[queue];
2215 if (q_len <= card->dynamic_slot_data.from_host_reserved_slots[queue])
2217 unifi_trace(card->ospriv,
UDBG5,
"queue %d q_len %d already has that many reserved slots, exiting\n", queue, q_len);
2223 if (q_len > num_data_slots)
2225 q_len = num_data_slots;
2230 if (i != (
s32)queue)
2232 reserved_slots += card->dynamic_slot_data.from_host_reserved_slots[
i];
2234 if ((i == (
s32)queue) || (card->dynamic_slot_data.from_host_reserved_slots[i] > 0))
2240 unifi_trace(card->ospriv,
UDBG5,
"CardCheckDynamicReservation: queue %d q_len %d\n", queue, q_len);
2241 unifi_trace(card->ospriv,
UDBG5,
"Active queues %d reserved slots on other queues %d\n",
2242 active_queues, reserved_slots);
2244 if (reserved_slots + q_len <= num_data_slots)
2246 card->dynamic_slot_data.from_host_reserved_slots[queue] =
q_len;
2247 if (q_len == num_data_slots)
2250 card->dynamic_slot_data.queue_stable[queue] =
TRUE;
2255 queue_fair_share = num_data_slots / active_queues;
2256 unifi_trace(card->ospriv,
UDBG5,
"queue fair share %d\n", queue_fair_share);
2262 card->dynamic_slot_data.from_host_reserved_slots[queue] =
q_len;
2266 if (card->dynamic_slot_data.from_host_reserved_slots[i] > queue_fair_share)
2268 excess_need_queues++;
2272 unmovable_slots += card->dynamic_slot_data.from_host_reserved_slots[
i];
2276 unifi_trace(card->ospriv,
UDBG5,
"Excess need queues %d\n", excess_need_queues);
2279 excess_queue_slots = (num_data_slots - unmovable_slots) / excess_need_queues;
2280 div_extra_slots = (num_data_slots - unmovable_slots) - excess_queue_slots * excess_need_queues;
2281 for (i = UNIFI_NO_OF_TX_QS - 1; i >= 0; i--)
2283 if (card->dynamic_slot_data.from_host_reserved_slots[i] > excess_queue_slots)
2285 card->dynamic_slot_data.from_host_reserved_slots[
i] = excess_queue_slots;
2286 if (div_extra_slots > 0)
2288 card->dynamic_slot_data.from_host_reserved_slots[
i]++;
2292 card->dynamic_slot_data.queue_stable[
i] =
TRUE;
2306 reserved_slots += card->dynamic_slot_data.from_host_reserved_slots[
q];
2310 card->dynamic_slot_data.from_host_max_slots[
i] = num_data_slots - reserved_slots;
2312 card->dynamic_slot_data.from_host_reserved_slots[i],
2313 card->dynamic_slot_data.from_host_max_slots[i]);
2336 u8 queue = card->from_host_data[
slot].queue;
2337 const void *os_data_ptr = card->from_host_data[
slot].bd.os_data_ptr;
2341 if (card->from_host_data[slot].bd.data_length == 0)
2344 "Surprise: request to clear an already free FH data slot: %d\n",
2350 if (os_data_ptr ==
NULL)
2353 "Clearing FH data slot %d: has null payload, len=%d\n",
2354 slot, card->from_host_data[slot].bd.data_length);
2359 unifi_free_bulk_data(card, &card->from_host_data[slot].bd);
2360 if (queue < UNIFI_NO_OF_TX_QS)
2362 if (card->dynamic_slot_data.from_host_used_slots[queue] == 0)
2364 unifi_error(card->ospriv,
"Goofed up used slots q = %d used slots = %d\n",
2366 card->dynamic_slot_data.from_host_used_slots[queue]);
2370 card->dynamic_slot_data.from_host_used_slots[queue]--;
2372 card->dynamic_slot_data.packets_txed[queue]++;
2373 card->dynamic_slot_data.total_packets_txed++;
2374 if (card->dynamic_slot_data.total_packets_txed >= card->dynamic_slot_data.packets_interval)
2376 CardReassignDynamicReservation(card);
2380 unifi_trace(card->ospriv,
UDBG4,
"CardClearFromHostDataSlot: slot %d recycled %p\n", slot, os_data_ptr);
2386 #ifdef CSR_WIFI_REQUEUE_PACKET_TO_HAL
2401 void CardClearFromHostDataSlotWithoutFreeingBulkData(
card_t *card,
const s16 slot)
2403 u8 queue = card->from_host_data[
slot].queue;
2410 queue = card->from_host_data[
slot].queue;
2412 if (queue < UNIFI_NO_OF_TX_QS)
2414 if (card->dynamic_slot_data.from_host_used_slots[queue] == 0)
2416 unifi_error(card->ospriv,
"Goofed up used slots q = %d used slots = %d\n",
2418 card->dynamic_slot_data.from_host_used_slots[queue]);
2422 card->dynamic_slot_data.from_host_used_slots[queue]--;
2424 card->dynamic_slot_data.packets_txed[queue]++;
2425 card->dynamic_slot_data.total_packets_txed++;
2426 if (card->dynamic_slot_data.total_packets_txed >=
2427 card->dynamic_slot_data.packets_interval)
2429 CardReassignDynamicReservation(card);
2439 return card->config_data.data_slot_size;
2463 for (i = 0; i < card->config_data.num_fromhost_data_slots; i++)
2465 if (card->from_host_data[i].bd.data_length == 0)
2495 for (i = 0; i < card->config_data.num_fromhost_data_slots; i++)
2497 if (card->from_host_data[i].bd.data_length != 0)
2511 card->chip_id = card->sdio_if->sdioId.cardId;
2512 card->function = card->sdio_if->sdioId.sdioFunction;
2513 card->sdio_io_block_size = card->sdio_if->blockSize;
2528 unifi_info(card->ospriv,
"Chip ID 0x%02X Function %u Block Size %u Name %s(%s)\n",
2529 card->chip_id, card->function, card->sdio_io_block_size,
2530 ChipHelper_MarketingName(card->helper),
2531 ChipHelper_FriendlyName(card->helper));
2546 r = unifi_identify_hw(card);
2553 unifi_error(card->ospriv,
"Failed to identify hw\n");
2559 "%s mode SDIO\n", card->sdio_io_block_pad?
"Block" :
"Byte");
2598 unifi_error(card->ospriv,
"Failed to re-enable function %d.\n", card->function);
2607 bootstrap_chip_hw(card);
2610 r = unifi_read_chip_version(card);
2624 u32 gbl_chip_version;
2630 gbl_chip_version = ChipHelper_GBL_CHIP_VERSION(card->helper);
2633 if (gbl_chip_version != 0)
2642 unifi_error(card->ospriv,
"Failed to read GBL_CHIP_VERSION\n");
2646 card->chip_version =
ver;
2650 unifi_info(card->ospriv,
"Unknown Chip ID, cannot locate GBL_CHIP_VERSION\n");
2654 unifi_info(card->ospriv,
"Chip Version 0x%04X\n", card->chip_version);
2690 r = unifi_prepare_hw(card);
2699 unifi_info(card->ospriv,
"Calling CsrSdioHardReset\n");
2703 unifi_info(card->ospriv,
"CsrSdioHardReset succeeded on reseting UniFi\n");
2704 r = unifi_prepare_hw(card);
2711 unifi_error(card->ospriv,
"unifi_prepare_hw failed after hard reset\n");
2723 unifi_info(card->ospriv,
"Falling back to software hard reset\n");
2731 unifi_error(card->ospriv,
"software hard reset failed\n");
2740 if (card->chip_version == 0)
2742 r = unifi_read_chip_version(card);
2751 #ifdef CSR_WIFI_HIP_SDIO_BLOCK_SIZE
2760 if (card->sdio_if->blockSize != new_block_size)
2763 "Actually got block size %d\n", card->sdio_if->blockSize);
2771 if (card->sdio_if->blockSize == 0)
2773 unifi_info(card->ospriv,
"Block size 0, block mode not available\n");
2779 card->sdio_io_block_size = 1;
2784 unifi_error(card->ospriv,
"Requires byte mode\n");
2791 card->sdio_io_block_size = card->sdio_if->blockSize;
2837 unifi_warning(card->ospriv,
"SDIO error writing IO_ENABLE: %d\n", r);
2844 r = card_wait_for_unifi_to_disable(card);
2852 r = card_wait_for_unifi_to_reset(card);
2871 unifi_warning(card->ospriv,
"SDIO error writing SDIO_CSR_FUNC_EN: %d\n", r);
2880 r = card_wait_for_unifi_to_reset(card);
2890 unifi_warning(card->ospriv,
"card_reset_method_io_enable failed to reset UniFi\n");
2932 unifi_error(card->ospriv,
"Failed to set UNIFI_HOST_STATE_DROWSY\n");
2946 unifi_error(card->ospriv,
"Can't stop processors\n");
2965 unifi_warning(card->ospriv,
"SDIO error writing DBG_RESET: %d\n", r);
2973 r = card_wait_for_unifi_to_reset(card);
2980 unifi_warning(card->ospriv,
"card_reset_method_dbg_reset failed to reset UniFi\n");
3014 card->proc_select = (
u32)(-1);
3015 card->dmem_page = (
u32)(-1);
3016 card->pmem_page = (
u32)(-1);
3023 r = unifi_identify_hw(card);
3030 unifi_error(card->ospriv,
"unifi_card_hard_reset failed to identify h/w\n");
3040 "Hard reset (Code download) is unsupported\n");
3054 r = card_reset_method_io_enable(card);
3067 r = card_reset_method_dbg_reset(card);
3105 (
u8)card->unifi_interrupt_seq);
3110 ChipHelper_SHARED_IO_INTERRUPT(card->helper) * 2,
3111 (
u8)card->unifi_interrupt_seq);
3119 unifi_error(card->ospriv,
"SDIO error writing UNIFI_SHARED_IO_INTERRUPT: %d\n", r);
3124 card->unifi_interrupt_seq++;
3158 unifi_error(card->ospriv,
"SDIO error reading SDIO_INT_ENABLE\n");
3171 unifi_error(card->ospriv,
"SDIO error writing SDIO_INT_ENABLE\n");
3206 unifi_error(card->ospriv,
"SDIO error reading SDIO_INT_ENABLE\n");
3210 int_enable &= ~(1 << card->function);
3219 unifi_error(card->ospriv,
"SDIO error writing SDIO_INT_ENABLE\n");
3259 unifi_error(card->ospriv,
"SDIO error reading SDIO_INT_PENDING\n");
3263 *pintr = (pending & (1 << card->function))?
TRUE :
FALSE;
3305 unifi_error(card->ospriv,
"SDIO error writing SDIO_CSR_HOST_INT_CLEAR\n");
3311 ChipHelper_SDIO_HOST_INT(card->helper) * 2,
3319 unifi_error(card->ospriv,
"SDIO error writing UNIFI_SDIO_HOST_INT\n");
3357 unifi_error(card->ospriv,
"SDIO error reading SDIO_INT_ENABLE\n");
3361 *enabled = (int_enable & (1 << card->function))?
TRUE :
FALSE;
3387 u8 *packed_sigptr, num_slots_required = 0;
3398 num_slots_required++;
3403 if (num_slots_required != 0)
3409 for (i = 0; i < card->config_data.num_fromhost_data_slots; i++)
3411 if (card->from_host_data[h].bd.data_length == 0)
3415 if (j == num_slots_required)
3421 if (++h >= card->config_data.num_fromhost_data_slots)
3429 if (card->dynamic_slot_data.from_host_used_slots[queue]
3430 < card->dynamic_slot_data.from_host_max_slots[queue])
3435 h = card->from_host_data_head;
3437 for (i = 0; i < nslots; i++)
3439 if (card->from_host_data[h].bd.data_length == 0)
3443 if (j == num_slots_required)
3454 card->from_host_data_head =
h;
3459 if (j != num_slots_required)
3461 unifi_trace(card->ospriv,
UDBG5,
"CardWriteBulkData: didn't find free slot/s\n");
3466 CardCheckDynamicReservation(card, queue);
3469 for (i = 0; i < card->config_data.num_fromhost_data_slots; i++)
3471 unifi_trace(card->ospriv,
UDBG5,
"fh data slot %d: %d\n", i, card->from_host_data[i].bd.data_length);
3478 packed_sigptr = csptr->
sigbuf;
3500 card->from_host_data[slots[
j]].bd.os_data_ptr = bulkdata[
i].
os_data_ptr;
3501 card->from_host_data[slots[
j]].bd.os_net_buf_ptr = bulkdata[
i].
os_net_buf_ptr;
3502 card->from_host_data[slots[
j]].bd.data_length = bulkdata[
i].
data_length;
3503 card->from_host_data[slots[
j]].bd.net_buf_length = bulkdata[
i].
net_buf_length;
3504 card->from_host_data[slots[
j]].queue = queue;
3506 unifi_trace(card->ospriv,
UDBG4,
"CardWriteBulkData sig=0x%x, fh slot %d = %p\n",
3512 if (!bulkdata[i].os_data_ptr)
3514 unifi_error(card->ospriv,
"Assign null os_data_ptr (len=%d) fh slot %d, i=%d, q=%d, sig=0x%x",
3519 if (queue < UNIFI_NO_OF_TX_QS)
3521 card->dynamic_slot_data.from_host_used_slots[queue]++;
3557 bd = &card->to_host_data[
sn];
3561 bd = &card->from_host_data[
sn].bd;
3593 if (ChipHelper_HasRom(card->helper))
3597 if (!ChipHelper_HasFlash(card->helper))
3620 if ((m1 == 0x0008) || (m1 == 0xFFFF) ||
3621 (m1 == 0x0004) || (m5 == 0x0004) ||
3622 (m5 == 0x0008) || (m5 == 0xFFFF))
3646 static void bootstrap_chip_hw(
card_t *card)
3650 void *sdio = card->sdio_if;
3656 for (i = 0; i < len; i++)
3661 unifi_warning(card->ospriv,
"Failed to write bootstrap value %d\n", i);
3709 ChipHelper_DBG_HOST_STOP_STATUS(card->helper) * 2,
3716 if ((status & 1) == 1)
3728 unifi_error(card->ospriv,
"Failed to stop processors: SDIO error\n");
3733 unifi_error(card->ospriv,
"Failed to stop processors: timeout waiting for stopped status\n");
3763 unifi_error(card->ospriv,
"unifi_set_proc_select failed: %d.\n", r);
3769 ChipHelper_DBG_EMU_CMD(card->helper) * 2, 8);
3776 ChipHelper_DBG_EMU_CMD(card->helper) * 2, 0);
3804 unifi_info(card->ospriv,
"Scheduled interrupt mode");
3806 card->intmode =
mode;
3846 card->request_max_clock = 1;
3884 static const char *
const states[] = {
3885 "AWAKE",
"DROWSY",
"TORPID"
3887 static const u8 state_csr_host_wakeup[] = {
3890 static const u8 state_io_abort[] = {
3895 states[card->host_state], states[state]);
3906 (
u8)((card->function << 4) | state_csr_host_wakeup[state]));
3919 unifi_error(card->ospriv,
"Failed to write UniFi deep sleep state\n");
3936 "Failed to increase the SDIO clock speed\n");
3948 card->host_state =
state;
3962 "Failed to decrease the SDIO clock speed\n");
3992 card_info->
chip_id = card->chip_id;
3994 card_info->
fw_build = card->build_id;
4031 unifi_error(card->ospriv,
"Failed to read SDIO_IO_ENABLE to check for spontaneous reset\n");
4035 if ((io_en & (1 << card->function)) == 0)
4039 unifi_error(card->ospriv,
"UniFi has spontaneously reset.\n");
4048 unifi_error(card->ospriv,
"Failed to read to-host sig written count\n");
4052 unifi_error(card->ospriv,
"thsw: %u (driver thinks is %u)\n",
4053 fw_count, card->to_host_signals_w);
4058 unifi_error(card->ospriv,
"Failed to read from-host sig read count\n");
4062 unifi_error(card->ospriv,
"fhsr: %u (driver thinks is %u)\n",
4063 fw_count, card->from_host_signals_r);
4069 unifi_info(card->ospriv,
"UniFi function %d is enabled.\n", card->function);
4075 unifi_error(card->ospriv,
"There is an unhandled pending interrupt.\n");
4095 nslots = card->config_data.num_fromhost_data_slots;
4097 for (i = 0; i < nslots; i++)
4099 if (card->from_host_data[i].bd.data_length == 0)
4107 sigq = &card->fh_traffic_queue[
i];
4119 unifi_error(card->ospriv,
"Failed to read from-host sig read count - %d\n", count_fhr);
4124 occupied_fh = (card->from_host_signals_w - count_fhr) % 128;
4126 hipqosinfo->
free_fh_fw_slots = (
u16)(card->config_data.num_fromhost_sig_frags - occupied_fh);
4156 unifi_warning(card->ospriv,
"Unrecognised csrResult error code: %d\n", csrResult);