cmd.c 44 KB

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