cmd.c 53 KB

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