cmd.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009-2010 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@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/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/ieee80211.h>
  28. #include <linux/slab.h>
  29. #include "wl12xx.h"
  30. #include "reg.h"
  31. #include "io.h"
  32. #include "acx.h"
  33. #include "wl12xx_80211.h"
  34. #include "cmd.h"
  35. #include "event.h"
  36. #include "tx.h"
  37. #define WL1271_CMD_FAST_POLL_COUNT 50
  38. /*
  39. * send command to firmware
  40. *
  41. * @wl: wl struct
  42. * @id: command id
  43. * @buf: buffer containing the command, must work with dma
  44. * @len: length of the buffer
  45. */
  46. int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
  47. size_t res_len)
  48. {
  49. struct wl1271_cmd_header *cmd;
  50. unsigned long timeout;
  51. u32 intr;
  52. int ret = 0;
  53. u16 status;
  54. u16 poll_count = 0;
  55. cmd = buf;
  56. cmd->id = cpu_to_le16(id);
  57. cmd->status = 0;
  58. WARN_ON(len % 4 != 0);
  59. WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
  60. wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
  61. wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
  62. timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
  63. intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
  64. while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
  65. if (time_after(jiffies, timeout)) {
  66. wl1271_error("command complete timeout");
  67. ret = -ETIMEDOUT;
  68. goto fail;
  69. }
  70. poll_count++;
  71. if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
  72. udelay(10);
  73. else
  74. msleep(1);
  75. intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
  76. }
  77. /* read back the status code of the command */
  78. if (res_len == 0)
  79. res_len = sizeof(struct wl1271_cmd_header);
  80. wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
  81. status = le16_to_cpu(cmd->status);
  82. if (status != CMD_STATUS_SUCCESS) {
  83. wl1271_error("command execute failure %d", status);
  84. ret = -EIO;
  85. goto fail;
  86. }
  87. wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
  88. WL1271_ACX_INTR_CMD_COMPLETE);
  89. return 0;
  90. fail:
  91. WARN_ON(1);
  92. wl12xx_queue_recovery_work(wl);
  93. return ret;
  94. }
  95. int wl1271_cmd_general_parms(struct wl1271 *wl)
  96. {
  97. struct wl1271_general_parms_cmd *gen_parms;
  98. struct wl1271_ini_general_params *gp =
  99. &((struct wl1271_nvs_file *)wl->nvs)->general_params;
  100. bool answer = false;
  101. int ret;
  102. if (!wl->nvs)
  103. return -ENODEV;
  104. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  105. if (!gen_parms)
  106. return -ENOMEM;
  107. gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  108. memcpy(&gen_parms->general_params, gp, sizeof(*gp));
  109. if (gp->tx_bip_fem_auto_detect)
  110. answer = true;
  111. /* Override the REF CLK from the NVS with the one from platform data */
  112. gen_parms->general_params.ref_clock = wl->ref_clock;
  113. /* LPD mode enable (bits 6-7) in WL1271 AP mode only */
  114. if (wl->quirks & WL12XX_QUIRK_LPD_MODE)
  115. gen_parms->general_params.general_settings |=
  116. GENERAL_SETTINGS_DRPW_LPD;
  117. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
  118. if (ret < 0) {
  119. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  120. goto out;
  121. }
  122. gp->tx_bip_fem_manufacturer =
  123. gen_parms->general_params.tx_bip_fem_manufacturer;
  124. wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
  125. answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
  126. out:
  127. kfree(gen_parms);
  128. return ret;
  129. }
  130. int wl128x_cmd_general_parms(struct wl1271 *wl)
  131. {
  132. struct wl128x_general_parms_cmd *gen_parms;
  133. struct wl128x_ini_general_params *gp =
  134. &((struct wl128x_nvs_file *)wl->nvs)->general_params;
  135. bool answer = false;
  136. int ret;
  137. if (!wl->nvs)
  138. return -ENODEV;
  139. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  140. if (!gen_parms)
  141. return -ENOMEM;
  142. gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  143. memcpy(&gen_parms->general_params, gp, sizeof(*gp));
  144. if (gp->tx_bip_fem_auto_detect)
  145. answer = true;
  146. /* Replace REF and TCXO CLKs with the ones from platform data */
  147. gen_parms->general_params.ref_clock = wl->ref_clock;
  148. gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
  149. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
  150. if (ret < 0) {
  151. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  152. goto out;
  153. }
  154. gp->tx_bip_fem_manufacturer =
  155. gen_parms->general_params.tx_bip_fem_manufacturer;
  156. wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
  157. answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
  158. out:
  159. kfree(gen_parms);
  160. return ret;
  161. }
  162. int wl1271_cmd_radio_parms(struct wl1271 *wl)
  163. {
  164. struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
  165. struct wl1271_radio_parms_cmd *radio_parms;
  166. struct wl1271_ini_general_params *gp = &nvs->general_params;
  167. int ret;
  168. if (!wl->nvs)
  169. return -ENODEV;
  170. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  171. if (!radio_parms)
  172. return -ENOMEM;
  173. radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
  174. /* 2.4GHz parameters */
  175. memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
  176. sizeof(struct wl1271_ini_band_params_2));
  177. memcpy(&radio_parms->dyn_params_2,
  178. &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
  179. sizeof(struct wl1271_ini_fem_params_2));
  180. /* 5GHz parameters */
  181. memcpy(&radio_parms->static_params_5,
  182. &nvs->stat_radio_params_5,
  183. sizeof(struct wl1271_ini_band_params_5));
  184. memcpy(&radio_parms->dyn_params_5,
  185. &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
  186. sizeof(struct wl1271_ini_fem_params_5));
  187. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
  188. radio_parms, sizeof(*radio_parms));
  189. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  190. if (ret < 0)
  191. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  192. kfree(radio_parms);
  193. return ret;
  194. }
  195. int wl128x_cmd_radio_parms(struct wl1271 *wl)
  196. {
  197. struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
  198. struct wl128x_radio_parms_cmd *radio_parms;
  199. struct wl128x_ini_general_params *gp = &nvs->general_params;
  200. int ret;
  201. if (!wl->nvs)
  202. return -ENODEV;
  203. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  204. if (!radio_parms)
  205. return -ENOMEM;
  206. radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
  207. /* 2.4GHz parameters */
  208. memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
  209. sizeof(struct wl128x_ini_band_params_2));
  210. memcpy(&radio_parms->dyn_params_2,
  211. &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
  212. sizeof(struct wl128x_ini_fem_params_2));
  213. /* 5GHz parameters */
  214. memcpy(&radio_parms->static_params_5,
  215. &nvs->stat_radio_params_5,
  216. sizeof(struct wl128x_ini_band_params_5));
  217. memcpy(&radio_parms->dyn_params_5,
  218. &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
  219. sizeof(struct wl128x_ini_fem_params_5));
  220. radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
  221. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
  222. radio_parms, sizeof(*radio_parms));
  223. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  224. if (ret < 0)
  225. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  226. kfree(radio_parms);
  227. return ret;
  228. }
  229. int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
  230. {
  231. struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
  232. struct conf_rf_settings *rf = &wl->conf.rf;
  233. int ret;
  234. if (!wl->nvs)
  235. return -ENODEV;
  236. ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
  237. if (!ext_radio_parms)
  238. return -ENOMEM;
  239. ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
  240. memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
  241. rf->tx_per_channel_power_compensation_2,
  242. CONF_TX_PWR_COMPENSATION_LEN_2);
  243. memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
  244. rf->tx_per_channel_power_compensation_5,
  245. CONF_TX_PWR_COMPENSATION_LEN_5);
  246. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
  247. ext_radio_parms, sizeof(*ext_radio_parms));
  248. ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
  249. if (ret < 0)
  250. wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
  251. kfree(ext_radio_parms);
  252. return ret;
  253. }
  254. /*
  255. * Poll the mailbox event field until any of the bits in the mask is set or a
  256. * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
  257. */
  258. static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
  259. {
  260. u32 events_vector, event;
  261. unsigned long timeout;
  262. timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
  263. do {
  264. if (time_after(jiffies, timeout)) {
  265. wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
  266. (int)mask);
  267. return -ETIMEDOUT;
  268. }
  269. msleep(1);
  270. /* read from both event fields */
  271. wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
  272. sizeof(events_vector), false);
  273. event = events_vector & mask;
  274. wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
  275. sizeof(events_vector), false);
  276. event |= events_vector & mask;
  277. } while (!event);
  278. return 0;
  279. }
  280. static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
  281. {
  282. int ret;
  283. ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
  284. if (ret != 0) {
  285. wl12xx_queue_recovery_work(wl);
  286. return ret;
  287. }
  288. return 0;
  289. }
  290. int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
  291. {
  292. struct wl1271_cmd_join *join;
  293. int ret, i;
  294. u8 *bssid;
  295. join = kzalloc(sizeof(*join), GFP_KERNEL);
  296. if (!join) {
  297. ret = -ENOMEM;
  298. goto out;
  299. }
  300. wl1271_debug(DEBUG_CMD, "cmd join");
  301. /* Reverse order BSSID */
  302. bssid = (u8 *) &join->bssid_lsb;
  303. for (i = 0; i < ETH_ALEN; i++)
  304. bssid[i] = wl->bssid[ETH_ALEN - i - 1];
  305. join->bss_type = bss_type;
  306. join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
  307. join->supported_rate_set = cpu_to_le32(wl->rate_set);
  308. if (wl->band == IEEE80211_BAND_5GHZ)
  309. join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
  310. join->beacon_interval = cpu_to_le16(wl->beacon_int);
  311. join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
  312. join->channel = wl->channel;
  313. join->ssid_len = wl->ssid_len;
  314. memcpy(join->ssid, wl->ssid, wl->ssid_len);
  315. join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
  316. wl1271_debug(DEBUG_CMD, "cmd join: basic_rate_set=0x%x, rate_set=0x%x",
  317. join->basic_rate_set, join->supported_rate_set);
  318. ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
  319. if (ret < 0) {
  320. wl1271_error("failed to initiate cmd join");
  321. goto out_free;
  322. }
  323. ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
  324. if (ret < 0)
  325. wl1271_error("cmd join event completion error");
  326. out_free:
  327. kfree(join);
  328. out:
  329. return ret;
  330. }
  331. /**
  332. * send test command to firmware
  333. *
  334. * @wl: wl struct
  335. * @buf: buffer containing the command, with all headers, must work with dma
  336. * @len: length of the buffer
  337. * @answer: is answer needed
  338. */
  339. int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
  340. {
  341. int ret;
  342. size_t res_len = 0;
  343. wl1271_debug(DEBUG_CMD, "cmd test");
  344. if (answer)
  345. res_len = buf_len;
  346. ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
  347. if (ret < 0) {
  348. wl1271_warning("TEST command failed");
  349. return ret;
  350. }
  351. return ret;
  352. }
  353. /**
  354. * read acx from firmware
  355. *
  356. * @wl: wl struct
  357. * @id: acx id
  358. * @buf: buffer for the response, including all headers, must work with dma
  359. * @len: length of buf
  360. */
  361. int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
  362. {
  363. struct acx_header *acx = buf;
  364. int ret;
  365. wl1271_debug(DEBUG_CMD, "cmd interrogate");
  366. acx->id = cpu_to_le16(id);
  367. /* payload length, does not include any headers */
  368. acx->len = cpu_to_le16(len - sizeof(*acx));
  369. ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
  370. if (ret < 0)
  371. wl1271_error("INTERROGATE command failed");
  372. return ret;
  373. }
  374. /**
  375. * write acx value to firmware
  376. *
  377. * @wl: wl struct
  378. * @id: acx id
  379. * @buf: buffer containing acx, including all headers, must work with dma
  380. * @len: length of buf
  381. */
  382. int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
  383. {
  384. struct acx_header *acx = buf;
  385. int ret;
  386. wl1271_debug(DEBUG_CMD, "cmd configure");
  387. acx->id = cpu_to_le16(id);
  388. /* payload length, does not include any headers */
  389. acx->len = cpu_to_le16(len - sizeof(*acx));
  390. ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
  391. if (ret < 0) {
  392. wl1271_warning("CONFIGURE command NOK");
  393. return ret;
  394. }
  395. return 0;
  396. }
  397. int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
  398. {
  399. struct cmd_enabledisable_path *cmd;
  400. int ret;
  401. u16 cmd_rx, cmd_tx;
  402. wl1271_debug(DEBUG_CMD, "cmd data path");
  403. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  404. if (!cmd) {
  405. ret = -ENOMEM;
  406. goto out;
  407. }
  408. /* the channel here is only used for calibration, so hardcoded to 1 */
  409. cmd->channel = 1;
  410. if (enable) {
  411. cmd_rx = CMD_ENABLE_RX;
  412. cmd_tx = CMD_ENABLE_TX;
  413. } else {
  414. cmd_rx = CMD_DISABLE_RX;
  415. cmd_tx = CMD_DISABLE_TX;
  416. }
  417. ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
  418. if (ret < 0) {
  419. wl1271_error("rx %s cmd for channel %d failed",
  420. enable ? "start" : "stop", cmd->channel);
  421. goto out;
  422. }
  423. wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
  424. enable ? "start" : "stop", cmd->channel);
  425. ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
  426. if (ret < 0) {
  427. wl1271_error("tx %s cmd for channel %d failed",
  428. enable ? "start" : "stop", cmd->channel);
  429. goto out;
  430. }
  431. wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
  432. enable ? "start" : "stop", cmd->channel);
  433. out:
  434. kfree(cmd);
  435. return ret;
  436. }
  437. int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
  438. {
  439. struct wl1271_cmd_ps_params *ps_params = NULL;
  440. int ret = 0;
  441. wl1271_debug(DEBUG_CMD, "cmd set ps mode");
  442. ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
  443. if (!ps_params) {
  444. ret = -ENOMEM;
  445. goto out;
  446. }
  447. ps_params->ps_mode = ps_mode;
  448. ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
  449. sizeof(*ps_params), 0);
  450. if (ret < 0) {
  451. wl1271_error("cmd set_ps_mode failed");
  452. goto out;
  453. }
  454. out:
  455. kfree(ps_params);
  456. return ret;
  457. }
  458. int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
  459. void *buf, size_t buf_len, int index, u32 rates)
  460. {
  461. struct wl1271_cmd_template_set *cmd;
  462. int ret = 0;
  463. wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
  464. WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
  465. buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
  466. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  467. if (!cmd) {
  468. ret = -ENOMEM;
  469. goto out;
  470. }
  471. cmd->len = cpu_to_le16(buf_len);
  472. cmd->template_type = template_id;
  473. cmd->enabled_rates = cpu_to_le32(rates);
  474. cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
  475. cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
  476. cmd->index = index;
  477. if (buf)
  478. memcpy(cmd->template_data, buf, buf_len);
  479. ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
  480. if (ret < 0) {
  481. wl1271_warning("cmd set_template failed: %d", ret);
  482. goto out_free;
  483. }
  484. out_free:
  485. kfree(cmd);
  486. out:
  487. return ret;
  488. }
  489. int wl1271_cmd_build_null_data(struct wl1271 *wl)
  490. {
  491. struct sk_buff *skb = NULL;
  492. int size;
  493. void *ptr;
  494. int ret = -ENOMEM;
  495. if (wl->bss_type == BSS_TYPE_IBSS) {
  496. size = sizeof(struct wl12xx_null_data_template);
  497. ptr = NULL;
  498. } else {
  499. skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
  500. if (!skb)
  501. goto out;
  502. size = skb->len;
  503. ptr = skb->data;
  504. }
  505. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
  506. wl->basic_rate);
  507. out:
  508. dev_kfree_skb(skb);
  509. if (ret)
  510. wl1271_warning("cmd buld null data failed %d", ret);
  511. return ret;
  512. }
  513. int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
  514. {
  515. struct sk_buff *skb = NULL;
  516. int ret = -ENOMEM;
  517. skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
  518. if (!skb)
  519. goto out;
  520. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
  521. skb->data, skb->len,
  522. CMD_TEMPL_KLV_IDX_NULL_DATA,
  523. wl->basic_rate);
  524. out:
  525. dev_kfree_skb(skb);
  526. if (ret)
  527. wl1271_warning("cmd build klv null data failed %d", ret);
  528. return ret;
  529. }
  530. int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
  531. {
  532. struct sk_buff *skb;
  533. int ret = 0;
  534. skb = ieee80211_pspoll_get(wl->hw, wl->vif);
  535. if (!skb)
  536. goto out;
  537. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
  538. skb->len, 0, wl->basic_rate_set);
  539. out:
  540. dev_kfree_skb(skb);
  541. return ret;
  542. }
  543. int wl1271_cmd_build_probe_req(struct wl1271 *wl,
  544. const u8 *ssid, size_t ssid_len,
  545. const u8 *ie, size_t ie_len, u8 band)
  546. {
  547. struct sk_buff *skb;
  548. int ret;
  549. skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
  550. ie, ie_len);
  551. if (!skb) {
  552. ret = -ENOMEM;
  553. goto out;
  554. }
  555. wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
  556. if (band == IEEE80211_BAND_2GHZ)
  557. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
  558. skb->data, skb->len, 0,
  559. wl->conf.tx.basic_rate);
  560. else
  561. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  562. skb->data, skb->len, 0,
  563. wl->conf.tx.basic_rate_5);
  564. out:
  565. dev_kfree_skb(skb);
  566. return ret;
  567. }
  568. struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
  569. struct sk_buff *skb)
  570. {
  571. int ret;
  572. if (!skb)
  573. skb = ieee80211_ap_probereq_get(wl->hw, wl->vif);
  574. if (!skb)
  575. goto out;
  576. wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
  577. if (wl->band == IEEE80211_BAND_2GHZ)
  578. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
  579. skb->data, skb->len, 0,
  580. wl->conf.tx.basic_rate);
  581. else
  582. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  583. skb->data, skb->len, 0,
  584. wl->conf.tx.basic_rate_5);
  585. if (ret < 0)
  586. wl1271_error("Unable to set ap probe request template.");
  587. out:
  588. return skb;
  589. }
  590. int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
  591. {
  592. int ret;
  593. struct wl12xx_arp_rsp_template tmpl;
  594. struct ieee80211_hdr_3addr *hdr;
  595. struct arphdr *arp_hdr;
  596. memset(&tmpl, 0, sizeof(tmpl));
  597. /* mac80211 header */
  598. hdr = &tmpl.hdr;
  599. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  600. IEEE80211_STYPE_DATA |
  601. IEEE80211_FCTL_TODS);
  602. memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN);
  603. memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN);
  604. memset(hdr->addr3, 0xff, ETH_ALEN);
  605. /* llc layer */
  606. memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
  607. tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
  608. /* arp header */
  609. arp_hdr = &tmpl.arp_hdr;
  610. arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
  611. arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
  612. arp_hdr->ar_hln = ETH_ALEN;
  613. arp_hdr->ar_pln = 4;
  614. arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
  615. /* arp payload */
  616. memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN);
  617. tmpl.sender_ip = ip_addr;
  618. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
  619. &tmpl, sizeof(tmpl), 0,
  620. wl->basic_rate);
  621. return ret;
  622. }
  623. int wl1271_build_qos_null_data(struct wl1271 *wl)
  624. {
  625. struct ieee80211_qos_hdr template;
  626. memset(&template, 0, sizeof(template));
  627. memcpy(template.addr1, wl->bssid, ETH_ALEN);
  628. memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
  629. memcpy(template.addr3, wl->bssid, ETH_ALEN);
  630. template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  631. IEEE80211_STYPE_QOS_NULLFUNC |
  632. IEEE80211_FCTL_TODS);
  633. /* FIXME: not sure what priority to use here */
  634. template.qos_ctrl = cpu_to_le16(0);
  635. return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
  636. sizeof(template), 0,
  637. wl->basic_rate);
  638. }
  639. int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id)
  640. {
  641. struct wl1271_cmd_set_sta_keys *cmd;
  642. int ret = 0;
  643. wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
  644. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  645. if (!cmd) {
  646. ret = -ENOMEM;
  647. goto out;
  648. }
  649. cmd->id = id;
  650. cmd->key_action = cpu_to_le16(KEY_SET_ID);
  651. cmd->key_type = KEY_WEP;
  652. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  653. if (ret < 0) {
  654. wl1271_warning("cmd set_default_wep_key failed: %d", ret);
  655. goto out;
  656. }
  657. out:
  658. kfree(cmd);
  659. return ret;
  660. }
  661. int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id)
  662. {
  663. struct wl1271_cmd_set_ap_keys *cmd;
  664. int ret = 0;
  665. wl1271_debug(DEBUG_CMD, "cmd set_ap_default_wep_key %d", id);
  666. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  667. if (!cmd) {
  668. ret = -ENOMEM;
  669. goto out;
  670. }
  671. cmd->hlid = WL1271_AP_BROADCAST_HLID;
  672. cmd->key_id = id;
  673. cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
  674. cmd->key_action = cpu_to_le16(KEY_SET_ID);
  675. cmd->key_type = KEY_WEP;
  676. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  677. if (ret < 0) {
  678. wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret);
  679. goto out;
  680. }
  681. out:
  682. kfree(cmd);
  683. return ret;
  684. }
  685. int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
  686. u8 key_size, const u8 *key, const u8 *addr,
  687. u32 tx_seq_32, u16 tx_seq_16)
  688. {
  689. struct wl1271_cmd_set_sta_keys *cmd;
  690. int ret = 0;
  691. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  692. if (!cmd) {
  693. ret = -ENOMEM;
  694. goto out;
  695. }
  696. if (key_type != KEY_WEP)
  697. memcpy(cmd->addr, addr, ETH_ALEN);
  698. cmd->key_action = cpu_to_le16(action);
  699. cmd->key_size = key_size;
  700. cmd->key_type = key_type;
  701. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  702. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  703. /* we have only one SSID profile */
  704. cmd->ssid_profile = 0;
  705. cmd->id = id;
  706. if (key_type == KEY_TKIP) {
  707. /*
  708. * We get the key in the following form:
  709. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  710. * but the target is expecting:
  711. * TKIP - RX MIC - TX MIC
  712. */
  713. memcpy(cmd->key, key, 16);
  714. memcpy(cmd->key + 16, key + 24, 8);
  715. memcpy(cmd->key + 24, key + 16, 8);
  716. } else {
  717. memcpy(cmd->key, key, key_size);
  718. }
  719. wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
  720. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  721. if (ret < 0) {
  722. wl1271_warning("could not set keys");
  723. goto out;
  724. }
  725. out:
  726. kfree(cmd);
  727. return ret;
  728. }
  729. int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
  730. u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
  731. u16 tx_seq_16)
  732. {
  733. struct wl1271_cmd_set_ap_keys *cmd;
  734. int ret = 0;
  735. u8 lid_type;
  736. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  737. if (!cmd)
  738. return -ENOMEM;
  739. if (hlid == WL1271_AP_BROADCAST_HLID) {
  740. if (key_type == KEY_WEP)
  741. lid_type = WEP_DEFAULT_LID_TYPE;
  742. else
  743. lid_type = BROADCAST_LID_TYPE;
  744. } else {
  745. lid_type = UNICAST_LID_TYPE;
  746. }
  747. wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
  748. " hlid: %d", (int)action, (int)id, (int)lid_type,
  749. (int)key_type, (int)hlid);
  750. cmd->lid_key_type = lid_type;
  751. cmd->hlid = hlid;
  752. cmd->key_action = cpu_to_le16(action);
  753. cmd->key_size = key_size;
  754. cmd->key_type = key_type;
  755. cmd->key_id = id;
  756. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  757. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  758. if (key_type == KEY_TKIP) {
  759. /*
  760. * We get the key in the following form:
  761. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  762. * but the target is expecting:
  763. * TKIP - RX MIC - TX MIC
  764. */
  765. memcpy(cmd->key, key, 16);
  766. memcpy(cmd->key + 16, key + 24, 8);
  767. memcpy(cmd->key + 24, key + 16, 8);
  768. } else {
  769. memcpy(cmd->key, key, key_size);
  770. }
  771. wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
  772. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  773. if (ret < 0) {
  774. wl1271_warning("could not set ap keys");
  775. goto out;
  776. }
  777. out:
  778. kfree(cmd);
  779. return ret;
  780. }
  781. int wl1271_cmd_disconnect(struct wl1271 *wl)
  782. {
  783. struct wl1271_cmd_disconnect *cmd;
  784. int ret = 0;
  785. wl1271_debug(DEBUG_CMD, "cmd disconnect");
  786. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  787. if (!cmd) {
  788. ret = -ENOMEM;
  789. goto out;
  790. }
  791. /* disconnect reason is not used in immediate disconnections */
  792. cmd->type = DISCONNECT_IMMEDIATE;
  793. ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
  794. if (ret < 0) {
  795. wl1271_error("failed to send disconnect command");
  796. goto out_free;
  797. }
  798. ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
  799. if (ret < 0)
  800. wl1271_error("cmd disconnect event completion error");
  801. out_free:
  802. kfree(cmd);
  803. out:
  804. return ret;
  805. }
  806. int wl1271_cmd_set_sta_state(struct wl1271 *wl)
  807. {
  808. struct wl1271_cmd_set_sta_state *cmd;
  809. int ret = 0;
  810. wl1271_debug(DEBUG_CMD, "cmd set sta state");
  811. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  812. if (!cmd) {
  813. ret = -ENOMEM;
  814. goto out;
  815. }
  816. cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
  817. ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0);
  818. if (ret < 0) {
  819. wl1271_error("failed to send set STA state command");
  820. goto out_free;
  821. }
  822. out_free:
  823. kfree(cmd);
  824. out:
  825. return ret;
  826. }
  827. int wl1271_cmd_start_bss(struct wl1271 *wl)
  828. {
  829. struct wl1271_cmd_bss_start *cmd;
  830. struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf;
  831. int ret;
  832. wl1271_debug(DEBUG_CMD, "cmd start bss");
  833. /*
  834. * FIXME: We currently do not support hidden SSID. The real SSID
  835. * should be fetched from mac80211 first.
  836. */
  837. if (wl->ssid_len == 0) {
  838. wl1271_warning("Hidden SSID currently not supported for AP");
  839. ret = -EINVAL;
  840. goto out;
  841. }
  842. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  843. if (!cmd) {
  844. ret = -ENOMEM;
  845. goto out;
  846. }
  847. memcpy(cmd->bssid, bss_conf->bssid, ETH_ALEN);
  848. cmd->aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
  849. cmd->bss_index = WL1271_AP_BSS_INDEX;
  850. cmd->global_hlid = WL1271_AP_GLOBAL_HLID;
  851. cmd->broadcast_hlid = WL1271_AP_BROADCAST_HLID;
  852. cmd->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
  853. cmd->beacon_interval = cpu_to_le16(wl->beacon_int);
  854. cmd->dtim_interval = bss_conf->dtim_period;
  855. cmd->beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
  856. cmd->channel = wl->channel;
  857. cmd->ssid_len = wl->ssid_len;
  858. cmd->ssid_type = SSID_TYPE_PUBLIC;
  859. memcpy(cmd->ssid, wl->ssid, wl->ssid_len);
  860. switch (wl->band) {
  861. case IEEE80211_BAND_2GHZ:
  862. cmd->band = RADIO_BAND_2_4GHZ;
  863. break;
  864. case IEEE80211_BAND_5GHZ:
  865. cmd->band = RADIO_BAND_5GHZ;
  866. break;
  867. default:
  868. wl1271_warning("bss start - unknown band: %d", (int)wl->band);
  869. cmd->band = RADIO_BAND_2_4GHZ;
  870. break;
  871. }
  872. ret = wl1271_cmd_send(wl, CMD_BSS_START, cmd, sizeof(*cmd), 0);
  873. if (ret < 0) {
  874. wl1271_error("failed to initiate cmd start bss");
  875. goto out_free;
  876. }
  877. out_free:
  878. kfree(cmd);
  879. out:
  880. return ret;
  881. }
  882. int wl1271_cmd_stop_bss(struct wl1271 *wl)
  883. {
  884. struct wl1271_cmd_bss_start *cmd;
  885. int ret;
  886. wl1271_debug(DEBUG_CMD, "cmd stop bss");
  887. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  888. if (!cmd) {
  889. ret = -ENOMEM;
  890. goto out;
  891. }
  892. cmd->bss_index = WL1271_AP_BSS_INDEX;
  893. ret = wl1271_cmd_send(wl, CMD_BSS_STOP, cmd, sizeof(*cmd), 0);
  894. if (ret < 0) {
  895. wl1271_error("failed to initiate cmd stop bss");
  896. goto out_free;
  897. }
  898. out_free:
  899. kfree(cmd);
  900. out:
  901. return ret;
  902. }
  903. int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
  904. {
  905. struct wl1271_cmd_add_sta *cmd;
  906. int ret;
  907. wl1271_debug(DEBUG_CMD, "cmd add sta %d", (int)hlid);
  908. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  909. if (!cmd) {
  910. ret = -ENOMEM;
  911. goto out;
  912. }
  913. /* currently we don't support UAPSD */
  914. cmd->sp_len = 0;
  915. memcpy(cmd->addr, sta->addr, ETH_ALEN);
  916. cmd->bss_index = WL1271_AP_BSS_INDEX;
  917. cmd->aid = sta->aid;
  918. cmd->hlid = hlid;
  919. cmd->wmm = sta->wme ? 1 : 0;
  920. cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl,
  921. sta->supp_rates[wl->band]));
  922. wl1271_debug(DEBUG_CMD, "new sta rates: 0x%x", cmd->supported_rates);
  923. ret = wl1271_cmd_send(wl, CMD_ADD_STA, cmd, sizeof(*cmd), 0);
  924. if (ret < 0) {
  925. wl1271_error("failed to initiate cmd add sta");
  926. goto out_free;
  927. }
  928. out_free:
  929. kfree(cmd);
  930. out:
  931. return ret;
  932. }
  933. int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid)
  934. {
  935. struct wl1271_cmd_remove_sta *cmd;
  936. int ret;
  937. wl1271_debug(DEBUG_CMD, "cmd remove sta %d", (int)hlid);
  938. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  939. if (!cmd) {
  940. ret = -ENOMEM;
  941. goto out;
  942. }
  943. cmd->hlid = hlid;
  944. /* We never send a deauth, mac80211 is in charge of this */
  945. cmd->reason_opcode = 0;
  946. cmd->send_deauth_flag = 0;
  947. ret = wl1271_cmd_send(wl, CMD_REMOVE_STA, cmd, sizeof(*cmd), 0);
  948. if (ret < 0) {
  949. wl1271_error("failed to initiate cmd remove sta");
  950. goto out_free;
  951. }
  952. /*
  953. * We are ok with a timeout here. The event is sometimes not sent
  954. * due to a firmware bug.
  955. */
  956. wl1271_cmd_wait_for_event_or_timeout(wl, STA_REMOVE_COMPLETE_EVENT_ID);
  957. out_free:
  958. kfree(cmd);
  959. out:
  960. return ret;
  961. }
  962. int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
  963. {
  964. struct wl12xx_cmd_config_fwlog *cmd;
  965. int ret = 0;
  966. wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
  967. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  968. if (!cmd) {
  969. ret = -ENOMEM;
  970. goto out;
  971. }
  972. cmd->logger_mode = wl->conf.fwlog.mode;
  973. cmd->log_severity = wl->conf.fwlog.severity;
  974. cmd->timestamp = wl->conf.fwlog.timestamp;
  975. cmd->output = wl->conf.fwlog.output;
  976. cmd->threshold = wl->conf.fwlog.threshold;
  977. ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
  978. if (ret < 0) {
  979. wl1271_error("failed to send config firmware logger command");
  980. goto out_free;
  981. }
  982. out_free:
  983. kfree(cmd);
  984. out:
  985. return ret;
  986. }
  987. int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
  988. {
  989. struct wl12xx_cmd_start_fwlog *cmd;
  990. int ret = 0;
  991. wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
  992. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  993. if (!cmd) {
  994. ret = -ENOMEM;
  995. goto out;
  996. }
  997. ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
  998. if (ret < 0) {
  999. wl1271_error("failed to send start firmware logger command");
  1000. goto out_free;
  1001. }
  1002. out_free:
  1003. kfree(cmd);
  1004. out:
  1005. return ret;
  1006. }
  1007. int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
  1008. {
  1009. struct wl12xx_cmd_stop_fwlog *cmd;
  1010. int ret = 0;
  1011. wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
  1012. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1013. if (!cmd) {
  1014. ret = -ENOMEM;
  1015. goto out;
  1016. }
  1017. ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
  1018. if (ret < 0) {
  1019. wl1271_error("failed to send stop firmware logger command");
  1020. goto out_free;
  1021. }
  1022. out_free:
  1023. kfree(cmd);
  1024. out:
  1025. return ret;
  1026. }