cmd.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  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. /**
  722. * @brief Read a MAC, Baseband, or RF register
  723. *
  724. * @param priv pointer to struct lbs_private
  725. * @param cmd register command, one of CMD_MAC_REG_ACCESS,
  726. * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS
  727. * @param offset byte offset of the register to get
  728. * @param value on success, the value of the register at 'offset'
  729. *
  730. * @return 0 on success, error code on failure
  731. */
  732. int lbs_get_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 *value)
  733. {
  734. struct cmd_ds_reg_access cmd;
  735. int ret = 0;
  736. lbs_deb_enter(LBS_DEB_CMD);
  737. BUG_ON(value == NULL);
  738. memset(&cmd, 0, sizeof(cmd));
  739. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  740. cmd.action = cpu_to_le16(CMD_ACT_GET);
  741. if (reg != CMD_MAC_REG_ACCESS &&
  742. reg != CMD_BBP_REG_ACCESS &&
  743. reg != CMD_RF_REG_ACCESS) {
  744. ret = -EINVAL;
  745. goto out;
  746. }
  747. ret = lbs_cmd_with_response(priv, reg, &cmd);
  748. if (ret) {
  749. if (reg == CMD_BBP_REG_ACCESS || reg == CMD_RF_REG_ACCESS)
  750. *value = cmd.value.bbp_rf;
  751. else if (reg == CMD_MAC_REG_ACCESS)
  752. *value = le32_to_cpu(cmd.value.mac);
  753. }
  754. out:
  755. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  756. return ret;
  757. }
  758. /**
  759. * @brief Write a MAC, Baseband, or RF register
  760. *
  761. * @param priv pointer to struct lbs_private
  762. * @param cmd register command, one of CMD_MAC_REG_ACCESS,
  763. * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS
  764. * @param offset byte offset of the register to set
  765. * @param value the value to write to the register at 'offset'
  766. *
  767. * @return 0 on success, error code on failure
  768. */
  769. int lbs_set_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 value)
  770. {
  771. struct cmd_ds_reg_access cmd;
  772. int ret = 0;
  773. lbs_deb_enter(LBS_DEB_CMD);
  774. memset(&cmd, 0, sizeof(cmd));
  775. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  776. cmd.action = cpu_to_le16(CMD_ACT_SET);
  777. if (reg == CMD_BBP_REG_ACCESS || reg == CMD_RF_REG_ACCESS)
  778. cmd.value.bbp_rf = (u8) (value & 0xFF);
  779. else if (reg == CMD_MAC_REG_ACCESS)
  780. cmd.value.mac = cpu_to_le32(value);
  781. else {
  782. ret = -EINVAL;
  783. goto out;
  784. }
  785. ret = lbs_cmd_with_response(priv, reg, &cmd);
  786. out:
  787. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  788. return ret;
  789. }
  790. static void lbs_queue_cmd(struct lbs_private *priv,
  791. struct cmd_ctrl_node *cmdnode)
  792. {
  793. unsigned long flags;
  794. int addtail = 1;
  795. lbs_deb_enter(LBS_DEB_HOST);
  796. if (!cmdnode) {
  797. lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
  798. goto done;
  799. }
  800. if (!cmdnode->cmdbuf->size) {
  801. lbs_deb_host("DNLD_CMD: cmd size is zero\n");
  802. goto done;
  803. }
  804. cmdnode->result = 0;
  805. /* Exit_PS command needs to be queued in the header always. */
  806. if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
  807. struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
  808. if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  809. if (priv->psstate != PS_STATE_FULL_POWER)
  810. addtail = 0;
  811. }
  812. }
  813. if (le16_to_cpu(cmdnode->cmdbuf->command) ==
  814. CMD_802_11_WAKEUP_CONFIRM)
  815. addtail = 0;
  816. spin_lock_irqsave(&priv->driver_lock, flags);
  817. if (addtail)
  818. list_add_tail(&cmdnode->list, &priv->cmdpendingq);
  819. else
  820. list_add(&cmdnode->list, &priv->cmdpendingq);
  821. spin_unlock_irqrestore(&priv->driver_lock, flags);
  822. lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
  823. le16_to_cpu(cmdnode->cmdbuf->command));
  824. done:
  825. lbs_deb_leave(LBS_DEB_HOST);
  826. }
  827. static void lbs_submit_command(struct lbs_private *priv,
  828. struct cmd_ctrl_node *cmdnode)
  829. {
  830. unsigned long flags;
  831. struct cmd_header *cmd;
  832. uint16_t cmdsize;
  833. uint16_t command;
  834. int timeo = 3 * HZ;
  835. int ret;
  836. lbs_deb_enter(LBS_DEB_HOST);
  837. cmd = cmdnode->cmdbuf;
  838. spin_lock_irqsave(&priv->driver_lock, flags);
  839. priv->cur_cmd = cmdnode;
  840. priv->cur_cmd_retcode = 0;
  841. spin_unlock_irqrestore(&priv->driver_lock, flags);
  842. cmdsize = le16_to_cpu(cmd->size);
  843. command = le16_to_cpu(cmd->command);
  844. /* These commands take longer */
  845. if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
  846. timeo = 5 * HZ;
  847. lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
  848. command, le16_to_cpu(cmd->seqnum), cmdsize);
  849. lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
  850. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
  851. if (ret) {
  852. lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
  853. /* Let the timer kick in and retry, and potentially reset
  854. the whole thing if the condition persists */
  855. timeo = HZ/4;
  856. }
  857. if (command == CMD_802_11_DEEP_SLEEP) {
  858. if (priv->is_auto_deep_sleep_enabled) {
  859. priv->wakeup_dev_required = 1;
  860. priv->dnld_sent = 0;
  861. }
  862. priv->is_deep_sleep = 1;
  863. lbs_complete_command(priv, cmdnode, 0);
  864. } else {
  865. /* Setup the timer after transmit command */
  866. mod_timer(&priv->command_timer, jiffies + timeo);
  867. }
  868. lbs_deb_leave(LBS_DEB_HOST);
  869. }
  870. /**
  871. * This function inserts command node to cmdfreeq
  872. * after cleans it. Requires priv->driver_lock held.
  873. */
  874. static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  875. struct cmd_ctrl_node *cmdnode)
  876. {
  877. lbs_deb_enter(LBS_DEB_HOST);
  878. if (!cmdnode)
  879. goto out;
  880. cmdnode->callback = NULL;
  881. cmdnode->callback_arg = 0;
  882. memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
  883. list_add_tail(&cmdnode->list, &priv->cmdfreeq);
  884. out:
  885. lbs_deb_leave(LBS_DEB_HOST);
  886. }
  887. static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  888. struct cmd_ctrl_node *ptempcmd)
  889. {
  890. unsigned long flags;
  891. spin_lock_irqsave(&priv->driver_lock, flags);
  892. __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
  893. spin_unlock_irqrestore(&priv->driver_lock, flags);
  894. }
  895. void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
  896. int result)
  897. {
  898. if (cmd == priv->cur_cmd)
  899. priv->cur_cmd_retcode = result;
  900. cmd->result = result;
  901. cmd->cmdwaitqwoken = 1;
  902. wake_up_interruptible(&cmd->cmdwait_q);
  903. if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
  904. __lbs_cleanup_and_insert_cmd(priv, cmd);
  905. priv->cur_cmd = NULL;
  906. }
  907. int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
  908. {
  909. struct cmd_ds_802_11_radio_control cmd;
  910. int ret = -EINVAL;
  911. lbs_deb_enter(LBS_DEB_CMD);
  912. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  913. cmd.action = cpu_to_le16(CMD_ACT_SET);
  914. /* Only v8 and below support setting the preamble */
  915. if (priv->fwrelease < 0x09000000) {
  916. switch (preamble) {
  917. case RADIO_PREAMBLE_SHORT:
  918. case RADIO_PREAMBLE_AUTO:
  919. case RADIO_PREAMBLE_LONG:
  920. cmd.control = cpu_to_le16(preamble);
  921. break;
  922. default:
  923. goto out;
  924. }
  925. }
  926. if (radio_on)
  927. cmd.control |= cpu_to_le16(0x1);
  928. else {
  929. cmd.control &= cpu_to_le16(~0x1);
  930. priv->txpower_cur = 0;
  931. }
  932. lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
  933. radio_on ? "ON" : "OFF", preamble);
  934. priv->radio_on = radio_on;
  935. ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
  936. out:
  937. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  938. return ret;
  939. }
  940. void lbs_set_mac_control(struct lbs_private *priv)
  941. {
  942. struct cmd_ds_mac_control cmd;
  943. lbs_deb_enter(LBS_DEB_CMD);
  944. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  945. cmd.action = cpu_to_le16(priv->mac_control);
  946. cmd.reserved = 0;
  947. lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
  948. lbs_deb_leave(LBS_DEB_CMD);
  949. }
  950. /**
  951. * @brief This function prepare the command before send to firmware.
  952. *
  953. * @param priv A pointer to struct lbs_private structure
  954. * @param cmd_no command number
  955. * @param cmd_action command action: GET or SET
  956. * @param wait_option wait option: wait response or not
  957. * @param cmd_oid cmd oid: treated as sub command
  958. * @param pdata_buf A pointer to informaion buffer
  959. * @return 0 or -1
  960. */
  961. int lbs_prepare_and_send_command(struct lbs_private *priv,
  962. u16 cmd_no,
  963. u16 cmd_action,
  964. u16 wait_option, u32 cmd_oid, void *pdata_buf)
  965. {
  966. int ret = 0;
  967. struct cmd_ctrl_node *cmdnode;
  968. struct cmd_ds_command *cmdptr;
  969. unsigned long flags;
  970. lbs_deb_enter(LBS_DEB_HOST);
  971. if (!priv) {
  972. lbs_deb_host("PREP_CMD: priv is NULL\n");
  973. ret = -1;
  974. goto done;
  975. }
  976. if (priv->surpriseremoved) {
  977. lbs_deb_host("PREP_CMD: card removed\n");
  978. ret = -1;
  979. goto done;
  980. }
  981. if (!lbs_is_cmd_allowed(priv)) {
  982. ret = -EBUSY;
  983. goto done;
  984. }
  985. cmdnode = lbs_get_cmd_ctrl_node(priv);
  986. if (cmdnode == NULL) {
  987. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  988. /* Wake up main thread to execute next command */
  989. wake_up_interruptible(&priv->waitq);
  990. ret = -1;
  991. goto done;
  992. }
  993. cmdnode->callback = NULL;
  994. cmdnode->callback_arg = (unsigned long)pdata_buf;
  995. cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
  996. lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
  997. /* Set sequence number, command and INT option */
  998. priv->seqnum++;
  999. cmdptr->seqnum = cpu_to_le16(priv->seqnum);
  1000. cmdptr->command = cpu_to_le16(cmd_no);
  1001. cmdptr->result = 0;
  1002. switch (cmd_no) {
  1003. case CMD_802_11_PS_MODE:
  1004. ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
  1005. break;
  1006. case CMD_802_11_DEEP_SLEEP:
  1007. cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
  1008. cmdptr->size = cpu_to_le16(sizeof(struct cmd_header));
  1009. break;
  1010. default:
  1011. lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
  1012. ret = -1;
  1013. break;
  1014. }
  1015. /* return error, since the command preparation failed */
  1016. if (ret != 0) {
  1017. lbs_deb_host("PREP_CMD: command preparation failed\n");
  1018. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1019. ret = -1;
  1020. goto done;
  1021. }
  1022. cmdnode->cmdwaitqwoken = 0;
  1023. lbs_queue_cmd(priv, cmdnode);
  1024. wake_up_interruptible(&priv->waitq);
  1025. if (wait_option & CMD_OPTION_WAITFORRSP) {
  1026. lbs_deb_host("PREP_CMD: wait for response\n");
  1027. might_sleep();
  1028. wait_event_interruptible(cmdnode->cmdwait_q,
  1029. cmdnode->cmdwaitqwoken);
  1030. }
  1031. spin_lock_irqsave(&priv->driver_lock, flags);
  1032. if (priv->cur_cmd_retcode) {
  1033. lbs_deb_host("PREP_CMD: command failed with return code %d\n",
  1034. priv->cur_cmd_retcode);
  1035. priv->cur_cmd_retcode = 0;
  1036. ret = -1;
  1037. }
  1038. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1039. done:
  1040. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1041. return ret;
  1042. }
  1043. /**
  1044. * @brief This function allocates the command buffer and link
  1045. * it to command free queue.
  1046. *
  1047. * @param priv A pointer to struct lbs_private structure
  1048. * @return 0 or -1
  1049. */
  1050. int lbs_allocate_cmd_buffer(struct lbs_private *priv)
  1051. {
  1052. int ret = 0;
  1053. u32 bufsize;
  1054. u32 i;
  1055. struct cmd_ctrl_node *cmdarray;
  1056. lbs_deb_enter(LBS_DEB_HOST);
  1057. /* Allocate and initialize the command array */
  1058. bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
  1059. if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
  1060. lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
  1061. ret = -1;
  1062. goto done;
  1063. }
  1064. priv->cmd_array = cmdarray;
  1065. /* Allocate and initialize each command buffer in the command array */
  1066. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1067. cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
  1068. if (!cmdarray[i].cmdbuf) {
  1069. lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
  1070. ret = -1;
  1071. goto done;
  1072. }
  1073. }
  1074. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1075. init_waitqueue_head(&cmdarray[i].cmdwait_q);
  1076. lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
  1077. }
  1078. ret = 0;
  1079. done:
  1080. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1081. return ret;
  1082. }
  1083. /**
  1084. * @brief This function frees the command buffer.
  1085. *
  1086. * @param priv A pointer to struct lbs_private structure
  1087. * @return 0 or -1
  1088. */
  1089. int lbs_free_cmd_buffer(struct lbs_private *priv)
  1090. {
  1091. struct cmd_ctrl_node *cmdarray;
  1092. unsigned int i;
  1093. lbs_deb_enter(LBS_DEB_HOST);
  1094. /* need to check if cmd array is allocated or not */
  1095. if (priv->cmd_array == NULL) {
  1096. lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
  1097. goto done;
  1098. }
  1099. cmdarray = priv->cmd_array;
  1100. /* Release shared memory buffers */
  1101. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1102. if (cmdarray[i].cmdbuf) {
  1103. kfree(cmdarray[i].cmdbuf);
  1104. cmdarray[i].cmdbuf = NULL;
  1105. }
  1106. }
  1107. /* Release cmd_ctrl_node */
  1108. if (priv->cmd_array) {
  1109. kfree(priv->cmd_array);
  1110. priv->cmd_array = NULL;
  1111. }
  1112. done:
  1113. lbs_deb_leave(LBS_DEB_HOST);
  1114. return 0;
  1115. }
  1116. /**
  1117. * @brief This function gets a free command node if available in
  1118. * command free queue.
  1119. *
  1120. * @param priv A pointer to struct lbs_private structure
  1121. * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
  1122. */
  1123. static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
  1124. {
  1125. struct cmd_ctrl_node *tempnode;
  1126. unsigned long flags;
  1127. lbs_deb_enter(LBS_DEB_HOST);
  1128. if (!priv)
  1129. return NULL;
  1130. spin_lock_irqsave(&priv->driver_lock, flags);
  1131. if (!list_empty(&priv->cmdfreeq)) {
  1132. tempnode = list_first_entry(&priv->cmdfreeq,
  1133. struct cmd_ctrl_node, list);
  1134. list_del(&tempnode->list);
  1135. } else {
  1136. lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
  1137. tempnode = NULL;
  1138. }
  1139. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1140. lbs_deb_leave(LBS_DEB_HOST);
  1141. return tempnode;
  1142. }
  1143. /**
  1144. * @brief This function executes next command in command
  1145. * pending queue. It will put firmware back to PS mode
  1146. * if applicable.
  1147. *
  1148. * @param priv A pointer to struct lbs_private structure
  1149. * @return 0 or -1
  1150. */
  1151. int lbs_execute_next_command(struct lbs_private *priv)
  1152. {
  1153. struct cmd_ctrl_node *cmdnode = NULL;
  1154. struct cmd_header *cmd;
  1155. unsigned long flags;
  1156. int ret = 0;
  1157. /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1158. * only caller to us is lbs_thread() and we get even when a
  1159. * data packet is received */
  1160. lbs_deb_enter(LBS_DEB_THREAD);
  1161. spin_lock_irqsave(&priv->driver_lock, flags);
  1162. if (priv->cur_cmd) {
  1163. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1164. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1165. ret = -1;
  1166. goto done;
  1167. }
  1168. if (!list_empty(&priv->cmdpendingq)) {
  1169. cmdnode = list_first_entry(&priv->cmdpendingq,
  1170. struct cmd_ctrl_node, list);
  1171. }
  1172. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1173. if (cmdnode) {
  1174. cmd = cmdnode->cmdbuf;
  1175. if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
  1176. if ((priv->psstate == PS_STATE_SLEEP) ||
  1177. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1178. lbs_deb_host(
  1179. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1180. le16_to_cpu(cmd->command),
  1181. priv->psstate);
  1182. ret = -1;
  1183. goto done;
  1184. }
  1185. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1186. "0x%04x in psstate %d\n",
  1187. le16_to_cpu(cmd->command), priv->psstate);
  1188. } else if (priv->psstate != PS_STATE_FULL_POWER) {
  1189. /*
  1190. * 1. Non-PS command:
  1191. * Queue it. set needtowakeup to TRUE if current state
  1192. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1193. * 2. PS command but not Exit_PS:
  1194. * Ignore it.
  1195. * 3. PS command Exit_PS:
  1196. * Set needtowakeup to TRUE if current state is SLEEP,
  1197. * otherwise send this command down to firmware
  1198. * immediately.
  1199. */
  1200. if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
  1201. /* Prepare to send Exit PS,
  1202. * this non PS command will be sent later */
  1203. if ((priv->psstate == PS_STATE_SLEEP)
  1204. || (priv->psstate == PS_STATE_PRE_SLEEP)
  1205. ) {
  1206. /* w/ new scheme, it will not reach here.
  1207. since it is blocked in main_thread. */
  1208. priv->needtowakeup = 1;
  1209. } else
  1210. lbs_ps_wakeup(priv, 0);
  1211. ret = 0;
  1212. goto done;
  1213. } else {
  1214. /*
  1215. * PS command. Ignore it if it is not Exit_PS.
  1216. * otherwise send it down immediately.
  1217. */
  1218. struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
  1219. lbs_deb_host(
  1220. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1221. psm->action);
  1222. if (psm->action !=
  1223. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1224. lbs_deb_host(
  1225. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1226. list_del(&cmdnode->list);
  1227. spin_lock_irqsave(&priv->driver_lock, flags);
  1228. lbs_complete_command(priv, cmdnode, 0);
  1229. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1230. ret = 0;
  1231. goto done;
  1232. }
  1233. if ((priv->psstate == PS_STATE_SLEEP) ||
  1234. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1235. lbs_deb_host(
  1236. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1237. list_del(&cmdnode->list);
  1238. spin_lock_irqsave(&priv->driver_lock, flags);
  1239. lbs_complete_command(priv, cmdnode, 0);
  1240. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1241. priv->needtowakeup = 1;
  1242. ret = 0;
  1243. goto done;
  1244. }
  1245. lbs_deb_host(
  1246. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1247. }
  1248. }
  1249. list_del(&cmdnode->list);
  1250. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1251. le16_to_cpu(cmd->command));
  1252. lbs_submit_command(priv, cmdnode);
  1253. } else {
  1254. /*
  1255. * check if in power save mode, if yes, put the device back
  1256. * to PS mode
  1257. */
  1258. #ifdef TODO
  1259. /*
  1260. * This was the old code for libertas+wext. Someone that
  1261. * understands this beast should re-code it in a sane way.
  1262. *
  1263. * I actually don't understand why this is related to WPA
  1264. * and to connection status, shouldn't powering should be
  1265. * independ of such things?
  1266. */
  1267. if ((priv->psmode != LBS802_11POWERMODECAM) &&
  1268. (priv->psstate == PS_STATE_FULL_POWER) &&
  1269. ((priv->connect_status == LBS_CONNECTED) ||
  1270. lbs_mesh_connected(priv))) {
  1271. if (priv->secinfo.WPAenabled ||
  1272. priv->secinfo.WPA2enabled) {
  1273. /* check for valid WPA group keys */
  1274. if (priv->wpa_mcast_key.len ||
  1275. priv->wpa_unicast_key.len) {
  1276. lbs_deb_host(
  1277. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1278. " go back to PS_SLEEP");
  1279. lbs_ps_sleep(priv, 0);
  1280. }
  1281. } else {
  1282. lbs_deb_host(
  1283. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1284. "go back to PS_SLEEP");
  1285. lbs_ps_sleep(priv, 0);
  1286. }
  1287. }
  1288. #endif
  1289. }
  1290. ret = 0;
  1291. done:
  1292. lbs_deb_leave(LBS_DEB_THREAD);
  1293. return ret;
  1294. }
  1295. static void lbs_send_confirmsleep(struct lbs_private *priv)
  1296. {
  1297. unsigned long flags;
  1298. int ret;
  1299. lbs_deb_enter(LBS_DEB_HOST);
  1300. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
  1301. sizeof(confirm_sleep));
  1302. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
  1303. sizeof(confirm_sleep));
  1304. if (ret) {
  1305. lbs_pr_alert("confirm_sleep failed\n");
  1306. goto out;
  1307. }
  1308. spin_lock_irqsave(&priv->driver_lock, flags);
  1309. /* We don't get a response on the sleep-confirmation */
  1310. priv->dnld_sent = DNLD_RES_RECEIVED;
  1311. if (priv->is_host_sleep_configured) {
  1312. priv->is_host_sleep_activated = 1;
  1313. wake_up_interruptible(&priv->host_sleep_q);
  1314. }
  1315. /* If nothing to do, go back to sleep (?) */
  1316. if (!kfifo_len(&priv->event_fifo) && !priv->resp_len[priv->resp_idx])
  1317. priv->psstate = PS_STATE_SLEEP;
  1318. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1319. out:
  1320. lbs_deb_leave(LBS_DEB_HOST);
  1321. }
  1322. void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
  1323. {
  1324. lbs_deb_enter(LBS_DEB_HOST);
  1325. /*
  1326. * PS is currently supported only in Infrastructure mode
  1327. * Remove this check if it is to be supported in IBSS mode also
  1328. */
  1329. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1330. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1331. lbs_deb_leave(LBS_DEB_HOST);
  1332. }
  1333. /**
  1334. * @brief This function sends Exit_PS command to firmware.
  1335. *
  1336. * @param priv A pointer to struct lbs_private structure
  1337. * @param wait_option wait response or not
  1338. * @return n/a
  1339. */
  1340. void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
  1341. {
  1342. __le32 Localpsmode;
  1343. lbs_deb_enter(LBS_DEB_HOST);
  1344. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1345. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1346. CMD_SUBCMD_EXIT_PS,
  1347. wait_option, 0, &Localpsmode);
  1348. lbs_deb_leave(LBS_DEB_HOST);
  1349. }
  1350. /**
  1351. * @brief This function checks condition and prepares to
  1352. * send sleep confirm command to firmware if ok.
  1353. *
  1354. * @param priv A pointer to struct lbs_private structure
  1355. * @param psmode Power Saving mode
  1356. * @return n/a
  1357. */
  1358. void lbs_ps_confirm_sleep(struct lbs_private *priv)
  1359. {
  1360. unsigned long flags =0;
  1361. int allowed = 1;
  1362. lbs_deb_enter(LBS_DEB_HOST);
  1363. spin_lock_irqsave(&priv->driver_lock, flags);
  1364. if (priv->dnld_sent) {
  1365. allowed = 0;
  1366. lbs_deb_host("dnld_sent was set\n");
  1367. }
  1368. /* In-progress command? */
  1369. if (priv->cur_cmd) {
  1370. allowed = 0;
  1371. lbs_deb_host("cur_cmd was set\n");
  1372. }
  1373. /* Pending events or command responses? */
  1374. if (kfifo_len(&priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
  1375. allowed = 0;
  1376. lbs_deb_host("pending events or command responses\n");
  1377. }
  1378. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1379. if (allowed) {
  1380. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1381. lbs_send_confirmsleep(priv);
  1382. } else {
  1383. lbs_deb_host("sleep confirm has been delayed\n");
  1384. }
  1385. lbs_deb_leave(LBS_DEB_HOST);
  1386. }
  1387. /**
  1388. * @brief Configures the transmission power control functionality.
  1389. *
  1390. * @param priv A pointer to struct lbs_private structure
  1391. * @param enable Transmission power control enable
  1392. * @param p0 Power level when link quality is good (dBm).
  1393. * @param p1 Power level when link quality is fair (dBm).
  1394. * @param p2 Power level when link quality is poor (dBm).
  1395. * @param usesnr Use Signal to Noise Ratio in TPC
  1396. *
  1397. * @return 0 on success
  1398. */
  1399. int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
  1400. int8_t p2, int usesnr)
  1401. {
  1402. struct cmd_ds_802_11_tpc_cfg cmd;
  1403. int ret;
  1404. memset(&cmd, 0, sizeof(cmd));
  1405. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1406. cmd.action = cpu_to_le16(CMD_ACT_SET);
  1407. cmd.enable = !!enable;
  1408. cmd.usesnr = !!usesnr;
  1409. cmd.P0 = p0;
  1410. cmd.P1 = p1;
  1411. cmd.P2 = p2;
  1412. ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
  1413. return ret;
  1414. }
  1415. /**
  1416. * @brief Configures the power adaptation settings.
  1417. *
  1418. * @param priv A pointer to struct lbs_private structure
  1419. * @param enable Power adaptation enable
  1420. * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
  1421. * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
  1422. * @param p2 Power level for 48 and 54 Mbps (dBm).
  1423. *
  1424. * @return 0 on Success
  1425. */
  1426. int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
  1427. int8_t p1, int8_t p2)
  1428. {
  1429. struct cmd_ds_802_11_pa_cfg cmd;
  1430. int ret;
  1431. memset(&cmd, 0, sizeof(cmd));
  1432. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1433. cmd.action = cpu_to_le16(CMD_ACT_SET);
  1434. cmd.enable = !!enable;
  1435. cmd.P0 = p0;
  1436. cmd.P1 = p1;
  1437. cmd.P2 = p2;
  1438. ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
  1439. return ret;
  1440. }
  1441. struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
  1442. uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
  1443. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1444. unsigned long callback_arg)
  1445. {
  1446. struct cmd_ctrl_node *cmdnode;
  1447. lbs_deb_enter(LBS_DEB_HOST);
  1448. if (priv->surpriseremoved) {
  1449. lbs_deb_host("PREP_CMD: card removed\n");
  1450. cmdnode = ERR_PTR(-ENOENT);
  1451. goto done;
  1452. }
  1453. if (!lbs_is_cmd_allowed(priv)) {
  1454. cmdnode = ERR_PTR(-EBUSY);
  1455. goto done;
  1456. }
  1457. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1458. if (cmdnode == NULL) {
  1459. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1460. /* Wake up main thread to execute next command */
  1461. wake_up_interruptible(&priv->waitq);
  1462. cmdnode = ERR_PTR(-ENOBUFS);
  1463. goto done;
  1464. }
  1465. cmdnode->callback = callback;
  1466. cmdnode->callback_arg = callback_arg;
  1467. /* Copy the incoming command to the buffer */
  1468. memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
  1469. /* Set sequence number, clean result, move to buffer */
  1470. priv->seqnum++;
  1471. cmdnode->cmdbuf->command = cpu_to_le16(command);
  1472. cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
  1473. cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
  1474. cmdnode->cmdbuf->result = 0;
  1475. lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
  1476. cmdnode->cmdwaitqwoken = 0;
  1477. lbs_queue_cmd(priv, cmdnode);
  1478. wake_up_interruptible(&priv->waitq);
  1479. done:
  1480. lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
  1481. return cmdnode;
  1482. }
  1483. void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
  1484. struct cmd_header *in_cmd, int in_cmd_size)
  1485. {
  1486. lbs_deb_enter(LBS_DEB_CMD);
  1487. __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1488. lbs_cmd_async_callback, 0);
  1489. lbs_deb_leave(LBS_DEB_CMD);
  1490. }
  1491. int __lbs_cmd(struct lbs_private *priv, uint16_t command,
  1492. struct cmd_header *in_cmd, int in_cmd_size,
  1493. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1494. unsigned long callback_arg)
  1495. {
  1496. struct cmd_ctrl_node *cmdnode;
  1497. unsigned long flags;
  1498. int ret = 0;
  1499. lbs_deb_enter(LBS_DEB_HOST);
  1500. cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1501. callback, callback_arg);
  1502. if (IS_ERR(cmdnode)) {
  1503. ret = PTR_ERR(cmdnode);
  1504. goto done;
  1505. }
  1506. might_sleep();
  1507. wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
  1508. spin_lock_irqsave(&priv->driver_lock, flags);
  1509. ret = cmdnode->result;
  1510. if (ret)
  1511. lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
  1512. command, ret);
  1513. __lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1514. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1515. done:
  1516. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1517. return ret;
  1518. }
  1519. EXPORT_SYMBOL_GPL(__lbs_cmd);