cmd.c 45 KB

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