wl1251_ops.c 18 KB

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