cmd.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090
  1. /**
  2. * This file contains the handling of command.
  3. * It prepares command and sends it to firmware when it is ready.
  4. */
  5. #include <net/iw_handler.h>
  6. #include <net/lib80211.h>
  7. #include <linux/kfifo.h>
  8. #include "host.h"
  9. #include "hostcmd.h"
  10. #include "decl.h"
  11. #include "defs.h"
  12. #include "dev.h"
  13. #include "assoc.h"
  14. #include "wext.h"
  15. #include "cmd.h"
  16. static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
  17. /**
  18. * @brief Simple callback that copies response back into command
  19. *
  20. * @param priv A pointer to struct lbs_private structure
  21. * @param extra A pointer to the original command structure for which
  22. * 'resp' is a response
  23. * @param resp A pointer to the command response
  24. *
  25. * @return 0 on success, error on failure
  26. */
  27. int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
  28. struct cmd_header *resp)
  29. {
  30. struct cmd_header *buf = (void *)extra;
  31. uint16_t copy_len;
  32. copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
  33. memcpy(buf, resp, copy_len);
  34. return 0;
  35. }
  36. EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
  37. /**
  38. * @brief Simple callback that ignores the result. Use this if
  39. * you just want to send a command to the hardware, but don't
  40. * care for the result.
  41. *
  42. * @param priv ignored
  43. * @param extra ignored
  44. * @param resp ignored
  45. *
  46. * @return 0 for success
  47. */
  48. static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
  49. struct cmd_header *resp)
  50. {
  51. return 0;
  52. }
  53. /**
  54. * @brief Checks whether a command is allowed in Power Save mode
  55. *
  56. * @param command the command ID
  57. * @return 1 if allowed, 0 if not allowed
  58. */
  59. static u8 is_command_allowed_in_ps(u16 cmd)
  60. {
  61. switch (cmd) {
  62. case CMD_802_11_RSSI:
  63. return 1;
  64. default:
  65. break;
  66. }
  67. return 0;
  68. }
  69. /**
  70. * @brief Updates the hardware details like MAC address and regulatory region
  71. *
  72. * @param priv A pointer to struct lbs_private structure
  73. *
  74. * @return 0 on success, error on failure
  75. */
  76. int lbs_update_hw_spec(struct lbs_private *priv)
  77. {
  78. struct cmd_ds_get_hw_spec cmd;
  79. int ret = -1;
  80. u32 i;
  81. lbs_deb_enter(LBS_DEB_CMD);
  82. memset(&cmd, 0, sizeof(cmd));
  83. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  84. memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
  85. ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
  86. if (ret)
  87. goto out;
  88. priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
  89. /* The firmware release is in an interesting format: the patch
  90. * level is in the most significant nibble ... so fix that: */
  91. priv->fwrelease = le32_to_cpu(cmd.fwrelease);
  92. priv->fwrelease = (priv->fwrelease << 8) |
  93. (priv->fwrelease >> 24 & 0xff);
  94. /* Some firmware capabilities:
  95. * CF card firmware 5.0.16p0: cap 0x00000303
  96. * USB dongle firmware 5.110.17p2: cap 0x00000303
  97. */
  98. lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
  99. cmd.permanentaddr,
  100. priv->fwrelease >> 24 & 0xff,
  101. priv->fwrelease >> 16 & 0xff,
  102. priv->fwrelease >> 8 & 0xff,
  103. priv->fwrelease & 0xff,
  104. priv->fwcapinfo);
  105. lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
  106. cmd.hwifversion, cmd.version);
  107. /* Clamp region code to 8-bit since FW spec indicates that it should
  108. * only ever be 8-bit, even though the field size is 16-bit. Some firmware
  109. * returns non-zero high 8 bits here.
  110. */
  111. priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
  112. for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
  113. /* use the region code to search for the index */
  114. if (priv->regioncode == lbs_region_code_to_index[i])
  115. break;
  116. }
  117. /* if it's unidentified region code, use the default (USA) */
  118. if (i >= MRVDRV_MAX_REGION_CODE) {
  119. priv->regioncode = 0x10;
  120. lbs_pr_info("unidentified region code; using the default (USA)\n");
  121. }
  122. if (priv->current_addr[0] == 0xff)
  123. memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
  124. memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
  125. if (priv->mesh_dev)
  126. memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
  127. if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
  128. ret = -1;
  129. goto out;
  130. }
  131. if (lbs_set_universaltable(priv, 0)) {
  132. ret = -1;
  133. goto out;
  134. }
  135. out:
  136. lbs_deb_leave(LBS_DEB_CMD);
  137. return ret;
  138. }
  139. int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria)
  140. {
  141. struct cmd_ds_host_sleep cmd_config;
  142. int ret;
  143. cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
  144. cmd_config.criteria = cpu_to_le32(criteria);
  145. cmd_config.gpio = priv->wol_gpio;
  146. cmd_config.gap = priv->wol_gap;
  147. ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
  148. if (!ret) {
  149. lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
  150. priv->wol_criteria = criteria;
  151. } else {
  152. lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
  153. }
  154. return ret;
  155. }
  156. EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
  157. static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
  158. u16 cmd_action)
  159. {
  160. struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
  161. lbs_deb_enter(LBS_DEB_CMD);
  162. cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
  163. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
  164. S_DS_GEN);
  165. psm->action = cpu_to_le16(cmd_action);
  166. psm->multipledtim = 0;
  167. switch (cmd_action) {
  168. case CMD_SUBCMD_ENTER_PS:
  169. lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
  170. psm->locallisteninterval = 0;
  171. psm->nullpktinterval = 0;
  172. psm->multipledtim =
  173. cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
  174. break;
  175. case CMD_SUBCMD_EXIT_PS:
  176. lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
  177. break;
  178. case CMD_SUBCMD_SLEEP_CONFIRMED:
  179. lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
  180. break;
  181. default:
  182. break;
  183. }
  184. lbs_deb_leave(LBS_DEB_CMD);
  185. return 0;
  186. }
  187. int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
  188. uint16_t cmd_action, uint16_t *timeout)
  189. {
  190. struct cmd_ds_802_11_inactivity_timeout cmd;
  191. int ret;
  192. lbs_deb_enter(LBS_DEB_CMD);
  193. cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
  194. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  195. cmd.action = cpu_to_le16(cmd_action);
  196. if (cmd_action == CMD_ACT_SET)
  197. cmd.timeout = cpu_to_le16(*timeout);
  198. else
  199. cmd.timeout = 0;
  200. ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
  201. if (!ret)
  202. *timeout = le16_to_cpu(cmd.timeout);
  203. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  204. return 0;
  205. }
  206. int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
  207. struct sleep_params *sp)
  208. {
  209. struct cmd_ds_802_11_sleep_params cmd;
  210. int ret;
  211. lbs_deb_enter(LBS_DEB_CMD);
  212. if (cmd_action == CMD_ACT_GET) {
  213. memset(&cmd, 0, sizeof(cmd));
  214. } else {
  215. cmd.error = cpu_to_le16(sp->sp_error);
  216. cmd.offset = cpu_to_le16(sp->sp_offset);
  217. cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
  218. cmd.calcontrol = sp->sp_calcontrol;
  219. cmd.externalsleepclk = sp->sp_extsleepclk;
  220. cmd.reserved = cpu_to_le16(sp->sp_reserved);
  221. }
  222. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  223. cmd.action = cpu_to_le16(cmd_action);
  224. ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
  225. if (!ret) {
  226. lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
  227. "calcontrol 0x%x extsleepclk 0x%x\n",
  228. le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
  229. le16_to_cpu(cmd.stabletime), cmd.calcontrol,
  230. cmd.externalsleepclk);
  231. sp->sp_error = le16_to_cpu(cmd.error);
  232. sp->sp_offset = le16_to_cpu(cmd.offset);
  233. sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
  234. sp->sp_calcontrol = cmd.calcontrol;
  235. sp->sp_extsleepclk = cmd.externalsleepclk;
  236. sp->sp_reserved = le16_to_cpu(cmd.reserved);
  237. }
  238. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  239. return 0;
  240. }
  241. int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
  242. struct assoc_request *assoc)
  243. {
  244. struct cmd_ds_802_11_set_wep cmd;
  245. int ret = 0;
  246. lbs_deb_enter(LBS_DEB_CMD);
  247. memset(&cmd, 0, sizeof(cmd));
  248. cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
  249. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  250. cmd.action = cpu_to_le16(cmd_action);
  251. if (cmd_action == CMD_ACT_ADD) {
  252. int i;
  253. /* default tx key index */
  254. cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
  255. CMD_WEP_KEY_INDEX_MASK);
  256. /* Copy key types and material to host command structure */
  257. for (i = 0; i < 4; i++) {
  258. struct enc_key *pkey = &assoc->wep_keys[i];
  259. switch (pkey->len) {
  260. case KEY_LEN_WEP_40:
  261. cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
  262. memmove(cmd.keymaterial[i], pkey->key, pkey->len);
  263. lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
  264. break;
  265. case KEY_LEN_WEP_104:
  266. cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
  267. memmove(cmd.keymaterial[i], pkey->key, pkey->len);
  268. lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
  269. break;
  270. case 0:
  271. break;
  272. default:
  273. lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
  274. i, pkey->len);
  275. ret = -1;
  276. goto done;
  277. break;
  278. }
  279. }
  280. } else if (cmd_action == CMD_ACT_REMOVE) {
  281. /* ACT_REMOVE clears _all_ WEP keys */
  282. /* default tx key index */
  283. cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
  284. CMD_WEP_KEY_INDEX_MASK);
  285. lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
  286. }
  287. ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
  288. done:
  289. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  290. return ret;
  291. }
  292. int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
  293. uint16_t *enable)
  294. {
  295. struct cmd_ds_802_11_enable_rsn cmd;
  296. int ret;
  297. lbs_deb_enter(LBS_DEB_CMD);
  298. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  299. cmd.action = cpu_to_le16(cmd_action);
  300. if (cmd_action == CMD_ACT_GET)
  301. cmd.enable = 0;
  302. else {
  303. if (*enable)
  304. cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
  305. else
  306. cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
  307. lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
  308. }
  309. ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
  310. if (!ret && cmd_action == CMD_ACT_GET)
  311. *enable = le16_to_cpu(cmd.enable);
  312. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  313. return ret;
  314. }
  315. static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
  316. struct enc_key *key)
  317. {
  318. lbs_deb_enter(LBS_DEB_CMD);
  319. if (key->flags & KEY_INFO_WPA_ENABLED)
  320. keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
  321. if (key->flags & KEY_INFO_WPA_UNICAST)
  322. keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
  323. if (key->flags & KEY_INFO_WPA_MCAST)
  324. keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
  325. keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  326. keyparam->keytypeid = cpu_to_le16(key->type);
  327. keyparam->keylen = cpu_to_le16(key->len);
  328. memcpy(keyparam->key, key->key, key->len);
  329. /* Length field doesn't include the {type,length} header */
  330. keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
  331. lbs_deb_leave(LBS_DEB_CMD);
  332. }
  333. int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
  334. struct assoc_request *assoc)
  335. {
  336. struct cmd_ds_802_11_key_material cmd;
  337. int ret = 0;
  338. int index = 0;
  339. lbs_deb_enter(LBS_DEB_CMD);
  340. cmd.action = cpu_to_le16(cmd_action);
  341. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  342. if (cmd_action == CMD_ACT_GET) {
  343. cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
  344. } else {
  345. memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
  346. if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
  347. set_one_wpa_key(&cmd.keyParamSet[index],
  348. &assoc->wpa_unicast_key);
  349. index++;
  350. }
  351. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
  352. set_one_wpa_key(&cmd.keyParamSet[index],
  353. &assoc->wpa_mcast_key);
  354. index++;
  355. }
  356. /* The common header and as many keys as we included */
  357. cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
  358. keyParamSet[index]));
  359. }
  360. ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
  361. /* Copy the returned key to driver private data */
  362. if (!ret && cmd_action == CMD_ACT_GET) {
  363. void *buf_ptr = cmd.keyParamSet;
  364. void *resp_end = &(&cmd)[1];
  365. while (buf_ptr < resp_end) {
  366. struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
  367. struct enc_key *key;
  368. uint16_t param_set_len = le16_to_cpu(keyparam->length);
  369. uint16_t key_len = le16_to_cpu(keyparam->keylen);
  370. uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
  371. uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
  372. void *end;
  373. end = (void *)keyparam + sizeof(keyparam->type)
  374. + sizeof(keyparam->length) + param_set_len;
  375. /* Make sure we don't access past the end of the IEs */
  376. if (end > resp_end)
  377. break;
  378. if (key_flags & KEY_INFO_WPA_UNICAST)
  379. key = &priv->wpa_unicast_key;
  380. else if (key_flags & KEY_INFO_WPA_MCAST)
  381. key = &priv->wpa_mcast_key;
  382. else
  383. break;
  384. /* Copy returned key into driver */
  385. memset(key, 0, sizeof(struct enc_key));
  386. if (key_len > sizeof(key->key))
  387. break;
  388. key->type = key_type;
  389. key->flags = key_flags;
  390. key->len = key_len;
  391. memcpy(key->key, keyparam->key, key->len);
  392. buf_ptr = end + 1;
  393. }
  394. }
  395. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  396. return ret;
  397. }
  398. /**
  399. * @brief Set an SNMP MIB value
  400. *
  401. * @param priv A pointer to struct lbs_private structure
  402. * @param oid The OID to set in the firmware
  403. * @param val Value to set the OID to
  404. *
  405. * @return 0 on success, error on failure
  406. */
  407. int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
  408. {
  409. struct cmd_ds_802_11_snmp_mib cmd;
  410. int ret;
  411. lbs_deb_enter(LBS_DEB_CMD);
  412. memset(&cmd, 0, sizeof (cmd));
  413. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  414. cmd.action = cpu_to_le16(CMD_ACT_SET);
  415. cmd.oid = cpu_to_le16((u16) oid);
  416. switch (oid) {
  417. case SNMP_MIB_OID_BSS_TYPE:
  418. cmd.bufsize = cpu_to_le16(sizeof(u8));
  419. cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
  420. break;
  421. case SNMP_MIB_OID_11D_ENABLE:
  422. case SNMP_MIB_OID_FRAG_THRESHOLD:
  423. case SNMP_MIB_OID_RTS_THRESHOLD:
  424. case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
  425. case SNMP_MIB_OID_LONG_RETRY_LIMIT:
  426. cmd.bufsize = cpu_to_le16(sizeof(u16));
  427. *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
  428. break;
  429. default:
  430. lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
  431. ret = -EINVAL;
  432. goto out;
  433. }
  434. lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
  435. le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
  436. ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
  437. out:
  438. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  439. return ret;
  440. }
  441. /**
  442. * @brief Get an SNMP MIB value
  443. *
  444. * @param priv A pointer to struct lbs_private structure
  445. * @param oid The OID to retrieve from the firmware
  446. * @param out_val Location for the returned value
  447. *
  448. * @return 0 on success, error on failure
  449. */
  450. int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
  451. {
  452. struct cmd_ds_802_11_snmp_mib cmd;
  453. int ret;
  454. lbs_deb_enter(LBS_DEB_CMD);
  455. memset(&cmd, 0, sizeof (cmd));
  456. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  457. cmd.action = cpu_to_le16(CMD_ACT_GET);
  458. cmd.oid = cpu_to_le16(oid);
  459. ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
  460. if (ret)
  461. goto out;
  462. switch (le16_to_cpu(cmd.bufsize)) {
  463. case sizeof(u8):
  464. if (oid == SNMP_MIB_OID_BSS_TYPE) {
  465. if (cmd.value[0] == 2)
  466. *out_val = IW_MODE_ADHOC;
  467. else
  468. *out_val = IW_MODE_INFRA;
  469. } else
  470. *out_val = cmd.value[0];
  471. break;
  472. case sizeof(u16):
  473. *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
  474. break;
  475. default:
  476. lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
  477. oid, le16_to_cpu(cmd.bufsize));
  478. break;
  479. }
  480. out:
  481. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  482. return ret;
  483. }
  484. /**
  485. * @brief Get the min, max, and current TX power
  486. *
  487. * @param priv A pointer to struct lbs_private structure
  488. * @param curlevel Current power level in dBm
  489. * @param minlevel Minimum supported power level in dBm (optional)
  490. * @param maxlevel Maximum supported power level in dBm (optional)
  491. *
  492. * @return 0 on success, error on failure
  493. */
  494. int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
  495. s16 *maxlevel)
  496. {
  497. struct cmd_ds_802_11_rf_tx_power cmd;
  498. int ret;
  499. lbs_deb_enter(LBS_DEB_CMD);
  500. memset(&cmd, 0, sizeof(cmd));
  501. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  502. cmd.action = cpu_to_le16(CMD_ACT_GET);
  503. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
  504. if (ret == 0) {
  505. *curlevel = le16_to_cpu(cmd.curlevel);
  506. if (minlevel)
  507. *minlevel = cmd.minlevel;
  508. if (maxlevel)
  509. *maxlevel = cmd.maxlevel;
  510. }
  511. lbs_deb_leave(LBS_DEB_CMD);
  512. return ret;
  513. }
  514. /**
  515. * @brief Set the TX power
  516. *
  517. * @param priv A pointer to struct lbs_private structure
  518. * @param dbm The desired power level in dBm
  519. *
  520. * @return 0 on success, error on failure
  521. */
  522. int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
  523. {
  524. struct cmd_ds_802_11_rf_tx_power cmd;
  525. int ret;
  526. lbs_deb_enter(LBS_DEB_CMD);
  527. memset(&cmd, 0, sizeof(cmd));
  528. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  529. cmd.action = cpu_to_le16(CMD_ACT_SET);
  530. cmd.curlevel = cpu_to_le16(dbm);
  531. lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
  532. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
  533. lbs_deb_leave(LBS_DEB_CMD);
  534. return ret;
  535. }
  536. static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
  537. u16 cmd_action, void *pdata_buf)
  538. {
  539. struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
  540. cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
  541. cmd->size =
  542. cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
  543. S_DS_GEN);
  544. monitor->action = cpu_to_le16(cmd_action);
  545. if (cmd_action == CMD_ACT_SET) {
  546. monitor->mode =
  547. cpu_to_le16((u16) (*(u32 *) pdata_buf));
  548. }
  549. return 0;
  550. }
  551. static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
  552. {
  553. /* Bit Rate
  554. * 15:13 Reserved
  555. * 12 54 Mbps
  556. * 11 48 Mbps
  557. * 10 36 Mbps
  558. * 9 24 Mbps
  559. * 8 18 Mbps
  560. * 7 12 Mbps
  561. * 6 9 Mbps
  562. * 5 6 Mbps
  563. * 4 Reserved
  564. * 3 11 Mbps
  565. * 2 5.5 Mbps
  566. * 1 2 Mbps
  567. * 0 1 Mbps
  568. **/
  569. uint16_t ratemask;
  570. int i = lbs_data_rate_to_fw_index(rate);
  571. if (lower_rates_ok)
  572. ratemask = (0x1fef >> (12 - i));
  573. else
  574. ratemask = (1 << i);
  575. return cpu_to_le16(ratemask);
  576. }
  577. int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
  578. uint16_t cmd_action)
  579. {
  580. struct cmd_ds_802_11_rate_adapt_rateset cmd;
  581. int ret;
  582. lbs_deb_enter(LBS_DEB_CMD);
  583. if (!priv->cur_rate && !priv->enablehwauto)
  584. return -EINVAL;
  585. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  586. cmd.action = cpu_to_le16(cmd_action);
  587. cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
  588. cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
  589. ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
  590. if (!ret && cmd_action == CMD_ACT_GET) {
  591. priv->ratebitmap = le16_to_cpu(cmd.bitmap);
  592. priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
  593. }
  594. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  595. return ret;
  596. }
  597. EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
  598. /**
  599. * @brief Set the data rate
  600. *
  601. * @param priv A pointer to struct lbs_private structure
  602. * @param rate The desired data rate, or 0 to clear a locked rate
  603. *
  604. * @return 0 on success, error on failure
  605. */
  606. int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
  607. {
  608. struct cmd_ds_802_11_data_rate cmd;
  609. int ret = 0;
  610. lbs_deb_enter(LBS_DEB_CMD);
  611. memset(&cmd, 0, sizeof(cmd));
  612. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  613. if (rate > 0) {
  614. cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
  615. cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
  616. if (cmd.rates[0] == 0) {
  617. lbs_deb_cmd("DATA_RATE: invalid requested rate of"
  618. " 0x%02X\n", rate);
  619. ret = 0;
  620. goto out;
  621. }
  622. lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
  623. } else {
  624. cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
  625. lbs_deb_cmd("DATA_RATE: setting auto\n");
  626. }
  627. ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
  628. if (ret)
  629. goto out;
  630. lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
  631. /* FIXME: get actual rates FW can do if this command actually returns
  632. * all data rates supported.
  633. */
  634. priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
  635. lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
  636. out:
  637. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  638. return ret;
  639. }
  640. /**
  641. * @brief Get the radio channel
  642. *
  643. * @param priv A pointer to struct lbs_private structure
  644. *
  645. * @return The channel on success, error on failure
  646. */
  647. int lbs_get_channel(struct lbs_private *priv)
  648. {
  649. struct cmd_ds_802_11_rf_channel cmd;
  650. int ret = 0;
  651. lbs_deb_enter(LBS_DEB_CMD);
  652. memset(&cmd, 0, sizeof(cmd));
  653. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  654. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
  655. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  656. if (ret)
  657. goto out;
  658. ret = le16_to_cpu(cmd.channel);
  659. lbs_deb_cmd("current radio channel is %d\n", ret);
  660. out:
  661. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  662. return ret;
  663. }
  664. int lbs_update_channel(struct lbs_private *priv)
  665. {
  666. int ret;
  667. /* the channel in f/w could be out of sync; get the current channel */
  668. lbs_deb_enter(LBS_DEB_ASSOC);
  669. ret = lbs_get_channel(priv);
  670. if (ret > 0) {
  671. priv->curbssparams.channel = ret;
  672. ret = 0;
  673. }
  674. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  675. return ret;
  676. }
  677. /**
  678. * @brief Set the radio channel
  679. *
  680. * @param priv A pointer to struct lbs_private structure
  681. * @param channel The desired channel, or 0 to clear a locked channel
  682. *
  683. * @return 0 on success, error on failure
  684. */
  685. int lbs_set_channel(struct lbs_private *priv, u8 channel)
  686. {
  687. struct cmd_ds_802_11_rf_channel cmd;
  688. #ifdef DEBUG
  689. u8 old_channel = priv->curbssparams.channel;
  690. #endif
  691. int ret = 0;
  692. lbs_deb_enter(LBS_DEB_CMD);
  693. memset(&cmd, 0, sizeof(cmd));
  694. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  695. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
  696. cmd.channel = cpu_to_le16(channel);
  697. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  698. if (ret)
  699. goto out;
  700. priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
  701. lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
  702. priv->curbssparams.channel);
  703. out:
  704. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  705. return ret;
  706. }
  707. static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
  708. struct cmd_ds_command *cmd)
  709. {
  710. lbs_deb_enter(LBS_DEB_CMD);
  711. cmd->command = cpu_to_le16(CMD_802_11_RSSI);
  712. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
  713. cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
  714. /* reset Beacon SNR/NF/RSSI values */
  715. priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
  716. priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
  717. priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
  718. priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
  719. priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
  720. priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
  721. lbs_deb_leave(LBS_DEB_CMD);
  722. return 0;
  723. }
  724. static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
  725. u8 cmd_action, void *pdata_buf)
  726. {
  727. struct lbs_offset_value *offval;
  728. lbs_deb_enter(LBS_DEB_CMD);
  729. offval = (struct lbs_offset_value *)pdata_buf;
  730. switch (le16_to_cpu(cmdptr->command)) {
  731. case CMD_MAC_REG_ACCESS:
  732. {
  733. struct cmd_ds_mac_reg_access *macreg;
  734. cmdptr->size =
  735. cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
  736. + S_DS_GEN);
  737. macreg =
  738. (struct cmd_ds_mac_reg_access *)&cmdptr->params.
  739. macreg;
  740. macreg->action = cpu_to_le16(cmd_action);
  741. macreg->offset = cpu_to_le16((u16) offval->offset);
  742. macreg->value = cpu_to_le32(offval->value);
  743. break;
  744. }
  745. case CMD_BBP_REG_ACCESS:
  746. {
  747. struct cmd_ds_bbp_reg_access *bbpreg;
  748. cmdptr->size =
  749. cpu_to_le16(sizeof
  750. (struct cmd_ds_bbp_reg_access)
  751. + S_DS_GEN);
  752. bbpreg =
  753. (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
  754. bbpreg;
  755. bbpreg->action = cpu_to_le16(cmd_action);
  756. bbpreg->offset = cpu_to_le16((u16) offval->offset);
  757. bbpreg->value = (u8) offval->value;
  758. break;
  759. }
  760. case CMD_RF_REG_ACCESS:
  761. {
  762. struct cmd_ds_rf_reg_access *rfreg;
  763. cmdptr->size =
  764. cpu_to_le16(sizeof
  765. (struct cmd_ds_rf_reg_access) +
  766. S_DS_GEN);
  767. rfreg =
  768. (struct cmd_ds_rf_reg_access *)&cmdptr->params.
  769. rfreg;
  770. rfreg->action = cpu_to_le16(cmd_action);
  771. rfreg->offset = cpu_to_le16((u16) offval->offset);
  772. rfreg->value = (u8) offval->value;
  773. break;
  774. }
  775. default:
  776. break;
  777. }
  778. lbs_deb_leave(LBS_DEB_CMD);
  779. return 0;
  780. }
  781. static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
  782. u16 cmd_action, void *pdata_buf)
  783. {
  784. struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
  785. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  786. cmd->command = cpu_to_le16(CMD_BT_ACCESS);
  787. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
  788. cmd->result = 0;
  789. bt_access->action = cpu_to_le16(cmd_action);
  790. switch (cmd_action) {
  791. case CMD_ACT_BT_ACCESS_ADD:
  792. memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
  793. lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
  794. break;
  795. case CMD_ACT_BT_ACCESS_DEL:
  796. memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
  797. lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
  798. break;
  799. case CMD_ACT_BT_ACCESS_LIST:
  800. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  801. break;
  802. case CMD_ACT_BT_ACCESS_RESET:
  803. break;
  804. case CMD_ACT_BT_ACCESS_SET_INVERT:
  805. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  806. break;
  807. case CMD_ACT_BT_ACCESS_GET_INVERT:
  808. break;
  809. default:
  810. break;
  811. }
  812. lbs_deb_leave(LBS_DEB_CMD);
  813. return 0;
  814. }
  815. static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
  816. u16 cmd_action, void *pdata_buf)
  817. {
  818. struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
  819. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  820. cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
  821. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
  822. cmd->result = 0;
  823. if (pdata_buf)
  824. memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
  825. else
  826. memset(fwt_access, 0, sizeof(*fwt_access));
  827. fwt_access->action = cpu_to_le16(cmd_action);
  828. lbs_deb_leave(LBS_DEB_CMD);
  829. return 0;
  830. }
  831. int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
  832. struct cmd_ds_mesh_access *cmd)
  833. {
  834. int ret;
  835. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  836. cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
  837. cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
  838. cmd->hdr.result = 0;
  839. cmd->action = cpu_to_le16(cmd_action);
  840. ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
  841. lbs_deb_leave(LBS_DEB_CMD);
  842. return ret;
  843. }
  844. static int __lbs_mesh_config_send(struct lbs_private *priv,
  845. struct cmd_ds_mesh_config *cmd,
  846. uint16_t action, uint16_t type)
  847. {
  848. int ret;
  849. lbs_deb_enter(LBS_DEB_CMD);
  850. cmd->hdr.command = cpu_to_le16(CMD_MESH_CONFIG);
  851. cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
  852. cmd->hdr.result = 0;
  853. cmd->type = cpu_to_le16(type);
  854. cmd->action = cpu_to_le16(action);
  855. ret = lbs_cmd_with_response(priv, CMD_MESH_CONFIG, cmd);
  856. lbs_deb_leave(LBS_DEB_CMD);
  857. return ret;
  858. }
  859. int lbs_mesh_config_send(struct lbs_private *priv,
  860. struct cmd_ds_mesh_config *cmd,
  861. uint16_t action, uint16_t type)
  862. {
  863. int ret;
  864. if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
  865. return -EOPNOTSUPP;
  866. ret = __lbs_mesh_config_send(priv, cmd, action, type);
  867. return ret;
  868. }
  869. /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
  870. * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
  871. * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
  872. * lbs_mesh_config_send.
  873. */
  874. int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
  875. {
  876. struct cmd_ds_mesh_config cmd;
  877. struct mrvl_meshie *ie;
  878. DECLARE_SSID_BUF(ssid);
  879. memset(&cmd, 0, sizeof(cmd));
  880. cmd.channel = cpu_to_le16(chan);
  881. ie = (struct mrvl_meshie *)cmd.data;
  882. switch (action) {
  883. case CMD_ACT_MESH_CONFIG_START:
  884. ie->id = WLAN_EID_GENERIC;
  885. ie->val.oui[0] = 0x00;
  886. ie->val.oui[1] = 0x50;
  887. ie->val.oui[2] = 0x43;
  888. ie->val.type = MARVELL_MESH_IE_TYPE;
  889. ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
  890. ie->val.version = MARVELL_MESH_IE_VERSION;
  891. ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
  892. ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
  893. ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
  894. ie->val.mesh_id_len = priv->mesh_ssid_len;
  895. memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
  896. ie->len = sizeof(struct mrvl_meshie_val) -
  897. IW_ESSID_MAX_SIZE + priv->mesh_ssid_len;
  898. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
  899. break;
  900. case CMD_ACT_MESH_CONFIG_STOP:
  901. break;
  902. default:
  903. return -1;
  904. }
  905. lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
  906. action, priv->mesh_tlv, chan,
  907. print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
  908. return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
  909. }
  910. static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
  911. struct cmd_ds_command *cmd,
  912. u16 cmd_action)
  913. {
  914. struct cmd_ds_802_11_beacon_control
  915. *bcn_ctrl = &cmd->params.bcn_ctrl;
  916. lbs_deb_enter(LBS_DEB_CMD);
  917. cmd->size =
  918. cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
  919. + S_DS_GEN);
  920. cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
  921. bcn_ctrl->action = cpu_to_le16(cmd_action);
  922. bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
  923. bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
  924. lbs_deb_leave(LBS_DEB_CMD);
  925. return 0;
  926. }
  927. static void lbs_queue_cmd(struct lbs_private *priv,
  928. struct cmd_ctrl_node *cmdnode)
  929. {
  930. unsigned long flags;
  931. int addtail = 1;
  932. lbs_deb_enter(LBS_DEB_HOST);
  933. if (!cmdnode) {
  934. lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
  935. goto done;
  936. }
  937. if (!cmdnode->cmdbuf->size) {
  938. lbs_deb_host("DNLD_CMD: cmd size is zero\n");
  939. goto done;
  940. }
  941. cmdnode->result = 0;
  942. /* Exit_PS command needs to be queued in the header always. */
  943. if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
  944. struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
  945. if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  946. if (priv->psstate != PS_STATE_FULL_POWER)
  947. addtail = 0;
  948. }
  949. }
  950. spin_lock_irqsave(&priv->driver_lock, flags);
  951. if (addtail)
  952. list_add_tail(&cmdnode->list, &priv->cmdpendingq);
  953. else
  954. list_add(&cmdnode->list, &priv->cmdpendingq);
  955. spin_unlock_irqrestore(&priv->driver_lock, flags);
  956. lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
  957. le16_to_cpu(cmdnode->cmdbuf->command));
  958. done:
  959. lbs_deb_leave(LBS_DEB_HOST);
  960. }
  961. static void lbs_submit_command(struct lbs_private *priv,
  962. struct cmd_ctrl_node *cmdnode)
  963. {
  964. unsigned long flags;
  965. struct cmd_header *cmd;
  966. uint16_t cmdsize;
  967. uint16_t command;
  968. int timeo = 3 * HZ;
  969. int ret;
  970. lbs_deb_enter(LBS_DEB_HOST);
  971. cmd = cmdnode->cmdbuf;
  972. spin_lock_irqsave(&priv->driver_lock, flags);
  973. priv->cur_cmd = cmdnode;
  974. priv->cur_cmd_retcode = 0;
  975. spin_unlock_irqrestore(&priv->driver_lock, flags);
  976. cmdsize = le16_to_cpu(cmd->size);
  977. command = le16_to_cpu(cmd->command);
  978. /* These commands take longer */
  979. if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE ||
  980. command == CMD_802_11_AUTHENTICATE)
  981. timeo = 5 * HZ;
  982. lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
  983. command, le16_to_cpu(cmd->seqnum), cmdsize);
  984. lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
  985. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
  986. if (ret) {
  987. lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
  988. /* Let the timer kick in and retry, and potentially reset
  989. the whole thing if the condition persists */
  990. timeo = HZ/4;
  991. }
  992. /* Setup the timer after transmit command */
  993. mod_timer(&priv->command_timer, jiffies + timeo);
  994. lbs_deb_leave(LBS_DEB_HOST);
  995. }
  996. /**
  997. * This function inserts command node to cmdfreeq
  998. * after cleans it. Requires priv->driver_lock held.
  999. */
  1000. static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  1001. struct cmd_ctrl_node *cmdnode)
  1002. {
  1003. lbs_deb_enter(LBS_DEB_HOST);
  1004. if (!cmdnode)
  1005. goto out;
  1006. cmdnode->callback = NULL;
  1007. cmdnode->callback_arg = 0;
  1008. memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
  1009. list_add_tail(&cmdnode->list, &priv->cmdfreeq);
  1010. out:
  1011. lbs_deb_leave(LBS_DEB_HOST);
  1012. }
  1013. static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  1014. struct cmd_ctrl_node *ptempcmd)
  1015. {
  1016. unsigned long flags;
  1017. spin_lock_irqsave(&priv->driver_lock, flags);
  1018. __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
  1019. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1020. }
  1021. void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
  1022. int result)
  1023. {
  1024. if (cmd == priv->cur_cmd)
  1025. priv->cur_cmd_retcode = result;
  1026. cmd->result = result;
  1027. cmd->cmdwaitqwoken = 1;
  1028. wake_up_interruptible(&cmd->cmdwait_q);
  1029. if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
  1030. __lbs_cleanup_and_insert_cmd(priv, cmd);
  1031. priv->cur_cmd = NULL;
  1032. }
  1033. int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
  1034. {
  1035. struct cmd_ds_802_11_radio_control cmd;
  1036. int ret = -EINVAL;
  1037. lbs_deb_enter(LBS_DEB_CMD);
  1038. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1039. cmd.action = cpu_to_le16(CMD_ACT_SET);
  1040. /* Only v8 and below support setting the preamble */
  1041. if (priv->fwrelease < 0x09000000) {
  1042. switch (preamble) {
  1043. case RADIO_PREAMBLE_SHORT:
  1044. if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
  1045. goto out;
  1046. /* Fall through */
  1047. case RADIO_PREAMBLE_AUTO:
  1048. case RADIO_PREAMBLE_LONG:
  1049. cmd.control = cpu_to_le16(preamble);
  1050. break;
  1051. default:
  1052. goto out;
  1053. }
  1054. }
  1055. if (radio_on)
  1056. cmd.control |= cpu_to_le16(0x1);
  1057. else {
  1058. cmd.control &= cpu_to_le16(~0x1);
  1059. priv->txpower_cur = 0;
  1060. }
  1061. lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
  1062. radio_on ? "ON" : "OFF", preamble);
  1063. priv->radio_on = radio_on;
  1064. ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
  1065. out:
  1066. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  1067. return ret;
  1068. }
  1069. void lbs_set_mac_control(struct lbs_private *priv)
  1070. {
  1071. struct cmd_ds_mac_control cmd;
  1072. lbs_deb_enter(LBS_DEB_CMD);
  1073. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1074. cmd.action = cpu_to_le16(priv->mac_control);
  1075. cmd.reserved = 0;
  1076. lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
  1077. lbs_deb_leave(LBS_DEB_CMD);
  1078. }
  1079. /**
  1080. * @brief This function prepare the command before send to firmware.
  1081. *
  1082. * @param priv A pointer to struct lbs_private structure
  1083. * @param cmd_no command number
  1084. * @param cmd_action command action: GET or SET
  1085. * @param wait_option wait option: wait response or not
  1086. * @param cmd_oid cmd oid: treated as sub command
  1087. * @param pdata_buf A pointer to informaion buffer
  1088. * @return 0 or -1
  1089. */
  1090. int lbs_prepare_and_send_command(struct lbs_private *priv,
  1091. u16 cmd_no,
  1092. u16 cmd_action,
  1093. u16 wait_option, u32 cmd_oid, void *pdata_buf)
  1094. {
  1095. int ret = 0;
  1096. struct cmd_ctrl_node *cmdnode;
  1097. struct cmd_ds_command *cmdptr;
  1098. unsigned long flags;
  1099. lbs_deb_enter(LBS_DEB_HOST);
  1100. if (!priv) {
  1101. lbs_deb_host("PREP_CMD: priv is NULL\n");
  1102. ret = -1;
  1103. goto done;
  1104. }
  1105. if (priv->surpriseremoved) {
  1106. lbs_deb_host("PREP_CMD: card removed\n");
  1107. ret = -1;
  1108. goto done;
  1109. }
  1110. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1111. if (cmdnode == NULL) {
  1112. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1113. /* Wake up main thread to execute next command */
  1114. wake_up_interruptible(&priv->waitq);
  1115. ret = -1;
  1116. goto done;
  1117. }
  1118. cmdnode->callback = NULL;
  1119. cmdnode->callback_arg = (unsigned long)pdata_buf;
  1120. cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
  1121. lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
  1122. /* Set sequence number, command and INT option */
  1123. priv->seqnum++;
  1124. cmdptr->seqnum = cpu_to_le16(priv->seqnum);
  1125. cmdptr->command = cpu_to_le16(cmd_no);
  1126. cmdptr->result = 0;
  1127. switch (cmd_no) {
  1128. case CMD_802_11_PS_MODE:
  1129. ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
  1130. break;
  1131. case CMD_802_11_ASSOCIATE:
  1132. case CMD_802_11_REASSOCIATE:
  1133. ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
  1134. break;
  1135. case CMD_802_11_AUTHENTICATE:
  1136. ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
  1137. break;
  1138. case CMD_MAC_REG_ACCESS:
  1139. case CMD_BBP_REG_ACCESS:
  1140. case CMD_RF_REG_ACCESS:
  1141. ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
  1142. break;
  1143. case CMD_802_11_MONITOR_MODE:
  1144. ret = lbs_cmd_802_11_monitor_mode(cmdptr,
  1145. cmd_action, pdata_buf);
  1146. break;
  1147. case CMD_802_11_RSSI:
  1148. ret = lbs_cmd_802_11_rssi(priv, cmdptr);
  1149. break;
  1150. case CMD_802_11_SET_AFC:
  1151. case CMD_802_11_GET_AFC:
  1152. cmdptr->command = cpu_to_le16(cmd_no);
  1153. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
  1154. S_DS_GEN);
  1155. memmove(&cmdptr->params.afc,
  1156. pdata_buf, sizeof(struct cmd_ds_802_11_afc));
  1157. ret = 0;
  1158. goto done;
  1159. case CMD_802_11D_DOMAIN_INFO:
  1160. ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
  1161. cmd_no, cmd_action);
  1162. break;
  1163. case CMD_802_11_TPC_CFG:
  1164. cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
  1165. cmdptr->size =
  1166. cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
  1167. S_DS_GEN);
  1168. memmove(&cmdptr->params.tpccfg,
  1169. pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
  1170. ret = 0;
  1171. break;
  1172. case CMD_802_11_LED_GPIO_CTRL:
  1173. {
  1174. struct mrvlietypes_ledgpio *gpio =
  1175. (struct mrvlietypes_ledgpio*)
  1176. cmdptr->params.ledgpio.data;
  1177. memmove(&cmdptr->params.ledgpio,
  1178. pdata_buf,
  1179. sizeof(struct cmd_ds_802_11_led_ctrl));
  1180. cmdptr->command =
  1181. cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
  1182. #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
  1183. cmdptr->size =
  1184. cpu_to_le16(le16_to_cpu(gpio->header.len)
  1185. + S_DS_GEN
  1186. + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
  1187. gpio->header.len = gpio->header.len;
  1188. ret = 0;
  1189. break;
  1190. }
  1191. case CMD_BT_ACCESS:
  1192. ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
  1193. break;
  1194. case CMD_FWT_ACCESS:
  1195. ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
  1196. break;
  1197. case CMD_GET_TSF:
  1198. cmdptr->command = cpu_to_le16(CMD_GET_TSF);
  1199. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
  1200. S_DS_GEN);
  1201. ret = 0;
  1202. break;
  1203. case CMD_802_11_BEACON_CTRL:
  1204. ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
  1205. break;
  1206. default:
  1207. lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
  1208. ret = -1;
  1209. break;
  1210. }
  1211. /* return error, since the command preparation failed */
  1212. if (ret != 0) {
  1213. lbs_deb_host("PREP_CMD: command preparation failed\n");
  1214. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1215. ret = -1;
  1216. goto done;
  1217. }
  1218. cmdnode->cmdwaitqwoken = 0;
  1219. lbs_queue_cmd(priv, cmdnode);
  1220. wake_up_interruptible(&priv->waitq);
  1221. if (wait_option & CMD_OPTION_WAITFORRSP) {
  1222. lbs_deb_host("PREP_CMD: wait for response\n");
  1223. might_sleep();
  1224. wait_event_interruptible(cmdnode->cmdwait_q,
  1225. cmdnode->cmdwaitqwoken);
  1226. }
  1227. spin_lock_irqsave(&priv->driver_lock, flags);
  1228. if (priv->cur_cmd_retcode) {
  1229. lbs_deb_host("PREP_CMD: command failed with return code %d\n",
  1230. priv->cur_cmd_retcode);
  1231. priv->cur_cmd_retcode = 0;
  1232. ret = -1;
  1233. }
  1234. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1235. done:
  1236. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1237. return ret;
  1238. }
  1239. /**
  1240. * @brief This function allocates the command buffer and link
  1241. * it to command free queue.
  1242. *
  1243. * @param priv A pointer to struct lbs_private structure
  1244. * @return 0 or -1
  1245. */
  1246. int lbs_allocate_cmd_buffer(struct lbs_private *priv)
  1247. {
  1248. int ret = 0;
  1249. u32 bufsize;
  1250. u32 i;
  1251. struct cmd_ctrl_node *cmdarray;
  1252. lbs_deb_enter(LBS_DEB_HOST);
  1253. /* Allocate and initialize the command array */
  1254. bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
  1255. if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
  1256. lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
  1257. ret = -1;
  1258. goto done;
  1259. }
  1260. priv->cmd_array = cmdarray;
  1261. /* Allocate and initialize each command buffer in the command array */
  1262. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1263. cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
  1264. if (!cmdarray[i].cmdbuf) {
  1265. lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
  1266. ret = -1;
  1267. goto done;
  1268. }
  1269. }
  1270. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1271. init_waitqueue_head(&cmdarray[i].cmdwait_q);
  1272. lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
  1273. }
  1274. ret = 0;
  1275. done:
  1276. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1277. return ret;
  1278. }
  1279. /**
  1280. * @brief This function frees the command buffer.
  1281. *
  1282. * @param priv A pointer to struct lbs_private structure
  1283. * @return 0 or -1
  1284. */
  1285. int lbs_free_cmd_buffer(struct lbs_private *priv)
  1286. {
  1287. struct cmd_ctrl_node *cmdarray;
  1288. unsigned int i;
  1289. lbs_deb_enter(LBS_DEB_HOST);
  1290. /* need to check if cmd array is allocated or not */
  1291. if (priv->cmd_array == NULL) {
  1292. lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
  1293. goto done;
  1294. }
  1295. cmdarray = priv->cmd_array;
  1296. /* Release shared memory buffers */
  1297. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1298. if (cmdarray[i].cmdbuf) {
  1299. kfree(cmdarray[i].cmdbuf);
  1300. cmdarray[i].cmdbuf = NULL;
  1301. }
  1302. }
  1303. /* Release cmd_ctrl_node */
  1304. if (priv->cmd_array) {
  1305. kfree(priv->cmd_array);
  1306. priv->cmd_array = NULL;
  1307. }
  1308. done:
  1309. lbs_deb_leave(LBS_DEB_HOST);
  1310. return 0;
  1311. }
  1312. /**
  1313. * @brief This function gets a free command node if available in
  1314. * command free queue.
  1315. *
  1316. * @param priv A pointer to struct lbs_private structure
  1317. * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
  1318. */
  1319. static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
  1320. {
  1321. struct cmd_ctrl_node *tempnode;
  1322. unsigned long flags;
  1323. lbs_deb_enter(LBS_DEB_HOST);
  1324. if (!priv)
  1325. return NULL;
  1326. spin_lock_irqsave(&priv->driver_lock, flags);
  1327. if (!list_empty(&priv->cmdfreeq)) {
  1328. tempnode = list_first_entry(&priv->cmdfreeq,
  1329. struct cmd_ctrl_node, list);
  1330. list_del(&tempnode->list);
  1331. } else {
  1332. lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
  1333. tempnode = NULL;
  1334. }
  1335. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1336. lbs_deb_leave(LBS_DEB_HOST);
  1337. return tempnode;
  1338. }
  1339. /**
  1340. * @brief This function executes next command in command
  1341. * pending queue. It will put fimware back to PS mode
  1342. * if applicable.
  1343. *
  1344. * @param priv A pointer to struct lbs_private structure
  1345. * @return 0 or -1
  1346. */
  1347. int lbs_execute_next_command(struct lbs_private *priv)
  1348. {
  1349. struct cmd_ctrl_node *cmdnode = NULL;
  1350. struct cmd_header *cmd;
  1351. unsigned long flags;
  1352. int ret = 0;
  1353. /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1354. * only caller to us is lbs_thread() and we get even when a
  1355. * data packet is received */
  1356. lbs_deb_enter(LBS_DEB_THREAD);
  1357. spin_lock_irqsave(&priv->driver_lock, flags);
  1358. if (priv->cur_cmd) {
  1359. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1360. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1361. ret = -1;
  1362. goto done;
  1363. }
  1364. if (!list_empty(&priv->cmdpendingq)) {
  1365. cmdnode = list_first_entry(&priv->cmdpendingq,
  1366. struct cmd_ctrl_node, list);
  1367. }
  1368. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1369. if (cmdnode) {
  1370. cmd = cmdnode->cmdbuf;
  1371. if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
  1372. if ((priv->psstate == PS_STATE_SLEEP) ||
  1373. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1374. lbs_deb_host(
  1375. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1376. le16_to_cpu(cmd->command),
  1377. priv->psstate);
  1378. ret = -1;
  1379. goto done;
  1380. }
  1381. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1382. "0x%04x in psstate %d\n",
  1383. le16_to_cpu(cmd->command), priv->psstate);
  1384. } else if (priv->psstate != PS_STATE_FULL_POWER) {
  1385. /*
  1386. * 1. Non-PS command:
  1387. * Queue it. set needtowakeup to TRUE if current state
  1388. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1389. * 2. PS command but not Exit_PS:
  1390. * Ignore it.
  1391. * 3. PS command Exit_PS:
  1392. * Set needtowakeup to TRUE if current state is SLEEP,
  1393. * otherwise send this command down to firmware
  1394. * immediately.
  1395. */
  1396. if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
  1397. /* Prepare to send Exit PS,
  1398. * this non PS command will be sent later */
  1399. if ((priv->psstate == PS_STATE_SLEEP)
  1400. || (priv->psstate == PS_STATE_PRE_SLEEP)
  1401. ) {
  1402. /* w/ new scheme, it will not reach here.
  1403. since it is blocked in main_thread. */
  1404. priv->needtowakeup = 1;
  1405. } else
  1406. lbs_ps_wakeup(priv, 0);
  1407. ret = 0;
  1408. goto done;
  1409. } else {
  1410. /*
  1411. * PS command. Ignore it if it is not Exit_PS.
  1412. * otherwise send it down immediately.
  1413. */
  1414. struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
  1415. lbs_deb_host(
  1416. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1417. psm->action);
  1418. if (psm->action !=
  1419. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1420. lbs_deb_host(
  1421. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1422. list_del(&cmdnode->list);
  1423. spin_lock_irqsave(&priv->driver_lock, flags);
  1424. lbs_complete_command(priv, cmdnode, 0);
  1425. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1426. ret = 0;
  1427. goto done;
  1428. }
  1429. if ((priv->psstate == PS_STATE_SLEEP) ||
  1430. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1431. lbs_deb_host(
  1432. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1433. list_del(&cmdnode->list);
  1434. spin_lock_irqsave(&priv->driver_lock, flags);
  1435. lbs_complete_command(priv, cmdnode, 0);
  1436. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1437. priv->needtowakeup = 1;
  1438. ret = 0;
  1439. goto done;
  1440. }
  1441. lbs_deb_host(
  1442. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1443. }
  1444. }
  1445. list_del(&cmdnode->list);
  1446. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1447. le16_to_cpu(cmd->command));
  1448. lbs_submit_command(priv, cmdnode);
  1449. } else {
  1450. /*
  1451. * check if in power save mode, if yes, put the device back
  1452. * to PS mode
  1453. */
  1454. if ((priv->psmode != LBS802_11POWERMODECAM) &&
  1455. (priv->psstate == PS_STATE_FULL_POWER) &&
  1456. ((priv->connect_status == LBS_CONNECTED) ||
  1457. (priv->mesh_connect_status == LBS_CONNECTED))) {
  1458. if (priv->secinfo.WPAenabled ||
  1459. priv->secinfo.WPA2enabled) {
  1460. /* check for valid WPA group keys */
  1461. if (priv->wpa_mcast_key.len ||
  1462. priv->wpa_unicast_key.len) {
  1463. lbs_deb_host(
  1464. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1465. " go back to PS_SLEEP");
  1466. lbs_ps_sleep(priv, 0);
  1467. }
  1468. } else {
  1469. lbs_deb_host(
  1470. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1471. "go back to PS_SLEEP");
  1472. lbs_ps_sleep(priv, 0);
  1473. }
  1474. }
  1475. }
  1476. ret = 0;
  1477. done:
  1478. lbs_deb_leave(LBS_DEB_THREAD);
  1479. return ret;
  1480. }
  1481. void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
  1482. {
  1483. union iwreq_data iwrq;
  1484. u8 buf[50];
  1485. lbs_deb_enter(LBS_DEB_WEXT);
  1486. memset(&iwrq, 0, sizeof(union iwreq_data));
  1487. memset(buf, 0, sizeof(buf));
  1488. snprintf(buf, sizeof(buf) - 1, "%s", str);
  1489. iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
  1490. /* Send Event to upper layer */
  1491. lbs_deb_wext("event indication string %s\n", (char *)buf);
  1492. lbs_deb_wext("event indication length %d\n", iwrq.data.length);
  1493. lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
  1494. wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
  1495. lbs_deb_leave(LBS_DEB_WEXT);
  1496. }
  1497. static void lbs_send_confirmsleep(struct lbs_private *priv)
  1498. {
  1499. unsigned long flags;
  1500. int ret;
  1501. lbs_deb_enter(LBS_DEB_HOST);
  1502. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
  1503. sizeof(confirm_sleep));
  1504. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
  1505. sizeof(confirm_sleep));
  1506. if (ret) {
  1507. lbs_pr_alert("confirm_sleep failed\n");
  1508. goto out;
  1509. }
  1510. spin_lock_irqsave(&priv->driver_lock, flags);
  1511. /* We don't get a response on the sleep-confirmation */
  1512. priv->dnld_sent = DNLD_RES_RECEIVED;
  1513. /* If nothing to do, go back to sleep (?) */
  1514. if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
  1515. priv->psstate = PS_STATE_SLEEP;
  1516. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1517. out:
  1518. lbs_deb_leave(LBS_DEB_HOST);
  1519. }
  1520. void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
  1521. {
  1522. lbs_deb_enter(LBS_DEB_HOST);
  1523. /*
  1524. * PS is currently supported only in Infrastructure mode
  1525. * Remove this check if it is to be supported in IBSS mode also
  1526. */
  1527. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1528. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1529. lbs_deb_leave(LBS_DEB_HOST);
  1530. }
  1531. /**
  1532. * @brief This function sends Exit_PS command to firmware.
  1533. *
  1534. * @param priv A pointer to struct lbs_private structure
  1535. * @param wait_option wait response or not
  1536. * @return n/a
  1537. */
  1538. void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
  1539. {
  1540. __le32 Localpsmode;
  1541. lbs_deb_enter(LBS_DEB_HOST);
  1542. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1543. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1544. CMD_SUBCMD_EXIT_PS,
  1545. wait_option, 0, &Localpsmode);
  1546. lbs_deb_leave(LBS_DEB_HOST);
  1547. }
  1548. /**
  1549. * @brief This function checks condition and prepares to
  1550. * send sleep confirm command to firmware if ok.
  1551. *
  1552. * @param priv A pointer to struct lbs_private structure
  1553. * @param psmode Power Saving mode
  1554. * @return n/a
  1555. */
  1556. void lbs_ps_confirm_sleep(struct lbs_private *priv)
  1557. {
  1558. unsigned long flags =0;
  1559. int allowed = 1;
  1560. lbs_deb_enter(LBS_DEB_HOST);
  1561. spin_lock_irqsave(&priv->driver_lock, flags);
  1562. if (priv->dnld_sent) {
  1563. allowed = 0;
  1564. lbs_deb_host("dnld_sent was set\n");
  1565. }
  1566. /* In-progress command? */
  1567. if (priv->cur_cmd) {
  1568. allowed = 0;
  1569. lbs_deb_host("cur_cmd was set\n");
  1570. }
  1571. /* Pending events or command responses? */
  1572. if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
  1573. allowed = 0;
  1574. lbs_deb_host("pending events or command responses\n");
  1575. }
  1576. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1577. if (allowed) {
  1578. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1579. lbs_send_confirmsleep(priv);
  1580. } else {
  1581. lbs_deb_host("sleep confirm has been delayed\n");
  1582. }
  1583. lbs_deb_leave(LBS_DEB_HOST);
  1584. }
  1585. /**
  1586. * @brief Configures the transmission power control functionality.
  1587. *
  1588. * @param priv A pointer to struct lbs_private structure
  1589. * @param enable Transmission power control enable
  1590. * @param p0 Power level when link quality is good (dBm).
  1591. * @param p1 Power level when link quality is fair (dBm).
  1592. * @param p2 Power level when link quality is poor (dBm).
  1593. * @param usesnr Use Signal to Noise Ratio in TPC
  1594. *
  1595. * @return 0 on success
  1596. */
  1597. int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
  1598. int8_t p2, int usesnr)
  1599. {
  1600. struct cmd_ds_802_11_tpc_cfg cmd;
  1601. int ret;
  1602. memset(&cmd, 0, sizeof(cmd));
  1603. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1604. cmd.action = cpu_to_le16(CMD_ACT_SET);
  1605. cmd.enable = !!enable;
  1606. cmd.usesnr = !!usesnr;
  1607. cmd.P0 = p0;
  1608. cmd.P1 = p1;
  1609. cmd.P2 = p2;
  1610. ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
  1611. return ret;
  1612. }
  1613. /**
  1614. * @brief Configures the power adaptation settings.
  1615. *
  1616. * @param priv A pointer to struct lbs_private structure
  1617. * @param enable Power adaptation enable
  1618. * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
  1619. * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
  1620. * @param p2 Power level for 48 and 54 Mbps (dBm).
  1621. *
  1622. * @return 0 on Success
  1623. */
  1624. int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
  1625. int8_t p1, int8_t p2)
  1626. {
  1627. struct cmd_ds_802_11_pa_cfg cmd;
  1628. int ret;
  1629. memset(&cmd, 0, sizeof(cmd));
  1630. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1631. cmd.action = cpu_to_le16(CMD_ACT_SET);
  1632. cmd.enable = !!enable;
  1633. cmd.P0 = p0;
  1634. cmd.P1 = p1;
  1635. cmd.P2 = p2;
  1636. ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
  1637. return ret;
  1638. }
  1639. static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
  1640. uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
  1641. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1642. unsigned long callback_arg)
  1643. {
  1644. struct cmd_ctrl_node *cmdnode;
  1645. lbs_deb_enter(LBS_DEB_HOST);
  1646. if (priv->surpriseremoved) {
  1647. lbs_deb_host("PREP_CMD: card removed\n");
  1648. cmdnode = ERR_PTR(-ENOENT);
  1649. goto done;
  1650. }
  1651. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1652. if (cmdnode == NULL) {
  1653. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1654. /* Wake up main thread to execute next command */
  1655. wake_up_interruptible(&priv->waitq);
  1656. cmdnode = ERR_PTR(-ENOBUFS);
  1657. goto done;
  1658. }
  1659. cmdnode->callback = callback;
  1660. cmdnode->callback_arg = callback_arg;
  1661. /* Copy the incoming command to the buffer */
  1662. memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
  1663. /* Set sequence number, clean result, move to buffer */
  1664. priv->seqnum++;
  1665. cmdnode->cmdbuf->command = cpu_to_le16(command);
  1666. cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
  1667. cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
  1668. cmdnode->cmdbuf->result = 0;
  1669. lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
  1670. cmdnode->cmdwaitqwoken = 0;
  1671. lbs_queue_cmd(priv, cmdnode);
  1672. wake_up_interruptible(&priv->waitq);
  1673. done:
  1674. lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
  1675. return cmdnode;
  1676. }
  1677. void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
  1678. struct cmd_header *in_cmd, int in_cmd_size)
  1679. {
  1680. lbs_deb_enter(LBS_DEB_CMD);
  1681. __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1682. lbs_cmd_async_callback, 0);
  1683. lbs_deb_leave(LBS_DEB_CMD);
  1684. }
  1685. int __lbs_cmd(struct lbs_private *priv, uint16_t command,
  1686. struct cmd_header *in_cmd, int in_cmd_size,
  1687. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1688. unsigned long callback_arg)
  1689. {
  1690. struct cmd_ctrl_node *cmdnode;
  1691. unsigned long flags;
  1692. int ret = 0;
  1693. lbs_deb_enter(LBS_DEB_HOST);
  1694. cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1695. callback, callback_arg);
  1696. if (IS_ERR(cmdnode)) {
  1697. ret = PTR_ERR(cmdnode);
  1698. goto done;
  1699. }
  1700. might_sleep();
  1701. wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
  1702. spin_lock_irqsave(&priv->driver_lock, flags);
  1703. ret = cmdnode->result;
  1704. if (ret)
  1705. lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
  1706. command, ret);
  1707. __lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1708. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1709. done:
  1710. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1711. return ret;
  1712. }
  1713. EXPORT_SYMBOL_GPL(__lbs_cmd);