cmd.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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->rx_config_options = cpu_to_le32(wl->rx_config);
  306. join->rx_filter_options = cpu_to_le32(wl->rx_filter);
  307. join->bss_type = bss_type;
  308. join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
  309. join->supported_rate_set = cpu_to_le32(wl->rate_set);
  310. if (wl->band == IEEE80211_BAND_5GHZ)
  311. join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
  312. join->beacon_interval = cpu_to_le16(wl->beacon_int);
  313. join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
  314. join->channel = wl->channel;
  315. join->ssid_len = wl->ssid_len;
  316. memcpy(join->ssid, wl->ssid, wl->ssid_len);
  317. join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
  318. /* reset TX security counters */
  319. wl->tx_security_last_seq = 0;
  320. wl->tx_security_seq = 0;
  321. wl1271_debug(DEBUG_CMD, "cmd join: basic_rate_set=0x%x, rate_set=0x%x",
  322. join->basic_rate_set, join->supported_rate_set);
  323. ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
  324. if (ret < 0) {
  325. wl1271_error("failed to initiate cmd join");
  326. goto out_free;
  327. }
  328. ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
  329. if (ret < 0)
  330. wl1271_error("cmd join event completion error");
  331. out_free:
  332. kfree(join);
  333. out:
  334. return ret;
  335. }
  336. /**
  337. * send test command to firmware
  338. *
  339. * @wl: wl struct
  340. * @buf: buffer containing the command, with all headers, must work with dma
  341. * @len: length of the buffer
  342. * @answer: is answer needed
  343. */
  344. int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
  345. {
  346. int ret;
  347. size_t res_len = 0;
  348. wl1271_debug(DEBUG_CMD, "cmd test");
  349. if (answer)
  350. res_len = buf_len;
  351. ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
  352. if (ret < 0) {
  353. wl1271_warning("TEST command failed");
  354. return ret;
  355. }
  356. return ret;
  357. }
  358. /**
  359. * read acx from firmware
  360. *
  361. * @wl: wl struct
  362. * @id: acx id
  363. * @buf: buffer for the response, including all headers, must work with dma
  364. * @len: length of buf
  365. */
  366. int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
  367. {
  368. struct acx_header *acx = buf;
  369. int ret;
  370. wl1271_debug(DEBUG_CMD, "cmd interrogate");
  371. acx->id = cpu_to_le16(id);
  372. /* payload length, does not include any headers */
  373. acx->len = cpu_to_le16(len - sizeof(*acx));
  374. ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
  375. if (ret < 0)
  376. wl1271_error("INTERROGATE command failed");
  377. return ret;
  378. }
  379. /**
  380. * write acx value to firmware
  381. *
  382. * @wl: wl struct
  383. * @id: acx id
  384. * @buf: buffer containing acx, including all headers, must work with dma
  385. * @len: length of buf
  386. */
  387. int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
  388. {
  389. struct acx_header *acx = buf;
  390. int ret;
  391. wl1271_debug(DEBUG_CMD, "cmd configure");
  392. acx->id = cpu_to_le16(id);
  393. /* payload length, does not include any headers */
  394. acx->len = cpu_to_le16(len - sizeof(*acx));
  395. ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
  396. if (ret < 0) {
  397. wl1271_warning("CONFIGURE command NOK");
  398. return ret;
  399. }
  400. return 0;
  401. }
  402. int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
  403. {
  404. struct cmd_enabledisable_path *cmd;
  405. int ret;
  406. u16 cmd_rx, cmd_tx;
  407. wl1271_debug(DEBUG_CMD, "cmd data path");
  408. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  409. if (!cmd) {
  410. ret = -ENOMEM;
  411. goto out;
  412. }
  413. /* the channel here is only used for calibration, so hardcoded to 1 */
  414. cmd->channel = 1;
  415. if (enable) {
  416. cmd_rx = CMD_ENABLE_RX;
  417. cmd_tx = CMD_ENABLE_TX;
  418. } else {
  419. cmd_rx = CMD_DISABLE_RX;
  420. cmd_tx = CMD_DISABLE_TX;
  421. }
  422. ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
  423. if (ret < 0) {
  424. wl1271_error("rx %s cmd for channel %d failed",
  425. enable ? "start" : "stop", cmd->channel);
  426. goto out;
  427. }
  428. wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
  429. enable ? "start" : "stop", cmd->channel);
  430. ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
  431. if (ret < 0) {
  432. wl1271_error("tx %s cmd for channel %d failed",
  433. enable ? "start" : "stop", cmd->channel);
  434. goto out;
  435. }
  436. wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
  437. enable ? "start" : "stop", cmd->channel);
  438. out:
  439. kfree(cmd);
  440. return ret;
  441. }
  442. int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
  443. {
  444. struct wl1271_cmd_ps_params *ps_params = NULL;
  445. int ret = 0;
  446. wl1271_debug(DEBUG_CMD, "cmd set ps mode");
  447. ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
  448. if (!ps_params) {
  449. ret = -ENOMEM;
  450. goto out;
  451. }
  452. ps_params->ps_mode = ps_mode;
  453. ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
  454. sizeof(*ps_params), 0);
  455. if (ret < 0) {
  456. wl1271_error("cmd set_ps_mode failed");
  457. goto out;
  458. }
  459. out:
  460. kfree(ps_params);
  461. return ret;
  462. }
  463. int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
  464. void *buf, size_t buf_len, int index, u32 rates)
  465. {
  466. struct wl1271_cmd_template_set *cmd;
  467. int ret = 0;
  468. wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
  469. WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
  470. buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
  471. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  472. if (!cmd) {
  473. ret = -ENOMEM;
  474. goto out;
  475. }
  476. cmd->len = cpu_to_le16(buf_len);
  477. cmd->template_type = template_id;
  478. cmd->enabled_rates = cpu_to_le32(rates);
  479. cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
  480. cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
  481. cmd->index = index;
  482. if (buf)
  483. memcpy(cmd->template_data, buf, buf_len);
  484. ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
  485. if (ret < 0) {
  486. wl1271_warning("cmd set_template failed: %d", ret);
  487. goto out_free;
  488. }
  489. out_free:
  490. kfree(cmd);
  491. out:
  492. return ret;
  493. }
  494. int wl1271_cmd_build_null_data(struct wl1271 *wl)
  495. {
  496. struct sk_buff *skb = NULL;
  497. int size;
  498. void *ptr;
  499. int ret = -ENOMEM;
  500. if (wl->bss_type == BSS_TYPE_IBSS) {
  501. size = sizeof(struct wl12xx_null_data_template);
  502. ptr = NULL;
  503. } else {
  504. skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
  505. if (!skb)
  506. goto out;
  507. size = skb->len;
  508. ptr = skb->data;
  509. }
  510. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
  511. wl->basic_rate);
  512. out:
  513. dev_kfree_skb(skb);
  514. if (ret)
  515. wl1271_warning("cmd buld null data failed %d", ret);
  516. return ret;
  517. }
  518. int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
  519. {
  520. struct sk_buff *skb = NULL;
  521. int ret = -ENOMEM;
  522. skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
  523. if (!skb)
  524. goto out;
  525. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
  526. skb->data, skb->len,
  527. CMD_TEMPL_KLV_IDX_NULL_DATA,
  528. wl->basic_rate);
  529. out:
  530. dev_kfree_skb(skb);
  531. if (ret)
  532. wl1271_warning("cmd build klv null data failed %d", ret);
  533. return ret;
  534. }
  535. int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
  536. {
  537. struct sk_buff *skb;
  538. int ret = 0;
  539. skb = ieee80211_pspoll_get(wl->hw, wl->vif);
  540. if (!skb)
  541. goto out;
  542. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
  543. skb->len, 0, wl->basic_rate_set);
  544. out:
  545. dev_kfree_skb(skb);
  546. return ret;
  547. }
  548. int wl1271_cmd_build_probe_req(struct wl1271 *wl,
  549. const u8 *ssid, size_t ssid_len,
  550. const u8 *ie, size_t ie_len, u8 band)
  551. {
  552. struct sk_buff *skb;
  553. int ret;
  554. skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
  555. ie, ie_len);
  556. if (!skb) {
  557. ret = -ENOMEM;
  558. goto out;
  559. }
  560. wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
  561. if (band == IEEE80211_BAND_2GHZ)
  562. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
  563. skb->data, skb->len, 0,
  564. wl->conf.tx.basic_rate);
  565. else
  566. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  567. skb->data, skb->len, 0,
  568. wl->conf.tx.basic_rate_5);
  569. out:
  570. dev_kfree_skb(skb);
  571. return ret;
  572. }
  573. struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
  574. struct sk_buff *skb)
  575. {
  576. int ret;
  577. if (!skb)
  578. skb = ieee80211_ap_probereq_get(wl->hw, wl->vif);
  579. if (!skb)
  580. goto out;
  581. wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
  582. if (wl->band == IEEE80211_BAND_2GHZ)
  583. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
  584. skb->data, skb->len, 0,
  585. wl->conf.tx.basic_rate);
  586. else
  587. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  588. skb->data, skb->len, 0,
  589. wl->conf.tx.basic_rate_5);
  590. if (ret < 0)
  591. wl1271_error("Unable to set ap probe request template.");
  592. out:
  593. return skb;
  594. }
  595. int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
  596. {
  597. int ret;
  598. struct wl12xx_arp_rsp_template tmpl;
  599. struct ieee80211_hdr_3addr *hdr;
  600. struct arphdr *arp_hdr;
  601. memset(&tmpl, 0, sizeof(tmpl));
  602. /* mac80211 header */
  603. hdr = &tmpl.hdr;
  604. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  605. IEEE80211_STYPE_DATA |
  606. IEEE80211_FCTL_TODS);
  607. memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN);
  608. memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN);
  609. memset(hdr->addr3, 0xff, ETH_ALEN);
  610. /* llc layer */
  611. memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
  612. tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
  613. /* arp header */
  614. arp_hdr = &tmpl.arp_hdr;
  615. arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
  616. arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
  617. arp_hdr->ar_hln = ETH_ALEN;
  618. arp_hdr->ar_pln = 4;
  619. arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
  620. /* arp payload */
  621. memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN);
  622. tmpl.sender_ip = ip_addr;
  623. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
  624. &tmpl, sizeof(tmpl), 0,
  625. wl->basic_rate);
  626. return ret;
  627. }
  628. int wl1271_build_qos_null_data(struct wl1271 *wl)
  629. {
  630. struct ieee80211_qos_hdr template;
  631. memset(&template, 0, sizeof(template));
  632. memcpy(template.addr1, wl->bssid, ETH_ALEN);
  633. memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
  634. memcpy(template.addr3, wl->bssid, ETH_ALEN);
  635. template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  636. IEEE80211_STYPE_QOS_NULLFUNC |
  637. IEEE80211_FCTL_TODS);
  638. /* FIXME: not sure what priority to use here */
  639. template.qos_ctrl = cpu_to_le16(0);
  640. return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
  641. sizeof(template), 0,
  642. wl->basic_rate);
  643. }
  644. int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id)
  645. {
  646. struct wl1271_cmd_set_sta_keys *cmd;
  647. int ret = 0;
  648. wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
  649. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  650. if (!cmd) {
  651. ret = -ENOMEM;
  652. goto out;
  653. }
  654. cmd->id = id;
  655. cmd->key_action = cpu_to_le16(KEY_SET_ID);
  656. cmd->key_type = KEY_WEP;
  657. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  658. if (ret < 0) {
  659. wl1271_warning("cmd set_default_wep_key failed: %d", ret);
  660. goto out;
  661. }
  662. out:
  663. kfree(cmd);
  664. return ret;
  665. }
  666. int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id)
  667. {
  668. struct wl1271_cmd_set_ap_keys *cmd;
  669. int ret = 0;
  670. wl1271_debug(DEBUG_CMD, "cmd set_ap_default_wep_key %d", id);
  671. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  672. if (!cmd) {
  673. ret = -ENOMEM;
  674. goto out;
  675. }
  676. cmd->hlid = WL1271_AP_BROADCAST_HLID;
  677. cmd->key_id = id;
  678. cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
  679. cmd->key_action = cpu_to_le16(KEY_SET_ID);
  680. cmd->key_type = KEY_WEP;
  681. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  682. if (ret < 0) {
  683. wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret);
  684. goto out;
  685. }
  686. out:
  687. kfree(cmd);
  688. return ret;
  689. }
  690. int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
  691. u8 key_size, const u8 *key, const u8 *addr,
  692. u32 tx_seq_32, u16 tx_seq_16)
  693. {
  694. struct wl1271_cmd_set_sta_keys *cmd;
  695. int ret = 0;
  696. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  697. if (!cmd) {
  698. ret = -ENOMEM;
  699. goto out;
  700. }
  701. if (key_type != KEY_WEP)
  702. memcpy(cmd->addr, addr, ETH_ALEN);
  703. cmd->key_action = cpu_to_le16(action);
  704. cmd->key_size = key_size;
  705. cmd->key_type = key_type;
  706. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  707. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  708. /* we have only one SSID profile */
  709. cmd->ssid_profile = 0;
  710. cmd->id = id;
  711. if (key_type == KEY_TKIP) {
  712. /*
  713. * We get the key in the following form:
  714. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  715. * but the target is expecting:
  716. * TKIP - RX MIC - TX MIC
  717. */
  718. memcpy(cmd->key, key, 16);
  719. memcpy(cmd->key + 16, key + 24, 8);
  720. memcpy(cmd->key + 24, key + 16, 8);
  721. } else {
  722. memcpy(cmd->key, key, key_size);
  723. }
  724. wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
  725. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  726. if (ret < 0) {
  727. wl1271_warning("could not set keys");
  728. goto out;
  729. }
  730. out:
  731. kfree(cmd);
  732. return ret;
  733. }
  734. int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
  735. u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
  736. u16 tx_seq_16)
  737. {
  738. struct wl1271_cmd_set_ap_keys *cmd;
  739. int ret = 0;
  740. u8 lid_type;
  741. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  742. if (!cmd)
  743. return -ENOMEM;
  744. if (hlid == WL1271_AP_BROADCAST_HLID) {
  745. if (key_type == KEY_WEP)
  746. lid_type = WEP_DEFAULT_LID_TYPE;
  747. else
  748. lid_type = BROADCAST_LID_TYPE;
  749. } else {
  750. lid_type = UNICAST_LID_TYPE;
  751. }
  752. wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
  753. " hlid: %d", (int)action, (int)id, (int)lid_type,
  754. (int)key_type, (int)hlid);
  755. cmd->lid_key_type = lid_type;
  756. cmd->hlid = hlid;
  757. cmd->key_action = cpu_to_le16(action);
  758. cmd->key_size = key_size;
  759. cmd->key_type = key_type;
  760. cmd->key_id = id;
  761. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  762. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  763. if (key_type == KEY_TKIP) {
  764. /*
  765. * We get the key in the following form:
  766. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  767. * but the target is expecting:
  768. * TKIP - RX MIC - TX MIC
  769. */
  770. memcpy(cmd->key, key, 16);
  771. memcpy(cmd->key + 16, key + 24, 8);
  772. memcpy(cmd->key + 24, key + 16, 8);
  773. } else {
  774. memcpy(cmd->key, key, key_size);
  775. }
  776. wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
  777. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  778. if (ret < 0) {
  779. wl1271_warning("could not set ap keys");
  780. goto out;
  781. }
  782. out:
  783. kfree(cmd);
  784. return ret;
  785. }
  786. int wl1271_cmd_disconnect(struct wl1271 *wl)
  787. {
  788. struct wl1271_cmd_disconnect *cmd;
  789. int ret = 0;
  790. wl1271_debug(DEBUG_CMD, "cmd disconnect");
  791. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  792. if (!cmd) {
  793. ret = -ENOMEM;
  794. goto out;
  795. }
  796. cmd->rx_config_options = cpu_to_le32(wl->rx_config);
  797. cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
  798. /* disconnect reason is not used in immediate disconnections */
  799. cmd->type = DISCONNECT_IMMEDIATE;
  800. ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
  801. if (ret < 0) {
  802. wl1271_error("failed to send disconnect command");
  803. goto out_free;
  804. }
  805. ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
  806. if (ret < 0)
  807. wl1271_error("cmd disconnect event completion error");
  808. out_free:
  809. kfree(cmd);
  810. out:
  811. return ret;
  812. }
  813. int wl1271_cmd_set_sta_state(struct wl1271 *wl)
  814. {
  815. struct wl1271_cmd_set_sta_state *cmd;
  816. int ret = 0;
  817. wl1271_debug(DEBUG_CMD, "cmd set sta state");
  818. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  819. if (!cmd) {
  820. ret = -ENOMEM;
  821. goto out;
  822. }
  823. cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
  824. ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0);
  825. if (ret < 0) {
  826. wl1271_error("failed to send set STA state command");
  827. goto out_free;
  828. }
  829. out_free:
  830. kfree(cmd);
  831. out:
  832. return ret;
  833. }
  834. int wl1271_cmd_start_bss(struct wl1271 *wl)
  835. {
  836. struct wl1271_cmd_bss_start *cmd;
  837. struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf;
  838. int ret;
  839. wl1271_debug(DEBUG_CMD, "cmd start bss");
  840. /*
  841. * FIXME: We currently do not support hidden SSID. The real SSID
  842. * should be fetched from mac80211 first.
  843. */
  844. if (wl->ssid_len == 0) {
  845. wl1271_warning("Hidden SSID currently not supported for AP");
  846. ret = -EINVAL;
  847. goto out;
  848. }
  849. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  850. if (!cmd) {
  851. ret = -ENOMEM;
  852. goto out;
  853. }
  854. memcpy(cmd->bssid, bss_conf->bssid, ETH_ALEN);
  855. cmd->aging_period = cpu_to_le16(WL1271_AP_DEF_INACTIV_SEC);
  856. cmd->bss_index = WL1271_AP_BSS_INDEX;
  857. cmd->global_hlid = WL1271_AP_GLOBAL_HLID;
  858. cmd->broadcast_hlid = WL1271_AP_BROADCAST_HLID;
  859. cmd->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
  860. cmd->beacon_interval = cpu_to_le16(wl->beacon_int);
  861. cmd->dtim_interval = bss_conf->dtim_period;
  862. cmd->beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
  863. cmd->channel = wl->channel;
  864. cmd->ssid_len = wl->ssid_len;
  865. cmd->ssid_type = SSID_TYPE_PUBLIC;
  866. memcpy(cmd->ssid, wl->ssid, wl->ssid_len);
  867. switch (wl->band) {
  868. case IEEE80211_BAND_2GHZ:
  869. cmd->band = RADIO_BAND_2_4GHZ;
  870. break;
  871. case IEEE80211_BAND_5GHZ:
  872. cmd->band = RADIO_BAND_5GHZ;
  873. break;
  874. default:
  875. wl1271_warning("bss start - unknown band: %d", (int)wl->band);
  876. cmd->band = RADIO_BAND_2_4GHZ;
  877. break;
  878. }
  879. ret = wl1271_cmd_send(wl, CMD_BSS_START, cmd, sizeof(*cmd), 0);
  880. if (ret < 0) {
  881. wl1271_error("failed to initiate cmd start bss");
  882. goto out_free;
  883. }
  884. out_free:
  885. kfree(cmd);
  886. out:
  887. return ret;
  888. }
  889. int wl1271_cmd_stop_bss(struct wl1271 *wl)
  890. {
  891. struct wl1271_cmd_bss_start *cmd;
  892. int ret;
  893. wl1271_debug(DEBUG_CMD, "cmd stop bss");
  894. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  895. if (!cmd) {
  896. ret = -ENOMEM;
  897. goto out;
  898. }
  899. cmd->bss_index = WL1271_AP_BSS_INDEX;
  900. ret = wl1271_cmd_send(wl, CMD_BSS_STOP, cmd, sizeof(*cmd), 0);
  901. if (ret < 0) {
  902. wl1271_error("failed to initiate cmd stop bss");
  903. goto out_free;
  904. }
  905. out_free:
  906. kfree(cmd);
  907. out:
  908. return ret;
  909. }
  910. int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
  911. {
  912. struct wl1271_cmd_add_sta *cmd;
  913. int ret;
  914. wl1271_debug(DEBUG_CMD, "cmd add sta %d", (int)hlid);
  915. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  916. if (!cmd) {
  917. ret = -ENOMEM;
  918. goto out;
  919. }
  920. /* currently we don't support UAPSD */
  921. cmd->sp_len = 0;
  922. memcpy(cmd->addr, sta->addr, ETH_ALEN);
  923. cmd->bss_index = WL1271_AP_BSS_INDEX;
  924. cmd->aid = sta->aid;
  925. cmd->hlid = hlid;
  926. cmd->wmm = sta->wme ? 1 : 0;
  927. cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl,
  928. sta->supp_rates[wl->band]));
  929. wl1271_debug(DEBUG_CMD, "new sta rates: 0x%x", cmd->supported_rates);
  930. ret = wl1271_cmd_send(wl, CMD_ADD_STA, cmd, sizeof(*cmd), 0);
  931. if (ret < 0) {
  932. wl1271_error("failed to initiate cmd add sta");
  933. goto out_free;
  934. }
  935. out_free:
  936. kfree(cmd);
  937. out:
  938. return ret;
  939. }
  940. int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid)
  941. {
  942. struct wl1271_cmd_remove_sta *cmd;
  943. int ret;
  944. wl1271_debug(DEBUG_CMD, "cmd remove sta %d", (int)hlid);
  945. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  946. if (!cmd) {
  947. ret = -ENOMEM;
  948. goto out;
  949. }
  950. cmd->hlid = hlid;
  951. /* We never send a deauth, mac80211 is in charge of this */
  952. cmd->reason_opcode = 0;
  953. cmd->send_deauth_flag = 0;
  954. ret = wl1271_cmd_send(wl, CMD_REMOVE_STA, cmd, sizeof(*cmd), 0);
  955. if (ret < 0) {
  956. wl1271_error("failed to initiate cmd remove sta");
  957. goto out_free;
  958. }
  959. /*
  960. * We are ok with a timeout here. The event is sometimes not sent
  961. * due to a firmware bug.
  962. */
  963. wl1271_cmd_wait_for_event_or_timeout(wl, STA_REMOVE_COMPLETE_EVENT_ID);
  964. out_free:
  965. kfree(cmd);
  966. out:
  967. return ret;
  968. }
  969. int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
  970. {
  971. struct wl12xx_cmd_config_fwlog *cmd;
  972. int ret = 0;
  973. wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
  974. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  975. if (!cmd) {
  976. ret = -ENOMEM;
  977. goto out;
  978. }
  979. cmd->logger_mode = wl->conf.fwlog.mode;
  980. cmd->log_severity = wl->conf.fwlog.severity;
  981. cmd->timestamp = wl->conf.fwlog.timestamp;
  982. cmd->output = wl->conf.fwlog.output;
  983. cmd->threshold = wl->conf.fwlog.threshold;
  984. ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
  985. if (ret < 0) {
  986. wl1271_error("failed to send config firmware logger command");
  987. goto out_free;
  988. }
  989. out_free:
  990. kfree(cmd);
  991. out:
  992. return ret;
  993. }
  994. int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
  995. {
  996. struct wl12xx_cmd_start_fwlog *cmd;
  997. int ret = 0;
  998. wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
  999. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1000. if (!cmd) {
  1001. ret = -ENOMEM;
  1002. goto out;
  1003. }
  1004. ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
  1005. if (ret < 0) {
  1006. wl1271_error("failed to send start firmware logger command");
  1007. goto out_free;
  1008. }
  1009. out_free:
  1010. kfree(cmd);
  1011. out:
  1012. return ret;
  1013. }
  1014. int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
  1015. {
  1016. struct wl12xx_cmd_stop_fwlog *cmd;
  1017. int ret = 0;
  1018. wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
  1019. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1020. if (!cmd) {
  1021. ret = -ENOMEM;
  1022. goto out;
  1023. }
  1024. ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
  1025. if (ret < 0) {
  1026. wl1271_error("failed to send stop firmware logger command");
  1027. goto out_free;
  1028. }
  1029. out_free:
  1030. kfree(cmd);
  1031. out:
  1032. return ret;
  1033. }