cmd.c 45 KB

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