wl1251.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * This file is part of wl12xx
  3. *
  4. * Copyright (C) 2008-2009 Nokia Corporation
  5. *
  6. * Contact: Kalle Valo <kalle.valo@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include "wl1251.h"
  26. #include "reg.h"
  27. #include "spi.h"
  28. #include "boot.h"
  29. #include "event.h"
  30. #include "acx.h"
  31. #include "tx.h"
  32. #include "rx.h"
  33. #include "ps.h"
  34. #include "init.h"
  35. static struct wl12xx_partition_set wl1251_part_table[PART_TABLE_LEN] = {
  36. [PART_DOWN] = {
  37. .mem = {
  38. .start = 0x00000000,
  39. .size = 0x00016800
  40. },
  41. .reg = {
  42. .start = REGISTERS_BASE,
  43. .size = REGISTERS_DOWN_SIZE
  44. },
  45. },
  46. [PART_WORK] = {
  47. .mem = {
  48. .start = 0x00028000,
  49. .size = 0x00014000
  50. },
  51. .reg = {
  52. .start = REGISTERS_BASE,
  53. .size = REGISTERS_WORK_SIZE
  54. },
  55. },
  56. /* WL1251 doesn't use the DRPW partition, so we don't set it here */
  57. };
  58. static enum wl12xx_acx_int_reg wl1251_acx_reg_table[ACX_REG_TABLE_LEN] = {
  59. [ACX_REG_INTERRUPT_TRIG] = (REGISTERS_BASE + 0x0474),
  60. [ACX_REG_INTERRUPT_TRIG_H] = (REGISTERS_BASE + 0x0478),
  61. [ACX_REG_INTERRUPT_MASK] = (REGISTERS_BASE + 0x0494),
  62. [ACX_REG_HINT_MASK_SET] = (REGISTERS_BASE + 0x0498),
  63. [ACX_REG_HINT_MASK_CLR] = (REGISTERS_BASE + 0x049C),
  64. [ACX_REG_INTERRUPT_NO_CLEAR] = (REGISTERS_BASE + 0x04B0),
  65. [ACX_REG_INTERRUPT_CLEAR] = (REGISTERS_BASE + 0x04A4),
  66. [ACX_REG_INTERRUPT_ACK] = (REGISTERS_BASE + 0x04A8),
  67. [ACX_REG_SLV_SOFT_RESET] = (REGISTERS_BASE + 0x0000),
  68. [ACX_REG_EE_START] = (REGISTERS_BASE + 0x080C),
  69. [ACX_REG_ECPU_CONTROL] = (REGISTERS_BASE + 0x0804)
  70. };
  71. static int wl1251_upload_firmware(struct wl12xx *wl)
  72. {
  73. struct wl12xx_partition_set *p_table = wl->chip.p_table;
  74. int addr, chunk_num, partition_limit;
  75. size_t fw_data_len;
  76. u8 *p;
  77. /* whal_FwCtrl_LoadFwImageSm() */
  78. wl12xx_debug(DEBUG_BOOT, "chip id before fw upload: 0x%x",
  79. wl12xx_reg_read32(wl, CHIP_ID_B));
  80. /* 10.0 check firmware length and set partition */
  81. fw_data_len = (wl->fw[4] << 24) | (wl->fw[5] << 16) |
  82. (wl->fw[6] << 8) | (wl->fw[7]);
  83. wl12xx_debug(DEBUG_BOOT, "fw_data_len %zu chunk_size %d", fw_data_len,
  84. CHUNK_SIZE);
  85. if ((fw_data_len % 4) != 0) {
  86. wl12xx_error("firmware length not multiple of four");
  87. return -EIO;
  88. }
  89. wl12xx_set_partition(wl,
  90. p_table[PART_DOWN].mem.start,
  91. p_table[PART_DOWN].mem.size,
  92. p_table[PART_DOWN].reg.start,
  93. p_table[PART_DOWN].reg.size);
  94. /* 10.1 set partition limit and chunk num */
  95. chunk_num = 0;
  96. partition_limit = p_table[PART_DOWN].mem.size;
  97. while (chunk_num < fw_data_len / CHUNK_SIZE) {
  98. /* 10.2 update partition, if needed */
  99. addr = p_table[PART_DOWN].mem.start +
  100. (chunk_num + 2) * CHUNK_SIZE;
  101. if (addr > partition_limit) {
  102. addr = p_table[PART_DOWN].mem.start +
  103. chunk_num * CHUNK_SIZE;
  104. partition_limit = chunk_num * CHUNK_SIZE +
  105. p_table[PART_DOWN].mem.size;
  106. wl12xx_set_partition(wl,
  107. addr,
  108. p_table[PART_DOWN].mem.size,
  109. p_table[PART_DOWN].reg.start,
  110. p_table[PART_DOWN].reg.size);
  111. }
  112. /* 10.3 upload the chunk */
  113. addr = p_table[PART_DOWN].mem.start + chunk_num * CHUNK_SIZE;
  114. p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
  115. wl12xx_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
  116. p, addr);
  117. wl12xx_spi_mem_write(wl, addr, p, CHUNK_SIZE);
  118. chunk_num++;
  119. }
  120. /* 10.4 upload the last chunk */
  121. addr = p_table[PART_DOWN].mem.start + chunk_num * CHUNK_SIZE;
  122. p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
  123. wl12xx_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x",
  124. fw_data_len % CHUNK_SIZE, p, addr);
  125. wl12xx_spi_mem_write(wl, addr, p, fw_data_len % CHUNK_SIZE);
  126. return 0;
  127. }
  128. static int wl1251_upload_nvs(struct wl12xx *wl)
  129. {
  130. size_t nvs_len, nvs_bytes_written, burst_len;
  131. int nvs_start, i;
  132. u32 dest_addr, val;
  133. u8 *nvs_ptr, *nvs;
  134. nvs = wl->nvs;
  135. if (nvs == NULL)
  136. return -ENODEV;
  137. nvs_ptr = nvs;
  138. nvs_len = wl->nvs_len;
  139. nvs_start = wl->fw_len;
  140. /*
  141. * Layout before the actual NVS tables:
  142. * 1 byte : burst length.
  143. * 2 bytes: destination address.
  144. * n bytes: data to burst copy.
  145. *
  146. * This is ended by a 0 length, then the NVS tables.
  147. */
  148. while (nvs_ptr[0]) {
  149. burst_len = nvs_ptr[0];
  150. dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
  151. /* We move our pointer to the data */
  152. nvs_ptr += 3;
  153. for (i = 0; i < burst_len; i++) {
  154. val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
  155. | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
  156. wl12xx_debug(DEBUG_BOOT,
  157. "nvs burst write 0x%x: 0x%x",
  158. dest_addr, val);
  159. wl12xx_mem_write32(wl, dest_addr, val);
  160. nvs_ptr += 4;
  161. dest_addr += 4;
  162. }
  163. }
  164. /*
  165. * We've reached the first zero length, the first NVS table
  166. * is 7 bytes further.
  167. */
  168. nvs_ptr += 7;
  169. nvs_len -= nvs_ptr - nvs;
  170. nvs_len = ALIGN(nvs_len, 4);
  171. /* Now we must set the partition correctly */
  172. wl12xx_set_partition(wl, nvs_start,
  173. wl->chip.p_table[PART_DOWN].mem.size,
  174. wl->chip.p_table[PART_DOWN].reg.start,
  175. wl->chip.p_table[PART_DOWN].reg.size);
  176. /* And finally we upload the NVS tables */
  177. nvs_bytes_written = 0;
  178. while (nvs_bytes_written < nvs_len) {
  179. val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
  180. | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
  181. val = cpu_to_le32(val);
  182. wl12xx_debug(DEBUG_BOOT,
  183. "nvs write table 0x%x: 0x%x",
  184. nvs_start, val);
  185. wl12xx_mem_write32(wl, nvs_start, val);
  186. nvs_ptr += 4;
  187. nvs_bytes_written += 4;
  188. nvs_start += 4;
  189. }
  190. return 0;
  191. }
  192. static int wl1251_boot(struct wl12xx *wl)
  193. {
  194. int ret = 0, minor_minor_e2_ver;
  195. u32 tmp, boot_data;
  196. ret = wl12xx_boot_soft_reset(wl);
  197. if (ret < 0)
  198. goto out;
  199. /* 2. start processing NVS file */
  200. ret = wl->chip.op_upload_nvs(wl);
  201. if (ret < 0)
  202. goto out;
  203. /* write firmware's last address (ie. it's length) to
  204. * ACX_EEPROMLESS_IND_REG */
  205. wl12xx_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len);
  206. /* 6. read the EEPROM parameters */
  207. tmp = wl12xx_reg_read32(wl, SCR_PAD2);
  208. /* 7. read bootdata */
  209. wl->boot_attr.radio_type = (tmp & 0x0000FF00) >> 8;
  210. wl->boot_attr.major = (tmp & 0x00FF0000) >> 16;
  211. tmp = wl12xx_reg_read32(wl, SCR_PAD3);
  212. /* 8. check bootdata and call restart sequence */
  213. wl->boot_attr.minor = (tmp & 0x00FF0000) >> 16;
  214. minor_minor_e2_ver = (tmp & 0xFF000000) >> 24;
  215. wl12xx_debug(DEBUG_BOOT, "radioType 0x%x majorE2Ver 0x%x "
  216. "minorE2Ver 0x%x minor_minor_e2_ver 0x%x",
  217. wl->boot_attr.radio_type, wl->boot_attr.major,
  218. wl->boot_attr.minor, minor_minor_e2_ver);
  219. ret = wl12xx_boot_init_seq(wl);
  220. if (ret < 0)
  221. goto out;
  222. /* 9. NVS processing done */
  223. boot_data = wl12xx_reg_read32(wl, ACX_REG_ECPU_CONTROL);
  224. wl12xx_debug(DEBUG_BOOT, "halt boot_data 0x%x", boot_data);
  225. /* 10. check that ECPU_CONTROL_HALT bits are set in
  226. * pWhalBus->uBootData and start uploading firmware
  227. */
  228. if ((boot_data & ECPU_CONTROL_HALT) == 0) {
  229. wl12xx_error("boot failed, ECPU_CONTROL_HALT not set");
  230. ret = -EIO;
  231. goto out;
  232. }
  233. ret = wl->chip.op_upload_fw(wl);
  234. if (ret < 0)
  235. goto out;
  236. /* 10.5 start firmware */
  237. ret = wl12xx_boot_run_firmware(wl);
  238. if (ret < 0)
  239. goto out;
  240. /* Get and save the firmware version */
  241. wl12xx_acx_fw_version(wl, wl->chip.fw_ver, sizeof(wl->chip.fw_ver));
  242. out:
  243. return ret;
  244. }
  245. static int wl1251_mem_cfg(struct wl12xx *wl)
  246. {
  247. struct wl1251_acx_config_memory mem_conf;
  248. int ret, i;
  249. wl12xx_debug(DEBUG_ACX, "wl1251 mem cfg");
  250. /* memory config */
  251. mem_conf.mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
  252. mem_conf.mem_config.rx_mem_block_num = 35;
  253. mem_conf.mem_config.tx_min_mem_block_num = 64;
  254. mem_conf.mem_config.num_tx_queues = MAX_TX_QUEUES;
  255. mem_conf.mem_config.host_if_options = HOSTIF_PKT_RING;
  256. mem_conf.mem_config.num_ssid_profiles = 1;
  257. mem_conf.mem_config.debug_buffer_size =
  258. cpu_to_le16(TRACE_BUFFER_MAX_SIZE);
  259. /* RX queue config */
  260. mem_conf.rx_queue_config.dma_address = 0;
  261. mem_conf.rx_queue_config.num_descs = ACX_RX_DESC_DEF;
  262. mem_conf.rx_queue_config.priority = DEFAULT_RXQ_PRIORITY;
  263. mem_conf.rx_queue_config.type = DEFAULT_RXQ_TYPE;
  264. /* TX queue config */
  265. for (i = 0; i < MAX_TX_QUEUES; i++) {
  266. mem_conf.tx_queue_config[i].num_descs = ACX_TX_DESC_DEF;
  267. mem_conf.tx_queue_config[i].attributes = i;
  268. }
  269. mem_conf.header.id = ACX_MEM_CFG;
  270. mem_conf.header.len = sizeof(struct wl1251_acx_config_memory) -
  271. sizeof(struct acx_header);
  272. mem_conf.header.len -=
  273. (MAX_TX_QUEUE_CONFIGS - mem_conf.mem_config.num_tx_queues) *
  274. sizeof(struct wl1251_acx_tx_queue_config);
  275. ret = wl12xx_cmd_configure(wl, &mem_conf,
  276. sizeof(struct wl1251_acx_config_memory));
  277. if (ret < 0)
  278. wl12xx_warning("wl1251 mem config failed: %d", ret);
  279. return ret;
  280. }
  281. static int wl1251_hw_init_mem_config(struct wl12xx *wl)
  282. {
  283. int ret;
  284. ret = wl1251_mem_cfg(wl);
  285. if (ret < 0)
  286. return ret;
  287. wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
  288. GFP_KERNEL);
  289. if (!wl->target_mem_map) {
  290. wl12xx_error("couldn't allocate target memory map");
  291. return -ENOMEM;
  292. }
  293. /* we now ask for the firmware built memory map */
  294. ret = wl12xx_acx_mem_map(wl, wl->target_mem_map,
  295. sizeof(struct wl1251_acx_mem_map));
  296. if (ret < 0) {
  297. wl12xx_error("couldn't retrieve firmware memory map");
  298. kfree(wl->target_mem_map);
  299. wl->target_mem_map = NULL;
  300. return ret;
  301. }
  302. return 0;
  303. }
  304. static void wl1251_set_ecpu_ctrl(struct wl12xx *wl, u32 flag)
  305. {
  306. u32 cpu_ctrl;
  307. /* 10.5.0 run the firmware (I) */
  308. cpu_ctrl = wl12xx_reg_read32(wl, ACX_REG_ECPU_CONTROL);
  309. /* 10.5.1 run the firmware (II) */
  310. cpu_ctrl &= ~flag;
  311. wl12xx_reg_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
  312. }
  313. static void wl1251_target_enable_interrupts(struct wl12xx *wl)
  314. {
  315. /* Enable target's interrupts */
  316. wl->intr_mask = WL1251_ACX_INTR_RX0_DATA |
  317. WL1251_ACX_INTR_RX1_DATA |
  318. WL1251_ACX_INTR_TX_RESULT |
  319. WL1251_ACX_INTR_EVENT_A |
  320. WL1251_ACX_INTR_EVENT_B |
  321. WL1251_ACX_INTR_INIT_COMPLETE;
  322. wl12xx_boot_target_enable_interrupts(wl);
  323. }
  324. static void wl1251_irq_work(struct work_struct *work)
  325. {
  326. u32 intr;
  327. struct wl12xx *wl =
  328. container_of(work, struct wl12xx, irq_work);
  329. mutex_lock(&wl->mutex);
  330. wl12xx_debug(DEBUG_IRQ, "IRQ work");
  331. if (wl->state == WL12XX_STATE_OFF)
  332. goto out;
  333. wl12xx_ps_elp_wakeup(wl);
  334. wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL);
  335. intr = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
  336. wl12xx_debug(DEBUG_IRQ, "intr: 0x%x", intr);
  337. if (wl->data_path) {
  338. wl12xx_spi_mem_read(wl, wl->data_path->rx_control_addr,
  339. &wl->rx_counter, sizeof(u32));
  340. /* We handle a frmware bug here */
  341. switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
  342. case 0:
  343. wl12xx_debug(DEBUG_IRQ, "RX: FW and host in sync");
  344. intr &= ~WL1251_ACX_INTR_RX0_DATA;
  345. intr &= ~WL1251_ACX_INTR_RX1_DATA;
  346. break;
  347. case 1:
  348. wl12xx_debug(DEBUG_IRQ, "RX: FW +1");
  349. intr |= WL1251_ACX_INTR_RX0_DATA;
  350. intr &= ~WL1251_ACX_INTR_RX1_DATA;
  351. break;
  352. case 2:
  353. wl12xx_debug(DEBUG_IRQ, "RX: FW +2");
  354. intr |= WL1251_ACX_INTR_RX0_DATA;
  355. intr |= WL1251_ACX_INTR_RX1_DATA;
  356. break;
  357. default:
  358. wl12xx_warning("RX: FW and host out of sync: %d",
  359. wl->rx_counter - wl->rx_handled);
  360. break;
  361. }
  362. wl->rx_handled = wl->rx_counter;
  363. wl12xx_debug(DEBUG_IRQ, "RX counter: %d", wl->rx_counter);
  364. }
  365. intr &= wl->intr_mask;
  366. if (intr == 0) {
  367. wl12xx_debug(DEBUG_IRQ, "INTR is 0");
  368. wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK,
  369. ~(wl->intr_mask));
  370. goto out_sleep;
  371. }
  372. if (intr & WL1251_ACX_INTR_RX0_DATA) {
  373. wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA");
  374. wl12xx_rx(wl);
  375. }
  376. if (intr & WL1251_ACX_INTR_RX1_DATA) {
  377. wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA");
  378. wl12xx_rx(wl);
  379. }
  380. if (intr & WL1251_ACX_INTR_TX_RESULT) {
  381. wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT");
  382. wl12xx_tx_complete(wl);
  383. }
  384. if (intr & (WL1251_ACX_INTR_EVENT_A | WL1251_ACX_INTR_EVENT_B)) {
  385. wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT (0x%x)", intr);
  386. if (intr & WL1251_ACX_INTR_EVENT_A)
  387. wl12xx_event_handle(wl, 0);
  388. else
  389. wl12xx_event_handle(wl, 1);
  390. }
  391. if (intr & WL1251_ACX_INTR_INIT_COMPLETE)
  392. wl12xx_debug(DEBUG_IRQ, "WL1251_ACX_INTR_INIT_COMPLETE");
  393. wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
  394. out_sleep:
  395. wl12xx_ps_elp_sleep(wl);
  396. out:
  397. mutex_unlock(&wl->mutex);
  398. }
  399. static int wl1251_hw_init_txq_fill(u8 qid,
  400. struct acx_tx_queue_qos_config *config,
  401. u32 num_blocks)
  402. {
  403. config->qid = qid;
  404. switch (qid) {
  405. case QOS_AC_BE:
  406. config->high_threshold =
  407. (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
  408. config->low_threshold =
  409. (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
  410. break;
  411. case QOS_AC_BK:
  412. config->high_threshold =
  413. (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
  414. config->low_threshold =
  415. (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
  416. break;
  417. case QOS_AC_VI:
  418. config->high_threshold =
  419. (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
  420. config->low_threshold =
  421. (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
  422. break;
  423. case QOS_AC_VO:
  424. config->high_threshold =
  425. (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
  426. config->low_threshold =
  427. (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
  428. break;
  429. default:
  430. wl12xx_error("Invalid TX queue id: %d", qid);
  431. return -EINVAL;
  432. }
  433. return 0;
  434. }
  435. static int wl1251_hw_init_tx_queue_config(struct wl12xx *wl)
  436. {
  437. struct acx_tx_queue_qos_config config;
  438. struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
  439. int ret, i;
  440. wl12xx_debug(DEBUG_ACX, "acx tx queue config");
  441. config.header.id = ACX_TX_QUEUE_CFG;
  442. config.header.len = sizeof(struct acx_tx_queue_qos_config) -
  443. sizeof(struct acx_header);
  444. for (i = 0; i < MAX_NUM_OF_AC; i++) {
  445. ret = wl1251_hw_init_txq_fill(i, &config,
  446. wl_mem_map->num_tx_mem_blocks);
  447. if (ret < 0)
  448. return ret;
  449. ret = wl12xx_cmd_configure(wl, &config, sizeof(config));
  450. if (ret < 0)
  451. return ret;
  452. }
  453. return 0;
  454. }
  455. static int wl1251_hw_init_data_path_config(struct wl12xx *wl)
  456. {
  457. int ret;
  458. /* asking for the data path parameters */
  459. wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
  460. GFP_KERNEL);
  461. if (!wl->data_path) {
  462. wl12xx_error("Couldnt allocate data path parameters");
  463. return -ENOMEM;
  464. }
  465. ret = wl12xx_acx_data_path_params(wl, wl->data_path);
  466. if (ret < 0) {
  467. kfree(wl->data_path);
  468. wl->data_path = NULL;
  469. return ret;
  470. }
  471. return 0;
  472. }
  473. static int wl1251_hw_init(struct wl12xx *wl)
  474. {
  475. struct wl1251_acx_mem_map *wl_mem_map;
  476. int ret;
  477. ret = wl12xx_hw_init_hwenc_config(wl);
  478. if (ret < 0)
  479. return ret;
  480. /* Template settings */
  481. ret = wl12xx_hw_init_templates_config(wl);
  482. if (ret < 0)
  483. return ret;
  484. /* Default memory configuration */
  485. ret = wl1251_hw_init_mem_config(wl);
  486. if (ret < 0)
  487. return ret;
  488. /* Default data path configuration */
  489. ret = wl1251_hw_init_data_path_config(wl);
  490. if (ret < 0)
  491. goto out_free_memmap;
  492. /* RX config */
  493. ret = wl12xx_hw_init_rx_config(wl,
  494. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  495. RX_FILTER_OPTION_DEF);
  496. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  497. RX_FILTER_OPTION_FILTER_ALL); */
  498. if (ret < 0)
  499. goto out_free_data_path;
  500. /* TX queues config */
  501. ret = wl1251_hw_init_tx_queue_config(wl);
  502. if (ret < 0)
  503. goto out_free_data_path;
  504. /* PHY layer config */
  505. ret = wl12xx_hw_init_phy_config(wl);
  506. if (ret < 0)
  507. goto out_free_data_path;
  508. /* Beacon filtering */
  509. ret = wl12xx_hw_init_beacon_filter(wl);
  510. if (ret < 0)
  511. goto out_free_data_path;
  512. /* Bluetooth WLAN coexistence */
  513. ret = wl12xx_hw_init_pta(wl);
  514. if (ret < 0)
  515. goto out_free_data_path;
  516. /* Energy detection */
  517. ret = wl12xx_hw_init_energy_detection(wl);
  518. if (ret < 0)
  519. goto out_free_data_path;
  520. /* Beacons and boradcast settings */
  521. ret = wl12xx_hw_init_beacon_broadcast(wl);
  522. if (ret < 0)
  523. goto out_free_data_path;
  524. /* Enable data path */
  525. ret = wl12xx_cmd_data_path(wl, wl->channel, 1);
  526. if (ret < 0)
  527. goto out_free_data_path;
  528. /* Default power state */
  529. ret = wl12xx_hw_init_power_auth(wl);
  530. if (ret < 0)
  531. goto out_free_data_path;
  532. wl_mem_map = wl->target_mem_map;
  533. wl12xx_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
  534. wl_mem_map->num_tx_mem_blocks,
  535. wl->data_path->tx_control_addr,
  536. wl_mem_map->num_rx_mem_blocks,
  537. wl->data_path->rx_control_addr);
  538. return 0;
  539. out_free_data_path:
  540. kfree(wl->data_path);
  541. out_free_memmap:
  542. kfree(wl->target_mem_map);
  543. return ret;
  544. }
  545. static int wl1251_plt_init(struct wl12xx *wl)
  546. {
  547. int ret;
  548. ret = wl1251_hw_init_mem_config(wl);
  549. if (ret < 0)
  550. return ret;
  551. ret = wl12xx_cmd_data_path(wl, wl->channel, 1);
  552. if (ret < 0)
  553. return ret;
  554. return 0;
  555. }
  556. void wl1251_setup(struct wl12xx *wl)
  557. {
  558. /* FIXME: Is it better to use strncpy here or is this ok? */
  559. wl->chip.fw_filename = WL1251_FW_NAME;
  560. wl->chip.nvs_filename = WL1251_NVS_NAME;
  561. /* Now we know what chip we're using, so adjust the power on sleep
  562. * time accordingly */
  563. wl->chip.power_on_sleep = WL1251_POWER_ON_SLEEP;
  564. wl->chip.intr_cmd_complete = WL1251_ACX_INTR_CMD_COMPLETE;
  565. wl->chip.intr_init_complete = WL1251_ACX_INTR_INIT_COMPLETE;
  566. wl->chip.op_upload_nvs = wl1251_upload_nvs;
  567. wl->chip.op_upload_fw = wl1251_upload_firmware;
  568. wl->chip.op_boot = wl1251_boot;
  569. wl->chip.op_set_ecpu_ctrl = wl1251_set_ecpu_ctrl;
  570. wl->chip.op_target_enable_interrupts = wl1251_target_enable_interrupts;
  571. wl->chip.op_hw_init = wl1251_hw_init;
  572. wl->chip.op_plt_init = wl1251_plt_init;
  573. wl->chip.p_table = wl1251_part_table;
  574. wl->chip.acx_reg_table = wl1251_acx_reg_table;
  575. INIT_WORK(&wl->irq_work, wl1251_irq_work);
  576. }