cmd.c 45 KB

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