cmd.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845
  1. /**
  2. * This file contains the handling of command.
  3. * It prepares command and sends it to firmware when it is ready.
  4. */
  5. #include <linux/kfifo.h>
  6. #include <linux/sched.h>
  7. #include <linux/slab.h>
  8. #include <linux/if_arp.h>
  9. #include "decl.h"
  10. #include "cfg.h"
  11. #include "cmd.h"
  12. #define CAL_NF(nf) ((s32)(-(s32)(nf)))
  13. #define CAL_RSSI(snr, nf) ((s32)((s32)(snr) + CAL_NF(nf)))
  14. static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
  15. /**
  16. * @brief Simple callback that copies response back into command
  17. *
  18. * @param priv A pointer to struct lbs_private structure
  19. * @param extra A pointer to the original command structure for which
  20. * 'resp' is a response
  21. * @param resp A pointer to the command response
  22. *
  23. * @return 0 on success, error on failure
  24. */
  25. int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
  26. struct cmd_header *resp)
  27. {
  28. struct cmd_header *buf = (void *)extra;
  29. uint16_t copy_len;
  30. copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
  31. memcpy(buf, resp, copy_len);
  32. return 0;
  33. }
  34. EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
  35. /**
  36. * @brief Simple callback that ignores the result. Use this if
  37. * you just want to send a command to the hardware, but don't
  38. * care for the result.
  39. *
  40. * @param priv ignored
  41. * @param extra ignored
  42. * @param resp ignored
  43. *
  44. * @return 0 for success
  45. */
  46. static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
  47. struct cmd_header *resp)
  48. {
  49. return 0;
  50. }
  51. /**
  52. * @brief Checks whether a command is allowed in Power Save mode
  53. *
  54. * @param command the command ID
  55. * @return 1 if allowed, 0 if not allowed
  56. */
  57. static u8 is_command_allowed_in_ps(u16 cmd)
  58. {
  59. switch (cmd) {
  60. case CMD_802_11_RSSI:
  61. return 1;
  62. case CMD_802_11_HOST_SLEEP_CFG:
  63. return 1;
  64. default:
  65. break;
  66. }
  67. return 0;
  68. }
  69. /**
  70. * @brief This function checks if the command is allowed.
  71. *
  72. * @param priv A pointer to lbs_private structure
  73. * @return allowed or not allowed.
  74. */
  75. static int lbs_is_cmd_allowed(struct lbs_private *priv)
  76. {
  77. int ret = 1;
  78. lbs_deb_enter(LBS_DEB_CMD);
  79. if (!priv->is_auto_deep_sleep_enabled) {
  80. if (priv->is_deep_sleep) {
  81. lbs_deb_cmd("command not allowed in deep sleep\n");
  82. ret = 0;
  83. }
  84. }
  85. lbs_deb_leave(LBS_DEB_CMD);
  86. return ret;
  87. }
  88. /**
  89. * @brief Updates the hardware details like MAC address and regulatory region
  90. *
  91. * @param priv A pointer to struct lbs_private structure
  92. *
  93. * @return 0 on success, error on failure
  94. */
  95. int lbs_update_hw_spec(struct lbs_private *priv)
  96. {
  97. struct cmd_ds_get_hw_spec cmd;
  98. int ret = -1;
  99. u32 i;
  100. lbs_deb_enter(LBS_DEB_CMD);
  101. memset(&cmd, 0, sizeof(cmd));
  102. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  103. memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
  104. ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
  105. if (ret)
  106. goto out;
  107. priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
  108. /* The firmware release is in an interesting format: the patch
  109. * level is in the most significant nibble ... so fix that: */
  110. priv->fwrelease = le32_to_cpu(cmd.fwrelease);
  111. priv->fwrelease = (priv->fwrelease << 8) |
  112. (priv->fwrelease >> 24 & 0xff);
  113. /* Some firmware capabilities:
  114. * CF card firmware 5.0.16p0: cap 0x00000303
  115. * USB dongle firmware 5.110.17p2: cap 0x00000303
  116. */
  117. lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
  118. cmd.permanentaddr,
  119. priv->fwrelease >> 24 & 0xff,
  120. priv->fwrelease >> 16 & 0xff,
  121. priv->fwrelease >> 8 & 0xff,
  122. priv->fwrelease & 0xff,
  123. priv->fwcapinfo);
  124. lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
  125. cmd.hwifversion, cmd.version);
  126. /* Clamp region code to 8-bit since FW spec indicates that it should
  127. * only ever be 8-bit, even though the field size is 16-bit. Some firmware
  128. * returns non-zero high 8 bits here.
  129. *
  130. * Firmware version 4.0.102 used in CF8381 has region code shifted. We
  131. * need to check for this problem and handle it properly.
  132. */
  133. if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
  134. priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
  135. else
  136. priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
  137. for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
  138. /* use the region code to search for the index */
  139. if (priv->regioncode == lbs_region_code_to_index[i])
  140. break;
  141. }
  142. /* if it's unidentified region code, use the default (USA) */
  143. if (i >= MRVDRV_MAX_REGION_CODE) {
  144. priv->regioncode = 0x10;
  145. lbs_pr_info("unidentified region code; using the default (USA)\n");
  146. }
  147. if (priv->current_addr[0] == 0xff)
  148. memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
  149. memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
  150. if (priv->mesh_dev)
  151. memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
  152. out:
  153. lbs_deb_leave(LBS_DEB_CMD);
  154. return ret;
  155. }
  156. static int lbs_ret_host_sleep_cfg(struct lbs_private *priv, unsigned long dummy,
  157. struct cmd_header *resp)
  158. {
  159. lbs_deb_enter(LBS_DEB_CMD);
  160. if (priv->is_host_sleep_activated) {
  161. priv->is_host_sleep_configured = 0;
  162. if (priv->psstate == PS_STATE_FULL_POWER) {
  163. priv->is_host_sleep_activated = 0;
  164. wake_up_interruptible(&priv->host_sleep_q);
  165. }
  166. } else {
  167. priv->is_host_sleep_configured = 1;
  168. }
  169. lbs_deb_leave(LBS_DEB_CMD);
  170. return 0;
  171. }
  172. int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
  173. struct wol_config *p_wol_config)
  174. {
  175. struct cmd_ds_host_sleep cmd_config;
  176. int ret;
  177. cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
  178. cmd_config.criteria = cpu_to_le32(criteria);
  179. cmd_config.gpio = priv->wol_gpio;
  180. cmd_config.gap = priv->wol_gap;
  181. if (p_wol_config != NULL)
  182. memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
  183. sizeof(struct wol_config));
  184. else
  185. cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
  186. ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config.hdr,
  187. le16_to_cpu(cmd_config.hdr.size),
  188. lbs_ret_host_sleep_cfg, 0);
  189. if (!ret) {
  190. if (p_wol_config)
  191. memcpy((uint8_t *) p_wol_config,
  192. (uint8_t *)&cmd_config.wol_conf,
  193. sizeof(struct wol_config));
  194. } else {
  195. lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
  196. }
  197. return ret;
  198. }
  199. EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
  200. static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
  201. u16 cmd_action)
  202. {
  203. struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
  204. lbs_deb_enter(LBS_DEB_CMD);
  205. cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
  206. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
  207. sizeof(struct cmd_header));
  208. psm->action = cpu_to_le16(cmd_action);
  209. psm->multipledtim = 0;
  210. switch (cmd_action) {
  211. case CMD_SUBCMD_ENTER_PS:
  212. lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
  213. psm->locallisteninterval = 0;
  214. psm->nullpktinterval = 0;
  215. psm->multipledtim =
  216. cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
  217. break;
  218. case CMD_SUBCMD_EXIT_PS:
  219. lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
  220. break;
  221. case CMD_SUBCMD_SLEEP_CONFIRMED:
  222. lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
  223. break;
  224. default:
  225. break;
  226. }
  227. lbs_deb_leave(LBS_DEB_CMD);
  228. return 0;
  229. }
  230. int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
  231. struct sleep_params *sp)
  232. {
  233. struct cmd_ds_802_11_sleep_params cmd;
  234. int ret;
  235. lbs_deb_enter(LBS_DEB_CMD);
  236. if (cmd_action == CMD_ACT_GET) {
  237. memset(&cmd, 0, sizeof(cmd));
  238. } else {
  239. cmd.error = cpu_to_le16(sp->sp_error);
  240. cmd.offset = cpu_to_le16(sp->sp_offset);
  241. cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
  242. cmd.calcontrol = sp->sp_calcontrol;
  243. cmd.externalsleepclk = sp->sp_extsleepclk;
  244. cmd.reserved = cpu_to_le16(sp->sp_reserved);
  245. }
  246. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  247. cmd.action = cpu_to_le16(cmd_action);
  248. ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
  249. if (!ret) {
  250. lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
  251. "calcontrol 0x%x extsleepclk 0x%x\n",
  252. le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
  253. le16_to_cpu(cmd.stabletime), cmd.calcontrol,
  254. cmd.externalsleepclk);
  255. sp->sp_error = le16_to_cpu(cmd.error);
  256. sp->sp_offset = le16_to_cpu(cmd.offset);
  257. sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
  258. sp->sp_calcontrol = cmd.calcontrol;
  259. sp->sp_extsleepclk = cmd.externalsleepclk;
  260. sp->sp_reserved = le16_to_cpu(cmd.reserved);
  261. }
  262. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  263. return 0;
  264. }
  265. static int lbs_wait_for_ds_awake(struct lbs_private *priv)
  266. {
  267. int ret = 0;
  268. lbs_deb_enter(LBS_DEB_CMD);
  269. if (priv->is_deep_sleep) {
  270. if (!wait_event_interruptible_timeout(priv->ds_awake_q,
  271. !priv->is_deep_sleep, (10 * HZ))) {
  272. lbs_pr_err("ds_awake_q: timer expired\n");
  273. ret = -1;
  274. }
  275. }
  276. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  277. return ret;
  278. }
  279. int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
  280. {
  281. int ret = 0;
  282. lbs_deb_enter(LBS_DEB_CMD);
  283. if (deep_sleep) {
  284. if (priv->is_deep_sleep != 1) {
  285. lbs_deb_cmd("deep sleep: sleep\n");
  286. BUG_ON(!priv->enter_deep_sleep);
  287. ret = priv->enter_deep_sleep(priv);
  288. if (!ret) {
  289. netif_stop_queue(priv->dev);
  290. netif_carrier_off(priv->dev);
  291. }
  292. } else {
  293. lbs_pr_err("deep sleep: already enabled\n");
  294. }
  295. } else {
  296. if (priv->is_deep_sleep) {
  297. lbs_deb_cmd("deep sleep: wakeup\n");
  298. BUG_ON(!priv->exit_deep_sleep);
  299. ret = priv->exit_deep_sleep(priv);
  300. if (!ret) {
  301. ret = lbs_wait_for_ds_awake(priv);
  302. if (ret)
  303. lbs_pr_err("deep sleep: wakeup"
  304. "failed\n");
  305. }
  306. }
  307. }
  308. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  309. return ret;
  310. }
  311. static int lbs_ret_host_sleep_activate(struct lbs_private *priv,
  312. unsigned long dummy,
  313. struct cmd_header *cmd)
  314. {
  315. lbs_deb_enter(LBS_DEB_FW);
  316. priv->is_host_sleep_activated = 1;
  317. wake_up_interruptible(&priv->host_sleep_q);
  318. lbs_deb_leave(LBS_DEB_FW);
  319. return 0;
  320. }
  321. int lbs_set_host_sleep(struct lbs_private *priv, int host_sleep)
  322. {
  323. struct cmd_header cmd;
  324. int ret = 0;
  325. uint32_t criteria = EHS_REMOVE_WAKEUP;
  326. lbs_deb_enter(LBS_DEB_CMD);
  327. if (host_sleep) {
  328. if (priv->is_host_sleep_activated != 1) {
  329. memset(&cmd, 0, sizeof(cmd));
  330. ret = lbs_host_sleep_cfg(priv, priv->wol_criteria,
  331. (struct wol_config *)NULL);
  332. if (ret) {
  333. lbs_pr_info("Host sleep configuration failed: "
  334. "%d\n", ret);
  335. return ret;
  336. }
  337. if (priv->psstate == PS_STATE_FULL_POWER) {
  338. ret = __lbs_cmd(priv,
  339. CMD_802_11_HOST_SLEEP_ACTIVATE,
  340. &cmd,
  341. sizeof(cmd),
  342. lbs_ret_host_sleep_activate, 0);
  343. if (ret)
  344. lbs_pr_info("HOST_SLEEP_ACTIVATE "
  345. "failed: %d\n", ret);
  346. }
  347. if (!wait_event_interruptible_timeout(
  348. priv->host_sleep_q,
  349. priv->is_host_sleep_activated,
  350. (10 * HZ))) {
  351. lbs_pr_err("host_sleep_q: timer expired\n");
  352. ret = -1;
  353. }
  354. } else {
  355. lbs_pr_err("host sleep: already enabled\n");
  356. }
  357. } else {
  358. if (priv->is_host_sleep_activated)
  359. ret = lbs_host_sleep_cfg(priv, criteria,
  360. (struct wol_config *)NULL);
  361. }
  362. return ret;
  363. }
  364. /**
  365. * @brief Set an SNMP MIB value
  366. *
  367. * @param priv A pointer to struct lbs_private structure
  368. * @param oid The OID to set in the firmware
  369. * @param val Value to set the OID to
  370. *
  371. * @return 0 on success, error on failure
  372. */
  373. int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
  374. {
  375. struct cmd_ds_802_11_snmp_mib cmd;
  376. int ret;
  377. lbs_deb_enter(LBS_DEB_CMD);
  378. memset(&cmd, 0, sizeof (cmd));
  379. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  380. cmd.action = cpu_to_le16(CMD_ACT_SET);
  381. cmd.oid = cpu_to_le16((u16) oid);
  382. switch (oid) {
  383. case SNMP_MIB_OID_BSS_TYPE:
  384. cmd.bufsize = cpu_to_le16(sizeof(u8));
  385. cmd.value[0] = val;
  386. break;
  387. case SNMP_MIB_OID_11D_ENABLE:
  388. case SNMP_MIB_OID_FRAG_THRESHOLD:
  389. case SNMP_MIB_OID_RTS_THRESHOLD:
  390. case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
  391. case SNMP_MIB_OID_LONG_RETRY_LIMIT:
  392. cmd.bufsize = cpu_to_le16(sizeof(u16));
  393. *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
  394. break;
  395. default:
  396. lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
  397. ret = -EINVAL;
  398. goto out;
  399. }
  400. lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
  401. le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
  402. ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
  403. out:
  404. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  405. return ret;
  406. }
  407. /**
  408. * @brief Get an SNMP MIB value
  409. *
  410. * @param priv A pointer to struct lbs_private structure
  411. * @param oid The OID to retrieve from the firmware
  412. * @param out_val Location for the returned value
  413. *
  414. * @return 0 on success, error on failure
  415. */
  416. int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
  417. {
  418. struct cmd_ds_802_11_snmp_mib cmd;
  419. int ret;
  420. lbs_deb_enter(LBS_DEB_CMD);
  421. memset(&cmd, 0, sizeof (cmd));
  422. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  423. cmd.action = cpu_to_le16(CMD_ACT_GET);
  424. cmd.oid = cpu_to_le16(oid);
  425. ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
  426. if (ret)
  427. goto out;
  428. switch (le16_to_cpu(cmd.bufsize)) {
  429. case sizeof(u8):
  430. *out_val = cmd.value[0];
  431. break;
  432. case sizeof(u16):
  433. *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
  434. break;
  435. default:
  436. lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
  437. oid, le16_to_cpu(cmd.bufsize));
  438. break;
  439. }
  440. out:
  441. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  442. return ret;
  443. }
  444. /**
  445. * @brief Get the min, max, and current TX power
  446. *
  447. * @param priv A pointer to struct lbs_private structure
  448. * @param curlevel Current power level in dBm
  449. * @param minlevel Minimum supported power level in dBm (optional)
  450. * @param maxlevel Maximum supported power level in dBm (optional)
  451. *
  452. * @return 0 on success, error on failure
  453. */
  454. int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
  455. s16 *maxlevel)
  456. {
  457. struct cmd_ds_802_11_rf_tx_power cmd;
  458. int ret;
  459. lbs_deb_enter(LBS_DEB_CMD);
  460. memset(&cmd, 0, sizeof(cmd));
  461. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  462. cmd.action = cpu_to_le16(CMD_ACT_GET);
  463. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
  464. if (ret == 0) {
  465. *curlevel = le16_to_cpu(cmd.curlevel);
  466. if (minlevel)
  467. *minlevel = cmd.minlevel;
  468. if (maxlevel)
  469. *maxlevel = cmd.maxlevel;
  470. }
  471. lbs_deb_leave(LBS_DEB_CMD);
  472. return ret;
  473. }
  474. /**
  475. * @brief Set the TX power
  476. *
  477. * @param priv A pointer to struct lbs_private structure
  478. * @param dbm The desired power level in dBm
  479. *
  480. * @return 0 on success, error on failure
  481. */
  482. int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
  483. {
  484. struct cmd_ds_802_11_rf_tx_power cmd;
  485. int ret;
  486. lbs_deb_enter(LBS_DEB_CMD);
  487. memset(&cmd, 0, sizeof(cmd));
  488. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  489. cmd.action = cpu_to_le16(CMD_ACT_SET);
  490. cmd.curlevel = cpu_to_le16(dbm);
  491. lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
  492. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
  493. lbs_deb_leave(LBS_DEB_CMD);
  494. return ret;
  495. }
  496. /**
  497. * @brief Enable or disable monitor mode (only implemented on OLPC usb8388 FW)
  498. *
  499. * @param priv A pointer to struct lbs_private structure
  500. * @param enable 1 to enable monitor mode, 0 to disable
  501. *
  502. * @return 0 on success, error on failure
  503. */
  504. int lbs_set_monitor_mode(struct lbs_private *priv, int enable)
  505. {
  506. struct cmd_ds_802_11_monitor_mode cmd;
  507. int ret;
  508. memset(&cmd, 0, sizeof(cmd));
  509. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  510. cmd.action = cpu_to_le16(CMD_ACT_SET);
  511. if (enable)
  512. cmd.mode = cpu_to_le16(0x1);
  513. lbs_deb_cmd("SET_MONITOR_MODE: %d\n", enable);
  514. ret = lbs_cmd_with_response(priv, CMD_802_11_MONITOR_MODE, &cmd);
  515. if (ret == 0) {
  516. priv->dev->type = enable ? ARPHRD_IEEE80211_RADIOTAP :
  517. ARPHRD_ETHER;
  518. }
  519. lbs_deb_leave(LBS_DEB_CMD);
  520. return ret;
  521. }
  522. /**
  523. * @brief Get the radio channel
  524. *
  525. * @param priv A pointer to struct lbs_private structure
  526. *
  527. * @return The channel on success, error on failure
  528. */
  529. static int lbs_get_channel(struct lbs_private *priv)
  530. {
  531. struct cmd_ds_802_11_rf_channel cmd;
  532. int ret = 0;
  533. lbs_deb_enter(LBS_DEB_CMD);
  534. memset(&cmd, 0, sizeof(cmd));
  535. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  536. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
  537. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  538. if (ret)
  539. goto out;
  540. ret = le16_to_cpu(cmd.channel);
  541. lbs_deb_cmd("current radio channel is %d\n", ret);
  542. out:
  543. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  544. return ret;
  545. }
  546. int lbs_update_channel(struct lbs_private *priv)
  547. {
  548. int ret;
  549. /* the channel in f/w could be out of sync; get the current channel */
  550. lbs_deb_enter(LBS_DEB_ASSOC);
  551. ret = lbs_get_channel(priv);
  552. if (ret > 0) {
  553. priv->channel = ret;
  554. ret = 0;
  555. }
  556. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  557. return ret;
  558. }
  559. /**
  560. * @brief Set the radio channel
  561. *
  562. * @param priv A pointer to struct lbs_private structure
  563. * @param channel The desired channel, or 0 to clear a locked channel
  564. *
  565. * @return 0 on success, error on failure
  566. */
  567. int lbs_set_channel(struct lbs_private *priv, u8 channel)
  568. {
  569. struct cmd_ds_802_11_rf_channel cmd;
  570. #ifdef DEBUG
  571. u8 old_channel = priv->channel;
  572. #endif
  573. int ret = 0;
  574. lbs_deb_enter(LBS_DEB_CMD);
  575. memset(&cmd, 0, sizeof(cmd));
  576. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  577. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
  578. cmd.channel = cpu_to_le16(channel);
  579. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  580. if (ret)
  581. goto out;
  582. priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
  583. lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
  584. priv->channel);
  585. out:
  586. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  587. return ret;
  588. }
  589. /**
  590. * @brief Get current RSSI and noise floor
  591. *
  592. * @param priv A pointer to struct lbs_private structure
  593. * @param rssi On successful return, signal level in mBm
  594. *
  595. * @return The channel on success, error on failure
  596. */
  597. int lbs_get_rssi(struct lbs_private *priv, s8 *rssi, s8 *nf)
  598. {
  599. struct cmd_ds_802_11_rssi cmd;
  600. int ret = 0;
  601. lbs_deb_enter(LBS_DEB_CMD);
  602. BUG_ON(rssi == NULL);
  603. BUG_ON(nf == NULL);
  604. memset(&cmd, 0, sizeof(cmd));
  605. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  606. /* Average SNR over last 8 beacons */
  607. cmd.n_or_snr = cpu_to_le16(8);
  608. ret = lbs_cmd_with_response(priv, CMD_802_11_RSSI, &cmd);
  609. if (ret == 0) {
  610. *nf = CAL_NF(le16_to_cpu(cmd.nf));
  611. *rssi = CAL_RSSI(le16_to_cpu(cmd.n_or_snr), le16_to_cpu(cmd.nf));
  612. }
  613. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  614. return ret;
  615. }
  616. /**
  617. * @brief Send regulatory and 802.11d domain information to the firmware
  618. *
  619. * @param priv pointer to struct lbs_private
  620. * @param request cfg80211 regulatory request structure
  621. * @param bands the device's supported bands and channels
  622. *
  623. * @return 0 on success, error code on failure
  624. */
  625. int lbs_set_11d_domain_info(struct lbs_private *priv,
  626. struct regulatory_request *request,
  627. struct ieee80211_supported_band **bands)
  628. {
  629. struct cmd_ds_802_11d_domain_info cmd;
  630. struct mrvl_ie_domain_param_set *domain = &cmd.domain;
  631. struct ieee80211_country_ie_triplet *t;
  632. enum ieee80211_band band;
  633. struct ieee80211_channel *ch;
  634. u8 num_triplet = 0;
  635. u8 num_parsed_chan = 0;
  636. u8 first_channel = 0, next_chan = 0, max_pwr = 0;
  637. u8 i, flag = 0;
  638. size_t triplet_size;
  639. int ret;
  640. lbs_deb_enter(LBS_DEB_11D);
  641. memset(&cmd, 0, sizeof(cmd));
  642. cmd.action = cpu_to_le16(CMD_ACT_SET);
  643. lbs_deb_11d("Setting country code '%c%c'\n",
  644. request->alpha2[0], request->alpha2[1]);
  645. domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN);
  646. /* Set country code */
  647. domain->country_code[0] = request->alpha2[0];
  648. domain->country_code[1] = request->alpha2[1];
  649. domain->country_code[2] = ' ';
  650. /* Now set up the channel triplets; firmware is somewhat picky here
  651. * and doesn't validate channel numbers and spans; hence it would
  652. * interpret a triplet of (36, 4, 20) as channels 36, 37, 38, 39. Since
  653. * the last 3 aren't valid channels, the driver is responsible for
  654. * splitting that up into 4 triplet pairs of (36, 1, 20) + (40, 1, 20)
  655. * etc.
  656. */
  657. for (band = 0;
  658. (band < IEEE80211_NUM_BANDS) && (num_triplet < MAX_11D_TRIPLETS);
  659. band++) {
  660. if (!bands[band])
  661. continue;
  662. for (i = 0;
  663. (i < bands[band]->n_channels) && (num_triplet < MAX_11D_TRIPLETS);
  664. i++) {
  665. ch = &bands[band]->channels[i];
  666. if (ch->flags & IEEE80211_CHAN_DISABLED)
  667. continue;
  668. if (!flag) {
  669. flag = 1;
  670. next_chan = first_channel = (u32) ch->hw_value;
  671. max_pwr = ch->max_power;
  672. num_parsed_chan = 1;
  673. continue;
  674. }
  675. if ((ch->hw_value == next_chan + 1) &&
  676. (ch->max_power == max_pwr)) {
  677. /* Consolidate adjacent channels */
  678. next_chan++;
  679. num_parsed_chan++;
  680. } else {
  681. /* Add this triplet */
  682. lbs_deb_11d("11D triplet (%d, %d, %d)\n",
  683. first_channel, num_parsed_chan,
  684. max_pwr);
  685. t = &domain->triplet[num_triplet];
  686. t->chans.first_channel = first_channel;
  687. t->chans.num_channels = num_parsed_chan;
  688. t->chans.max_power = max_pwr;
  689. num_triplet++;
  690. flag = 0;
  691. }
  692. }
  693. if (flag) {
  694. /* Add last triplet */
  695. lbs_deb_11d("11D triplet (%d, %d, %d)\n", first_channel,
  696. num_parsed_chan, max_pwr);
  697. t = &domain->triplet[num_triplet];
  698. t->chans.first_channel = first_channel;
  699. t->chans.num_channels = num_parsed_chan;
  700. t->chans.max_power = max_pwr;
  701. num_triplet++;
  702. }
  703. }
  704. lbs_deb_11d("# triplets %d\n", num_triplet);
  705. /* Set command header sizes */
  706. triplet_size = num_triplet * sizeof(struct ieee80211_country_ie_triplet);
  707. domain->header.len = cpu_to_le16(sizeof(domain->country_code) +
  708. triplet_size);
  709. lbs_deb_hex(LBS_DEB_11D, "802.11D domain param set",
  710. (u8 *) &cmd.domain.country_code,
  711. le16_to_cpu(domain->header.len));
  712. cmd.hdr.size = cpu_to_le16(sizeof(cmd.hdr) +
  713. sizeof(cmd.action) +
  714. sizeof(cmd.domain.header) +
  715. sizeof(cmd.domain.country_code) +
  716. triplet_size);
  717. ret = lbs_cmd_with_response(priv, CMD_802_11D_DOMAIN_INFO, &cmd);
  718. lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
  719. return ret;
  720. }
  721. static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
  722. u8 cmd_action, void *pdata_buf)
  723. {
  724. struct lbs_offset_value *offval;
  725. lbs_deb_enter(LBS_DEB_CMD);
  726. offval = (struct lbs_offset_value *)pdata_buf;
  727. switch (le16_to_cpu(cmdptr->command)) {
  728. case CMD_MAC_REG_ACCESS:
  729. {
  730. struct cmd_ds_mac_reg_access *macreg;
  731. cmdptr->size =
  732. cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
  733. + sizeof(struct cmd_header));
  734. macreg =
  735. (struct cmd_ds_mac_reg_access *)&cmdptr->params.
  736. macreg;
  737. macreg->action = cpu_to_le16(cmd_action);
  738. macreg->offset = cpu_to_le16((u16) offval->offset);
  739. macreg->value = cpu_to_le32(offval->value);
  740. break;
  741. }
  742. case CMD_BBP_REG_ACCESS:
  743. {
  744. struct cmd_ds_bbp_reg_access *bbpreg;
  745. cmdptr->size =
  746. cpu_to_le16(sizeof
  747. (struct cmd_ds_bbp_reg_access)
  748. + sizeof(struct cmd_header));
  749. bbpreg =
  750. (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
  751. bbpreg;
  752. bbpreg->action = cpu_to_le16(cmd_action);
  753. bbpreg->offset = cpu_to_le16((u16) offval->offset);
  754. bbpreg->value = (u8) offval->value;
  755. break;
  756. }
  757. case CMD_RF_REG_ACCESS:
  758. {
  759. struct cmd_ds_rf_reg_access *rfreg;
  760. cmdptr->size =
  761. cpu_to_le16(sizeof
  762. (struct cmd_ds_rf_reg_access) +
  763. sizeof(struct cmd_header));
  764. rfreg =
  765. (struct cmd_ds_rf_reg_access *)&cmdptr->params.
  766. rfreg;
  767. rfreg->action = cpu_to_le16(cmd_action);
  768. rfreg->offset = cpu_to_le16((u16) offval->offset);
  769. rfreg->value = (u8) offval->value;
  770. break;
  771. }
  772. default:
  773. break;
  774. }
  775. lbs_deb_leave(LBS_DEB_CMD);
  776. return 0;
  777. }
  778. static void lbs_queue_cmd(struct lbs_private *priv,
  779. struct cmd_ctrl_node *cmdnode)
  780. {
  781. unsigned long flags;
  782. int addtail = 1;
  783. lbs_deb_enter(LBS_DEB_HOST);
  784. if (!cmdnode) {
  785. lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
  786. goto done;
  787. }
  788. if (!cmdnode->cmdbuf->size) {
  789. lbs_deb_host("DNLD_CMD: cmd size is zero\n");
  790. goto done;
  791. }
  792. cmdnode->result = 0;
  793. /* Exit_PS command needs to be queued in the header always. */
  794. if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
  795. struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
  796. if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  797. if (priv->psstate != PS_STATE_FULL_POWER)
  798. addtail = 0;
  799. }
  800. }
  801. if (le16_to_cpu(cmdnode->cmdbuf->command) ==
  802. CMD_802_11_WAKEUP_CONFIRM)
  803. addtail = 0;
  804. spin_lock_irqsave(&priv->driver_lock, flags);
  805. if (addtail)
  806. list_add_tail(&cmdnode->list, &priv->cmdpendingq);
  807. else
  808. list_add(&cmdnode->list, &priv->cmdpendingq);
  809. spin_unlock_irqrestore(&priv->driver_lock, flags);
  810. lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
  811. le16_to_cpu(cmdnode->cmdbuf->command));
  812. done:
  813. lbs_deb_leave(LBS_DEB_HOST);
  814. }
  815. static void lbs_submit_command(struct lbs_private *priv,
  816. struct cmd_ctrl_node *cmdnode)
  817. {
  818. unsigned long flags;
  819. struct cmd_header *cmd;
  820. uint16_t cmdsize;
  821. uint16_t command;
  822. int timeo = 3 * HZ;
  823. int ret;
  824. lbs_deb_enter(LBS_DEB_HOST);
  825. cmd = cmdnode->cmdbuf;
  826. spin_lock_irqsave(&priv->driver_lock, flags);
  827. priv->cur_cmd = cmdnode;
  828. priv->cur_cmd_retcode = 0;
  829. spin_unlock_irqrestore(&priv->driver_lock, flags);
  830. cmdsize = le16_to_cpu(cmd->size);
  831. command = le16_to_cpu(cmd->command);
  832. /* These commands take longer */
  833. if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
  834. timeo = 5 * HZ;
  835. lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
  836. command, le16_to_cpu(cmd->seqnum), cmdsize);
  837. lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
  838. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
  839. if (ret) {
  840. lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
  841. /* Let the timer kick in and retry, and potentially reset
  842. the whole thing if the condition persists */
  843. timeo = HZ/4;
  844. }
  845. if (command == CMD_802_11_DEEP_SLEEP) {
  846. if (priv->is_auto_deep_sleep_enabled) {
  847. priv->wakeup_dev_required = 1;
  848. priv->dnld_sent = 0;
  849. }
  850. priv->is_deep_sleep = 1;
  851. lbs_complete_command(priv, cmdnode, 0);
  852. } else {
  853. /* Setup the timer after transmit command */
  854. mod_timer(&priv->command_timer, jiffies + timeo);
  855. }
  856. lbs_deb_leave(LBS_DEB_HOST);
  857. }
  858. /**
  859. * This function inserts command node to cmdfreeq
  860. * after cleans it. Requires priv->driver_lock held.
  861. */
  862. static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  863. struct cmd_ctrl_node *cmdnode)
  864. {
  865. lbs_deb_enter(LBS_DEB_HOST);
  866. if (!cmdnode)
  867. goto out;
  868. cmdnode->callback = NULL;
  869. cmdnode->callback_arg = 0;
  870. memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
  871. list_add_tail(&cmdnode->list, &priv->cmdfreeq);
  872. out:
  873. lbs_deb_leave(LBS_DEB_HOST);
  874. }
  875. static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  876. struct cmd_ctrl_node *ptempcmd)
  877. {
  878. unsigned long flags;
  879. spin_lock_irqsave(&priv->driver_lock, flags);
  880. __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
  881. spin_unlock_irqrestore(&priv->driver_lock, flags);
  882. }
  883. void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
  884. int result)
  885. {
  886. if (cmd == priv->cur_cmd)
  887. priv->cur_cmd_retcode = result;
  888. cmd->result = result;
  889. cmd->cmdwaitqwoken = 1;
  890. wake_up_interruptible(&cmd->cmdwait_q);
  891. if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
  892. __lbs_cleanup_and_insert_cmd(priv, cmd);
  893. priv->cur_cmd = NULL;
  894. }
  895. int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
  896. {
  897. struct cmd_ds_802_11_radio_control cmd;
  898. int ret = -EINVAL;
  899. lbs_deb_enter(LBS_DEB_CMD);
  900. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  901. cmd.action = cpu_to_le16(CMD_ACT_SET);
  902. /* Only v8 and below support setting the preamble */
  903. if (priv->fwrelease < 0x09000000) {
  904. switch (preamble) {
  905. case RADIO_PREAMBLE_SHORT:
  906. case RADIO_PREAMBLE_AUTO:
  907. case RADIO_PREAMBLE_LONG:
  908. cmd.control = cpu_to_le16(preamble);
  909. break;
  910. default:
  911. goto out;
  912. }
  913. }
  914. if (radio_on)
  915. cmd.control |= cpu_to_le16(0x1);
  916. else {
  917. cmd.control &= cpu_to_le16(~0x1);
  918. priv->txpower_cur = 0;
  919. }
  920. lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
  921. radio_on ? "ON" : "OFF", preamble);
  922. priv->radio_on = radio_on;
  923. ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
  924. out:
  925. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  926. return ret;
  927. }
  928. void lbs_set_mac_control(struct lbs_private *priv)
  929. {
  930. struct cmd_ds_mac_control cmd;
  931. lbs_deb_enter(LBS_DEB_CMD);
  932. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  933. cmd.action = cpu_to_le16(priv->mac_control);
  934. cmd.reserved = 0;
  935. lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
  936. lbs_deb_leave(LBS_DEB_CMD);
  937. }
  938. /**
  939. * @brief This function prepare the command before send to firmware.
  940. *
  941. * @param priv A pointer to struct lbs_private structure
  942. * @param cmd_no command number
  943. * @param cmd_action command action: GET or SET
  944. * @param wait_option wait option: wait response or not
  945. * @param cmd_oid cmd oid: treated as sub command
  946. * @param pdata_buf A pointer to informaion buffer
  947. * @return 0 or -1
  948. */
  949. int lbs_prepare_and_send_command(struct lbs_private *priv,
  950. u16 cmd_no,
  951. u16 cmd_action,
  952. u16 wait_option, u32 cmd_oid, void *pdata_buf)
  953. {
  954. int ret = 0;
  955. struct cmd_ctrl_node *cmdnode;
  956. struct cmd_ds_command *cmdptr;
  957. unsigned long flags;
  958. lbs_deb_enter(LBS_DEB_HOST);
  959. if (!priv) {
  960. lbs_deb_host("PREP_CMD: priv is NULL\n");
  961. ret = -1;
  962. goto done;
  963. }
  964. if (priv->surpriseremoved) {
  965. lbs_deb_host("PREP_CMD: card removed\n");
  966. ret = -1;
  967. goto done;
  968. }
  969. if (!lbs_is_cmd_allowed(priv)) {
  970. ret = -EBUSY;
  971. goto done;
  972. }
  973. cmdnode = lbs_get_cmd_ctrl_node(priv);
  974. if (cmdnode == NULL) {
  975. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  976. /* Wake up main thread to execute next command */
  977. wake_up_interruptible(&priv->waitq);
  978. ret = -1;
  979. goto done;
  980. }
  981. cmdnode->callback = NULL;
  982. cmdnode->callback_arg = (unsigned long)pdata_buf;
  983. cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
  984. lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
  985. /* Set sequence number, command and INT option */
  986. priv->seqnum++;
  987. cmdptr->seqnum = cpu_to_le16(priv->seqnum);
  988. cmdptr->command = cpu_to_le16(cmd_no);
  989. cmdptr->result = 0;
  990. switch (cmd_no) {
  991. case CMD_802_11_PS_MODE:
  992. ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
  993. break;
  994. case CMD_MAC_REG_ACCESS:
  995. case CMD_BBP_REG_ACCESS:
  996. case CMD_RF_REG_ACCESS:
  997. ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
  998. break;
  999. case CMD_802_11_SET_AFC:
  1000. case CMD_802_11_GET_AFC:
  1001. cmdptr->command = cpu_to_le16(cmd_no);
  1002. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
  1003. sizeof(struct cmd_header));
  1004. memmove(&cmdptr->params.afc,
  1005. pdata_buf, sizeof(struct cmd_ds_802_11_afc));
  1006. ret = 0;
  1007. goto done;
  1008. #ifdef CONFIG_LIBERTAS_MESH
  1009. case CMD_BT_ACCESS:
  1010. ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
  1011. break;
  1012. case CMD_FWT_ACCESS:
  1013. ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
  1014. break;
  1015. #endif
  1016. case CMD_802_11_BEACON_CTRL:
  1017. ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
  1018. break;
  1019. case CMD_802_11_DEEP_SLEEP:
  1020. cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
  1021. cmdptr->size = cpu_to_le16(sizeof(struct cmd_header));
  1022. break;
  1023. default:
  1024. lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
  1025. ret = -1;
  1026. break;
  1027. }
  1028. /* return error, since the command preparation failed */
  1029. if (ret != 0) {
  1030. lbs_deb_host("PREP_CMD: command preparation failed\n");
  1031. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1032. ret = -1;
  1033. goto done;
  1034. }
  1035. cmdnode->cmdwaitqwoken = 0;
  1036. lbs_queue_cmd(priv, cmdnode);
  1037. wake_up_interruptible(&priv->waitq);
  1038. if (wait_option & CMD_OPTION_WAITFORRSP) {
  1039. lbs_deb_host("PREP_CMD: wait for response\n");
  1040. might_sleep();
  1041. wait_event_interruptible(cmdnode->cmdwait_q,
  1042. cmdnode->cmdwaitqwoken);
  1043. }
  1044. spin_lock_irqsave(&priv->driver_lock, flags);
  1045. if (priv->cur_cmd_retcode) {
  1046. lbs_deb_host("PREP_CMD: command failed with return code %d\n",
  1047. priv->cur_cmd_retcode);
  1048. priv->cur_cmd_retcode = 0;
  1049. ret = -1;
  1050. }
  1051. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1052. done:
  1053. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1054. return ret;
  1055. }
  1056. /**
  1057. * @brief This function allocates the command buffer and link
  1058. * it to command free queue.
  1059. *
  1060. * @param priv A pointer to struct lbs_private structure
  1061. * @return 0 or -1
  1062. */
  1063. int lbs_allocate_cmd_buffer(struct lbs_private *priv)
  1064. {
  1065. int ret = 0;
  1066. u32 bufsize;
  1067. u32 i;
  1068. struct cmd_ctrl_node *cmdarray;
  1069. lbs_deb_enter(LBS_DEB_HOST);
  1070. /* Allocate and initialize the command array */
  1071. bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
  1072. if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
  1073. lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
  1074. ret = -1;
  1075. goto done;
  1076. }
  1077. priv->cmd_array = cmdarray;
  1078. /* Allocate and initialize each command buffer in the command array */
  1079. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1080. cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
  1081. if (!cmdarray[i].cmdbuf) {
  1082. lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
  1083. ret = -1;
  1084. goto done;
  1085. }
  1086. }
  1087. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1088. init_waitqueue_head(&cmdarray[i].cmdwait_q);
  1089. lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
  1090. }
  1091. ret = 0;
  1092. done:
  1093. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1094. return ret;
  1095. }
  1096. /**
  1097. * @brief This function frees the command buffer.
  1098. *
  1099. * @param priv A pointer to struct lbs_private structure
  1100. * @return 0 or -1
  1101. */
  1102. int lbs_free_cmd_buffer(struct lbs_private *priv)
  1103. {
  1104. struct cmd_ctrl_node *cmdarray;
  1105. unsigned int i;
  1106. lbs_deb_enter(LBS_DEB_HOST);
  1107. /* need to check if cmd array is allocated or not */
  1108. if (priv->cmd_array == NULL) {
  1109. lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
  1110. goto done;
  1111. }
  1112. cmdarray = priv->cmd_array;
  1113. /* Release shared memory buffers */
  1114. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1115. if (cmdarray[i].cmdbuf) {
  1116. kfree(cmdarray[i].cmdbuf);
  1117. cmdarray[i].cmdbuf = NULL;
  1118. }
  1119. }
  1120. /* Release cmd_ctrl_node */
  1121. if (priv->cmd_array) {
  1122. kfree(priv->cmd_array);
  1123. priv->cmd_array = NULL;
  1124. }
  1125. done:
  1126. lbs_deb_leave(LBS_DEB_HOST);
  1127. return 0;
  1128. }
  1129. /**
  1130. * @brief This function gets a free command node if available in
  1131. * command free queue.
  1132. *
  1133. * @param priv A pointer to struct lbs_private structure
  1134. * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
  1135. */
  1136. static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
  1137. {
  1138. struct cmd_ctrl_node *tempnode;
  1139. unsigned long flags;
  1140. lbs_deb_enter(LBS_DEB_HOST);
  1141. if (!priv)
  1142. return NULL;
  1143. spin_lock_irqsave(&priv->driver_lock, flags);
  1144. if (!list_empty(&priv->cmdfreeq)) {
  1145. tempnode = list_first_entry(&priv->cmdfreeq,
  1146. struct cmd_ctrl_node, list);
  1147. list_del(&tempnode->list);
  1148. } else {
  1149. lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
  1150. tempnode = NULL;
  1151. }
  1152. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1153. lbs_deb_leave(LBS_DEB_HOST);
  1154. return tempnode;
  1155. }
  1156. /**
  1157. * @brief This function executes next command in command
  1158. * pending queue. It will put firmware back to PS mode
  1159. * if applicable.
  1160. *
  1161. * @param priv A pointer to struct lbs_private structure
  1162. * @return 0 or -1
  1163. */
  1164. int lbs_execute_next_command(struct lbs_private *priv)
  1165. {
  1166. struct cmd_ctrl_node *cmdnode = NULL;
  1167. struct cmd_header *cmd;
  1168. unsigned long flags;
  1169. int ret = 0;
  1170. /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1171. * only caller to us is lbs_thread() and we get even when a
  1172. * data packet is received */
  1173. lbs_deb_enter(LBS_DEB_THREAD);
  1174. spin_lock_irqsave(&priv->driver_lock, flags);
  1175. if (priv->cur_cmd) {
  1176. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1177. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1178. ret = -1;
  1179. goto done;
  1180. }
  1181. if (!list_empty(&priv->cmdpendingq)) {
  1182. cmdnode = list_first_entry(&priv->cmdpendingq,
  1183. struct cmd_ctrl_node, list);
  1184. }
  1185. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1186. if (cmdnode) {
  1187. cmd = cmdnode->cmdbuf;
  1188. if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
  1189. if ((priv->psstate == PS_STATE_SLEEP) ||
  1190. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1191. lbs_deb_host(
  1192. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1193. le16_to_cpu(cmd->command),
  1194. priv->psstate);
  1195. ret = -1;
  1196. goto done;
  1197. }
  1198. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1199. "0x%04x in psstate %d\n",
  1200. le16_to_cpu(cmd->command), priv->psstate);
  1201. } else if (priv->psstate != PS_STATE_FULL_POWER) {
  1202. /*
  1203. * 1. Non-PS command:
  1204. * Queue it. set needtowakeup to TRUE if current state
  1205. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1206. * 2. PS command but not Exit_PS:
  1207. * Ignore it.
  1208. * 3. PS command Exit_PS:
  1209. * Set needtowakeup to TRUE if current state is SLEEP,
  1210. * otherwise send this command down to firmware
  1211. * immediately.
  1212. */
  1213. if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
  1214. /* Prepare to send Exit PS,
  1215. * this non PS command will be sent later */
  1216. if ((priv->psstate == PS_STATE_SLEEP)
  1217. || (priv->psstate == PS_STATE_PRE_SLEEP)
  1218. ) {
  1219. /* w/ new scheme, it will not reach here.
  1220. since it is blocked in main_thread. */
  1221. priv->needtowakeup = 1;
  1222. } else
  1223. lbs_ps_wakeup(priv, 0);
  1224. ret = 0;
  1225. goto done;
  1226. } else {
  1227. /*
  1228. * PS command. Ignore it if it is not Exit_PS.
  1229. * otherwise send it down immediately.
  1230. */
  1231. struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
  1232. lbs_deb_host(
  1233. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1234. psm->action);
  1235. if (psm->action !=
  1236. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1237. lbs_deb_host(
  1238. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1239. list_del(&cmdnode->list);
  1240. spin_lock_irqsave(&priv->driver_lock, flags);
  1241. lbs_complete_command(priv, cmdnode, 0);
  1242. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1243. ret = 0;
  1244. goto done;
  1245. }
  1246. if ((priv->psstate == PS_STATE_SLEEP) ||
  1247. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1248. lbs_deb_host(
  1249. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1250. list_del(&cmdnode->list);
  1251. spin_lock_irqsave(&priv->driver_lock, flags);
  1252. lbs_complete_command(priv, cmdnode, 0);
  1253. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1254. priv->needtowakeup = 1;
  1255. ret = 0;
  1256. goto done;
  1257. }
  1258. lbs_deb_host(
  1259. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1260. }
  1261. }
  1262. list_del(&cmdnode->list);
  1263. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1264. le16_to_cpu(cmd->command));
  1265. lbs_submit_command(priv, cmdnode);
  1266. } else {
  1267. /*
  1268. * check if in power save mode, if yes, put the device back
  1269. * to PS mode
  1270. */
  1271. #ifdef TODO
  1272. /*
  1273. * This was the old code for libertas+wext. Someone that
  1274. * understands this beast should re-code it in a sane way.
  1275. *
  1276. * I actually don't understand why this is related to WPA
  1277. * and to connection status, shouldn't powering should be
  1278. * independ of such things?
  1279. */
  1280. if ((priv->psmode != LBS802_11POWERMODECAM) &&
  1281. (priv->psstate == PS_STATE_FULL_POWER) &&
  1282. ((priv->connect_status == LBS_CONNECTED) ||
  1283. lbs_mesh_connected(priv))) {
  1284. if (priv->secinfo.WPAenabled ||
  1285. priv->secinfo.WPA2enabled) {
  1286. /* check for valid WPA group keys */
  1287. if (priv->wpa_mcast_key.len ||
  1288. priv->wpa_unicast_key.len) {
  1289. lbs_deb_host(
  1290. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1291. " go back to PS_SLEEP");
  1292. lbs_ps_sleep(priv, 0);
  1293. }
  1294. } else {
  1295. lbs_deb_host(
  1296. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1297. "go back to PS_SLEEP");
  1298. lbs_ps_sleep(priv, 0);
  1299. }
  1300. }
  1301. #endif
  1302. }
  1303. ret = 0;
  1304. done:
  1305. lbs_deb_leave(LBS_DEB_THREAD);
  1306. return ret;
  1307. }
  1308. static void lbs_send_confirmsleep(struct lbs_private *priv)
  1309. {
  1310. unsigned long flags;
  1311. int ret;
  1312. lbs_deb_enter(LBS_DEB_HOST);
  1313. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
  1314. sizeof(confirm_sleep));
  1315. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
  1316. sizeof(confirm_sleep));
  1317. if (ret) {
  1318. lbs_pr_alert("confirm_sleep failed\n");
  1319. goto out;
  1320. }
  1321. spin_lock_irqsave(&priv->driver_lock, flags);
  1322. /* We don't get a response on the sleep-confirmation */
  1323. priv->dnld_sent = DNLD_RES_RECEIVED;
  1324. if (priv->is_host_sleep_configured) {
  1325. priv->is_host_sleep_activated = 1;
  1326. wake_up_interruptible(&priv->host_sleep_q);
  1327. }
  1328. /* If nothing to do, go back to sleep (?) */
  1329. if (!kfifo_len(&priv->event_fifo) && !priv->resp_len[priv->resp_idx])
  1330. priv->psstate = PS_STATE_SLEEP;
  1331. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1332. out:
  1333. lbs_deb_leave(LBS_DEB_HOST);
  1334. }
  1335. void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
  1336. {
  1337. lbs_deb_enter(LBS_DEB_HOST);
  1338. /*
  1339. * PS is currently supported only in Infrastructure mode
  1340. * Remove this check if it is to be supported in IBSS mode also
  1341. */
  1342. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1343. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1344. lbs_deb_leave(LBS_DEB_HOST);
  1345. }
  1346. /**
  1347. * @brief This function sends Exit_PS command to firmware.
  1348. *
  1349. * @param priv A pointer to struct lbs_private structure
  1350. * @param wait_option wait response or not
  1351. * @return n/a
  1352. */
  1353. void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
  1354. {
  1355. __le32 Localpsmode;
  1356. lbs_deb_enter(LBS_DEB_HOST);
  1357. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1358. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1359. CMD_SUBCMD_EXIT_PS,
  1360. wait_option, 0, &Localpsmode);
  1361. lbs_deb_leave(LBS_DEB_HOST);
  1362. }
  1363. /**
  1364. * @brief This function checks condition and prepares to
  1365. * send sleep confirm command to firmware if ok.
  1366. *
  1367. * @param priv A pointer to struct lbs_private structure
  1368. * @param psmode Power Saving mode
  1369. * @return n/a
  1370. */
  1371. void lbs_ps_confirm_sleep(struct lbs_private *priv)
  1372. {
  1373. unsigned long flags =0;
  1374. int allowed = 1;
  1375. lbs_deb_enter(LBS_DEB_HOST);
  1376. spin_lock_irqsave(&priv->driver_lock, flags);
  1377. if (priv->dnld_sent) {
  1378. allowed = 0;
  1379. lbs_deb_host("dnld_sent was set\n");
  1380. }
  1381. /* In-progress command? */
  1382. if (priv->cur_cmd) {
  1383. allowed = 0;
  1384. lbs_deb_host("cur_cmd was set\n");
  1385. }
  1386. /* Pending events or command responses? */
  1387. if (kfifo_len(&priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
  1388. allowed = 0;
  1389. lbs_deb_host("pending events or command responses\n");
  1390. }
  1391. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1392. if (allowed) {
  1393. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1394. lbs_send_confirmsleep(priv);
  1395. } else {
  1396. lbs_deb_host("sleep confirm has been delayed\n");
  1397. }
  1398. lbs_deb_leave(LBS_DEB_HOST);
  1399. }
  1400. /**
  1401. * @brief Configures the transmission power control functionality.
  1402. *
  1403. * @param priv A pointer to struct lbs_private structure
  1404. * @param enable Transmission power control enable
  1405. * @param p0 Power level when link quality is good (dBm).
  1406. * @param p1 Power level when link quality is fair (dBm).
  1407. * @param p2 Power level when link quality is poor (dBm).
  1408. * @param usesnr Use Signal to Noise Ratio in TPC
  1409. *
  1410. * @return 0 on success
  1411. */
  1412. int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
  1413. int8_t p2, int usesnr)
  1414. {
  1415. struct cmd_ds_802_11_tpc_cfg cmd;
  1416. int ret;
  1417. memset(&cmd, 0, sizeof(cmd));
  1418. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1419. cmd.action = cpu_to_le16(CMD_ACT_SET);
  1420. cmd.enable = !!enable;
  1421. cmd.usesnr = !!usesnr;
  1422. cmd.P0 = p0;
  1423. cmd.P1 = p1;
  1424. cmd.P2 = p2;
  1425. ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
  1426. return ret;
  1427. }
  1428. /**
  1429. * @brief Configures the power adaptation settings.
  1430. *
  1431. * @param priv A pointer to struct lbs_private structure
  1432. * @param enable Power adaptation enable
  1433. * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
  1434. * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
  1435. * @param p2 Power level for 48 and 54 Mbps (dBm).
  1436. *
  1437. * @return 0 on Success
  1438. */
  1439. int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
  1440. int8_t p1, int8_t p2)
  1441. {
  1442. struct cmd_ds_802_11_pa_cfg cmd;
  1443. int ret;
  1444. memset(&cmd, 0, sizeof(cmd));
  1445. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1446. cmd.action = cpu_to_le16(CMD_ACT_SET);
  1447. cmd.enable = !!enable;
  1448. cmd.P0 = p0;
  1449. cmd.P1 = p1;
  1450. cmd.P2 = p2;
  1451. ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
  1452. return ret;
  1453. }
  1454. struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
  1455. uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
  1456. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1457. unsigned long callback_arg)
  1458. {
  1459. struct cmd_ctrl_node *cmdnode;
  1460. lbs_deb_enter(LBS_DEB_HOST);
  1461. if (priv->surpriseremoved) {
  1462. lbs_deb_host("PREP_CMD: card removed\n");
  1463. cmdnode = ERR_PTR(-ENOENT);
  1464. goto done;
  1465. }
  1466. if (!lbs_is_cmd_allowed(priv)) {
  1467. cmdnode = ERR_PTR(-EBUSY);
  1468. goto done;
  1469. }
  1470. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1471. if (cmdnode == NULL) {
  1472. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1473. /* Wake up main thread to execute next command */
  1474. wake_up_interruptible(&priv->waitq);
  1475. cmdnode = ERR_PTR(-ENOBUFS);
  1476. goto done;
  1477. }
  1478. cmdnode->callback = callback;
  1479. cmdnode->callback_arg = callback_arg;
  1480. /* Copy the incoming command to the buffer */
  1481. memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
  1482. /* Set sequence number, clean result, move to buffer */
  1483. priv->seqnum++;
  1484. cmdnode->cmdbuf->command = cpu_to_le16(command);
  1485. cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
  1486. cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
  1487. cmdnode->cmdbuf->result = 0;
  1488. lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
  1489. cmdnode->cmdwaitqwoken = 0;
  1490. lbs_queue_cmd(priv, cmdnode);
  1491. wake_up_interruptible(&priv->waitq);
  1492. done:
  1493. lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
  1494. return cmdnode;
  1495. }
  1496. void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
  1497. struct cmd_header *in_cmd, int in_cmd_size)
  1498. {
  1499. lbs_deb_enter(LBS_DEB_CMD);
  1500. __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1501. lbs_cmd_async_callback, 0);
  1502. lbs_deb_leave(LBS_DEB_CMD);
  1503. }
  1504. int __lbs_cmd(struct lbs_private *priv, uint16_t command,
  1505. struct cmd_header *in_cmd, int in_cmd_size,
  1506. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1507. unsigned long callback_arg)
  1508. {
  1509. struct cmd_ctrl_node *cmdnode;
  1510. unsigned long flags;
  1511. int ret = 0;
  1512. lbs_deb_enter(LBS_DEB_HOST);
  1513. cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1514. callback, callback_arg);
  1515. if (IS_ERR(cmdnode)) {
  1516. ret = PTR_ERR(cmdnode);
  1517. goto done;
  1518. }
  1519. might_sleep();
  1520. wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
  1521. spin_lock_irqsave(&priv->driver_lock, flags);
  1522. ret = cmdnode->result;
  1523. if (ret)
  1524. lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
  1525. command, ret);
  1526. __lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1527. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1528. done:
  1529. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1530. return ret;
  1531. }
  1532. EXPORT_SYMBOL_GPL(__lbs_cmd);