wmi.c 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/ip.h>
  18. #include <linux/in.h>
  19. #include "core.h"
  20. #include "debug.h"
  21. #include "testmode.h"
  22. #include "trace.h"
  23. #include "../regd.h"
  24. #include "../regd_common.h"
  25. static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
  26. static const s32 wmi_rate_tbl[][2] = {
  27. /* {W/O SGI, with SGI} */
  28. {1000, 1000},
  29. {2000, 2000},
  30. {5500, 5500},
  31. {11000, 11000},
  32. {6000, 6000},
  33. {9000, 9000},
  34. {12000, 12000},
  35. {18000, 18000},
  36. {24000, 24000},
  37. {36000, 36000},
  38. {48000, 48000},
  39. {54000, 54000},
  40. {6500, 7200},
  41. {13000, 14400},
  42. {19500, 21700},
  43. {26000, 28900},
  44. {39000, 43300},
  45. {52000, 57800},
  46. {58500, 65000},
  47. {65000, 72200},
  48. {13500, 15000},
  49. {27000, 30000},
  50. {40500, 45000},
  51. {54000, 60000},
  52. {81000, 90000},
  53. {108000, 120000},
  54. {121500, 135000},
  55. {135000, 150000},
  56. {0, 0}
  57. };
  58. static const s32 wmi_rate_tbl_mcs15[][2] = {
  59. /* {W/O SGI, with SGI} */
  60. {1000, 1000},
  61. {2000, 2000},
  62. {5500, 5500},
  63. {11000, 11000},
  64. {6000, 6000},
  65. {9000, 9000},
  66. {12000, 12000},
  67. {18000, 18000},
  68. {24000, 24000},
  69. {36000, 36000},
  70. {48000, 48000},
  71. {54000, 54000},
  72. {6500, 7200}, /* HT 20, MCS 0 */
  73. {13000, 14400},
  74. {19500, 21700},
  75. {26000, 28900},
  76. {39000, 43300},
  77. {52000, 57800},
  78. {58500, 65000},
  79. {65000, 72200},
  80. {13000, 14400}, /* HT 20, MCS 8 */
  81. {26000, 28900},
  82. {39000, 43300},
  83. {52000, 57800},
  84. {78000, 86700},
  85. {104000, 115600},
  86. {117000, 130000},
  87. {130000, 144400}, /* HT 20, MCS 15 */
  88. {13500, 15000}, /*HT 40, MCS 0 */
  89. {27000, 30000},
  90. {40500, 45000},
  91. {54000, 60000},
  92. {81000, 90000},
  93. {108000, 120000},
  94. {121500, 135000},
  95. {135000, 150000},
  96. {27000, 30000}, /*HT 40, MCS 8 */
  97. {54000, 60000},
  98. {81000, 90000},
  99. {108000, 120000},
  100. {162000, 180000},
  101. {216000, 240000},
  102. {243000, 270000},
  103. {270000, 300000}, /*HT 40, MCS 15 */
  104. {0, 0}
  105. };
  106. /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
  107. static const u8 up_to_ac[] = {
  108. WMM_AC_BE,
  109. WMM_AC_BK,
  110. WMM_AC_BK,
  111. WMM_AC_BE,
  112. WMM_AC_VI,
  113. WMM_AC_VI,
  114. WMM_AC_VO,
  115. WMM_AC_VO,
  116. };
  117. void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
  118. {
  119. if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
  120. return;
  121. wmi->ep_id = ep_id;
  122. }
  123. enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
  124. {
  125. return wmi->ep_id;
  126. }
  127. struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
  128. {
  129. struct ath6kl_vif *vif, *found = NULL;
  130. if (WARN_ON(if_idx > (ar->vif_max - 1)))
  131. return NULL;
  132. /* FIXME: Locking */
  133. spin_lock_bh(&ar->list_lock);
  134. list_for_each_entry(vif, &ar->vif_list, list) {
  135. if (vif->fw_vif_idx == if_idx) {
  136. found = vif;
  137. break;
  138. }
  139. }
  140. spin_unlock_bh(&ar->list_lock);
  141. return found;
  142. }
  143. /* Performs DIX to 802.3 encapsulation for transmit packets.
  144. * Assumes the entire DIX header is contiguous and that there is
  145. * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
  146. */
  147. int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
  148. {
  149. struct ath6kl_llc_snap_hdr *llc_hdr;
  150. struct ethhdr *eth_hdr;
  151. size_t new_len;
  152. __be16 type;
  153. u8 *datap;
  154. u16 size;
  155. if (WARN_ON(skb == NULL))
  156. return -EINVAL;
  157. size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
  158. if (skb_headroom(skb) < size)
  159. return -ENOMEM;
  160. eth_hdr = (struct ethhdr *) skb->data;
  161. type = eth_hdr->h_proto;
  162. if (!is_ethertype(be16_to_cpu(type))) {
  163. ath6kl_dbg(ATH6KL_DBG_WMI,
  164. "%s: pkt is already in 802.3 format\n", __func__);
  165. return 0;
  166. }
  167. new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
  168. skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
  169. datap = skb->data;
  170. eth_hdr->h_proto = cpu_to_be16(new_len);
  171. memcpy(datap, eth_hdr, sizeof(*eth_hdr));
  172. llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
  173. llc_hdr->dsap = 0xAA;
  174. llc_hdr->ssap = 0xAA;
  175. llc_hdr->cntl = 0x03;
  176. llc_hdr->org_code[0] = 0x0;
  177. llc_hdr->org_code[1] = 0x0;
  178. llc_hdr->org_code[2] = 0x0;
  179. llc_hdr->eth_type = type;
  180. return 0;
  181. }
  182. static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
  183. u8 *version, void *tx_meta_info)
  184. {
  185. struct wmi_tx_meta_v1 *v1;
  186. struct wmi_tx_meta_v2 *v2;
  187. if (WARN_ON(skb == NULL || version == NULL))
  188. return -EINVAL;
  189. switch (*version) {
  190. case WMI_META_VERSION_1:
  191. skb_push(skb, WMI_MAX_TX_META_SZ);
  192. v1 = (struct wmi_tx_meta_v1 *) skb->data;
  193. v1->pkt_id = 0;
  194. v1->rate_plcy_id = 0;
  195. *version = WMI_META_VERSION_1;
  196. break;
  197. case WMI_META_VERSION_2:
  198. skb_push(skb, WMI_MAX_TX_META_SZ);
  199. v2 = (struct wmi_tx_meta_v2 *) skb->data;
  200. memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
  201. sizeof(struct wmi_tx_meta_v2));
  202. break;
  203. }
  204. return 0;
  205. }
  206. int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
  207. u8 msg_type, u32 flags,
  208. enum wmi_data_hdr_data_type data_type,
  209. u8 meta_ver, void *tx_meta_info, u8 if_idx)
  210. {
  211. struct wmi_data_hdr *data_hdr;
  212. int ret;
  213. if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
  214. return -EINVAL;
  215. if (tx_meta_info) {
  216. ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
  217. if (ret)
  218. return ret;
  219. }
  220. skb_push(skb, sizeof(struct wmi_data_hdr));
  221. data_hdr = (struct wmi_data_hdr *)skb->data;
  222. memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
  223. data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  224. data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
  225. if (flags & WMI_DATA_HDR_FLAGS_MORE)
  226. data_hdr->info |= WMI_DATA_HDR_MORE;
  227. if (flags & WMI_DATA_HDR_FLAGS_EOSP)
  228. data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP);
  229. data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
  230. data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
  231. return 0;
  232. }
  233. u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
  234. {
  235. struct iphdr *ip_hdr = (struct iphdr *) pkt;
  236. u8 ip_pri;
  237. /*
  238. * Determine IPTOS priority
  239. *
  240. * IP-TOS - 8bits
  241. * : DSCP(6-bits) ECN(2-bits)
  242. * : DSCP - P2 P1 P0 X X X
  243. * where (P2 P1 P0) form 802.1D
  244. */
  245. ip_pri = ip_hdr->tos >> 5;
  246. ip_pri &= 0x7;
  247. if ((layer2_pri & 0x7) > ip_pri)
  248. return (u8) layer2_pri & 0x7;
  249. else
  250. return ip_pri;
  251. }
  252. u8 ath6kl_wmi_get_traffic_class(u8 user_priority)
  253. {
  254. return up_to_ac[user_priority & 0x7];
  255. }
  256. int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
  257. struct sk_buff *skb,
  258. u32 layer2_priority, bool wmm_enabled,
  259. u8 *ac)
  260. {
  261. struct wmi_data_hdr *data_hdr;
  262. struct ath6kl_llc_snap_hdr *llc_hdr;
  263. struct wmi_create_pstream_cmd cmd;
  264. u32 meta_size, hdr_size;
  265. u16 ip_type = IP_ETHERTYPE;
  266. u8 stream_exist, usr_pri;
  267. u8 traffic_class = WMM_AC_BE;
  268. u8 *datap;
  269. if (WARN_ON(skb == NULL))
  270. return -EINVAL;
  271. datap = skb->data;
  272. data_hdr = (struct wmi_data_hdr *) datap;
  273. meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
  274. WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
  275. if (!wmm_enabled) {
  276. /* If WMM is disabled all traffic goes as BE traffic */
  277. usr_pri = 0;
  278. } else {
  279. hdr_size = sizeof(struct ethhdr);
  280. llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
  281. sizeof(struct
  282. wmi_data_hdr) +
  283. meta_size + hdr_size);
  284. if (llc_hdr->eth_type == htons(ip_type)) {
  285. /*
  286. * Extract the endpoint info from the TOS field
  287. * in the IP header.
  288. */
  289. usr_pri =
  290. ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
  291. sizeof(struct ath6kl_llc_snap_hdr),
  292. layer2_priority);
  293. } else {
  294. usr_pri = layer2_priority & 0x7;
  295. }
  296. /*
  297. * Queue the EAPOL frames in the same WMM_AC_VO queue
  298. * as that of management frames.
  299. */
  300. if (skb->protocol == cpu_to_be16(ETH_P_PAE))
  301. usr_pri = WMI_VOICE_USER_PRIORITY;
  302. }
  303. /*
  304. * workaround for WMM S5
  305. *
  306. * FIXME: wmi->traffic_class is always 100 so this test doesn't
  307. * make sense
  308. */
  309. if ((wmi->traffic_class == WMM_AC_VI) &&
  310. ((usr_pri == 5) || (usr_pri == 4)))
  311. usr_pri = 1;
  312. /* Convert user priority to traffic class */
  313. traffic_class = up_to_ac[usr_pri & 0x7];
  314. wmi_data_hdr_set_up(data_hdr, usr_pri);
  315. spin_lock_bh(&wmi->lock);
  316. stream_exist = wmi->fat_pipe_exist;
  317. spin_unlock_bh(&wmi->lock);
  318. if (!(stream_exist & (1 << traffic_class))) {
  319. memset(&cmd, 0, sizeof(cmd));
  320. cmd.traffic_class = traffic_class;
  321. cmd.user_pri = usr_pri;
  322. cmd.inactivity_int =
  323. cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
  324. /* Implicit streams are created with TSID 0xFF */
  325. cmd.tsid = WMI_IMPLICIT_PSTREAM;
  326. ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
  327. }
  328. *ac = traffic_class;
  329. return 0;
  330. }
  331. int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
  332. {
  333. struct ieee80211_hdr_3addr *pwh, wh;
  334. struct ath6kl_llc_snap_hdr *llc_hdr;
  335. struct ethhdr eth_hdr;
  336. u32 hdr_size;
  337. u8 *datap;
  338. __le16 sub_type;
  339. if (WARN_ON(skb == NULL))
  340. return -EINVAL;
  341. datap = skb->data;
  342. pwh = (struct ieee80211_hdr_3addr *) datap;
  343. sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
  344. memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
  345. /* Strip off the 802.11 header */
  346. if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
  347. hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
  348. sizeof(u32));
  349. skb_pull(skb, hdr_size);
  350. } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA)) {
  351. skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
  352. }
  353. datap = skb->data;
  354. llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
  355. memset(&eth_hdr, 0, sizeof(eth_hdr));
  356. eth_hdr.h_proto = llc_hdr->eth_type;
  357. switch ((le16_to_cpu(wh.frame_control)) &
  358. (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  359. case IEEE80211_FCTL_TODS:
  360. memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
  361. memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
  362. break;
  363. case IEEE80211_FCTL_FROMDS:
  364. memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
  365. memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
  366. break;
  367. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  368. break;
  369. default:
  370. memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
  371. memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
  372. break;
  373. }
  374. skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
  375. skb_push(skb, sizeof(eth_hdr));
  376. datap = skb->data;
  377. memcpy(datap, &eth_hdr, sizeof(eth_hdr));
  378. return 0;
  379. }
  380. /*
  381. * Performs 802.3 to DIX encapsulation for received packets.
  382. * Assumes the entire 802.3 header is contiguous.
  383. */
  384. int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
  385. {
  386. struct ath6kl_llc_snap_hdr *llc_hdr;
  387. struct ethhdr eth_hdr;
  388. u8 *datap;
  389. if (WARN_ON(skb == NULL))
  390. return -EINVAL;
  391. datap = skb->data;
  392. memcpy(&eth_hdr, datap, sizeof(eth_hdr));
  393. llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
  394. eth_hdr.h_proto = llc_hdr->eth_type;
  395. skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
  396. datap = skb->data;
  397. memcpy(datap, &eth_hdr, sizeof(eth_hdr));
  398. return 0;
  399. }
  400. static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
  401. {
  402. struct tx_complete_msg_v1 *msg_v1;
  403. struct wmi_tx_complete_event *evt;
  404. int index;
  405. u16 size;
  406. evt = (struct wmi_tx_complete_event *) datap;
  407. ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
  408. evt->num_msg, evt->msg_len, evt->msg_type);
  409. for (index = 0; index < evt->num_msg; index++) {
  410. size = sizeof(struct wmi_tx_complete_event) +
  411. (index * sizeof(struct tx_complete_msg_v1));
  412. msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
  413. ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
  414. msg_v1->status, msg_v1->pkt_id,
  415. msg_v1->rate_idx, msg_v1->ack_failures);
  416. }
  417. return 0;
  418. }
  419. static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
  420. int len, struct ath6kl_vif *vif)
  421. {
  422. struct wmi_remain_on_chnl_event *ev;
  423. u32 freq;
  424. u32 dur;
  425. struct ieee80211_channel *chan;
  426. struct ath6kl *ar = wmi->parent_dev;
  427. u32 id;
  428. if (len < sizeof(*ev))
  429. return -EINVAL;
  430. ev = (struct wmi_remain_on_chnl_event *) datap;
  431. freq = le32_to_cpu(ev->freq);
  432. dur = le32_to_cpu(ev->duration);
  433. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
  434. freq, dur);
  435. chan = ieee80211_get_channel(ar->wiphy, freq);
  436. if (!chan) {
  437. ath6kl_dbg(ATH6KL_DBG_WMI,
  438. "remain_on_chnl: Unknown channel (freq=%u)\n",
  439. freq);
  440. return -EINVAL;
  441. }
  442. id = vif->last_roc_id;
  443. cfg80211_ready_on_channel(&vif->wdev, id, chan,
  444. dur, GFP_ATOMIC);
  445. return 0;
  446. }
  447. static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
  448. u8 *datap, int len,
  449. struct ath6kl_vif *vif)
  450. {
  451. struct wmi_cancel_remain_on_chnl_event *ev;
  452. u32 freq;
  453. u32 dur;
  454. struct ieee80211_channel *chan;
  455. struct ath6kl *ar = wmi->parent_dev;
  456. u32 id;
  457. if (len < sizeof(*ev))
  458. return -EINVAL;
  459. ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
  460. freq = le32_to_cpu(ev->freq);
  461. dur = le32_to_cpu(ev->duration);
  462. ath6kl_dbg(ATH6KL_DBG_WMI,
  463. "cancel_remain_on_chnl: freq=%u dur=%u status=%u\n",
  464. freq, dur, ev->status);
  465. chan = ieee80211_get_channel(ar->wiphy, freq);
  466. if (!chan) {
  467. ath6kl_dbg(ATH6KL_DBG_WMI,
  468. "cancel_remain_on_chnl: Unknown channel (freq=%u)\n",
  469. freq);
  470. return -EINVAL;
  471. }
  472. if (vif->last_cancel_roc_id &&
  473. vif->last_cancel_roc_id + 1 == vif->last_roc_id)
  474. id = vif->last_cancel_roc_id; /* event for cancel command */
  475. else
  476. id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
  477. vif->last_cancel_roc_id = 0;
  478. cfg80211_remain_on_channel_expired(&vif->wdev, id, chan, GFP_ATOMIC);
  479. return 0;
  480. }
  481. static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
  482. struct ath6kl_vif *vif)
  483. {
  484. struct wmi_tx_status_event *ev;
  485. u32 id;
  486. if (len < sizeof(*ev))
  487. return -EINVAL;
  488. ev = (struct wmi_tx_status_event *) datap;
  489. id = le32_to_cpu(ev->id);
  490. ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
  491. id, ev->ack_status);
  492. if (wmi->last_mgmt_tx_frame) {
  493. cfg80211_mgmt_tx_status(&vif->wdev, id,
  494. wmi->last_mgmt_tx_frame,
  495. wmi->last_mgmt_tx_frame_len,
  496. !!ev->ack_status, GFP_ATOMIC);
  497. kfree(wmi->last_mgmt_tx_frame);
  498. wmi->last_mgmt_tx_frame = NULL;
  499. wmi->last_mgmt_tx_frame_len = 0;
  500. }
  501. return 0;
  502. }
  503. static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  504. struct ath6kl_vif *vif)
  505. {
  506. struct wmi_p2p_rx_probe_req_event *ev;
  507. u32 freq;
  508. u16 dlen;
  509. if (len < sizeof(*ev))
  510. return -EINVAL;
  511. ev = (struct wmi_p2p_rx_probe_req_event *) datap;
  512. freq = le32_to_cpu(ev->freq);
  513. dlen = le16_to_cpu(ev->len);
  514. if (datap + len < ev->data + dlen) {
  515. ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n",
  516. len, dlen);
  517. return -EINVAL;
  518. }
  519. ath6kl_dbg(ATH6KL_DBG_WMI,
  520. "rx_probe_req: len=%u freq=%u probe_req_report=%d\n",
  521. dlen, freq, vif->probe_req_report);
  522. if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
  523. cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
  524. return 0;
  525. }
  526. static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
  527. {
  528. struct wmi_p2p_capabilities_event *ev;
  529. u16 dlen;
  530. if (len < sizeof(*ev))
  531. return -EINVAL;
  532. ev = (struct wmi_p2p_capabilities_event *) datap;
  533. dlen = le16_to_cpu(ev->len);
  534. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
  535. return 0;
  536. }
  537. static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
  538. struct ath6kl_vif *vif)
  539. {
  540. struct wmi_rx_action_event *ev;
  541. u32 freq;
  542. u16 dlen;
  543. if (len < sizeof(*ev))
  544. return -EINVAL;
  545. ev = (struct wmi_rx_action_event *) datap;
  546. freq = le32_to_cpu(ev->freq);
  547. dlen = le16_to_cpu(ev->len);
  548. if (datap + len < ev->data + dlen) {
  549. ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n",
  550. len, dlen);
  551. return -EINVAL;
  552. }
  553. ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
  554. cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
  555. return 0;
  556. }
  557. static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
  558. {
  559. struct wmi_p2p_info_event *ev;
  560. u32 flags;
  561. u16 dlen;
  562. if (len < sizeof(*ev))
  563. return -EINVAL;
  564. ev = (struct wmi_p2p_info_event *) datap;
  565. flags = le32_to_cpu(ev->info_req_flags);
  566. dlen = le16_to_cpu(ev->len);
  567. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
  568. if (flags & P2P_FLAG_CAPABILITIES_REQ) {
  569. struct wmi_p2p_capabilities *cap;
  570. if (dlen < sizeof(*cap))
  571. return -EINVAL;
  572. cap = (struct wmi_p2p_capabilities *) ev->data;
  573. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
  574. cap->go_power_save);
  575. }
  576. if (flags & P2P_FLAG_MACADDR_REQ) {
  577. struct wmi_p2p_macaddr *mac;
  578. if (dlen < sizeof(*mac))
  579. return -EINVAL;
  580. mac = (struct wmi_p2p_macaddr *) ev->data;
  581. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
  582. mac->mac_addr);
  583. }
  584. if (flags & P2P_FLAG_HMODEL_REQ) {
  585. struct wmi_p2p_hmodel *mod;
  586. if (dlen < sizeof(*mod))
  587. return -EINVAL;
  588. mod = (struct wmi_p2p_hmodel *) ev->data;
  589. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
  590. mod->p2p_model,
  591. mod->p2p_model ? "host" : "firmware");
  592. }
  593. return 0;
  594. }
  595. static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
  596. {
  597. struct sk_buff *skb;
  598. skb = ath6kl_buf_alloc(size);
  599. if (!skb)
  600. return NULL;
  601. skb_put(skb, size);
  602. if (size)
  603. memset(skb->data, 0, size);
  604. return skb;
  605. }
  606. /* Send a "simple" wmi command -- one with no arguments */
  607. static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
  608. enum wmi_cmd_id cmd_id)
  609. {
  610. struct sk_buff *skb;
  611. int ret;
  612. skb = ath6kl_wmi_get_new_buf(0);
  613. if (!skb)
  614. return -ENOMEM;
  615. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
  616. return ret;
  617. }
  618. static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
  619. {
  620. struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
  621. if (len < sizeof(struct wmi_ready_event_2))
  622. return -EINVAL;
  623. ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
  624. le32_to_cpu(ev->sw_version),
  625. le32_to_cpu(ev->abi_version), ev->phy_cap);
  626. return 0;
  627. }
  628. /*
  629. * Mechanism to modify the roaming behavior in the firmware. The lower rssi
  630. * at which the station has to roam can be passed with
  631. * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
  632. * in dBm.
  633. */
  634. int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
  635. {
  636. struct sk_buff *skb;
  637. struct roam_ctrl_cmd *cmd;
  638. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  639. if (!skb)
  640. return -ENOMEM;
  641. cmd = (struct roam_ctrl_cmd *) skb->data;
  642. cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
  643. cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
  644. DEF_SCAN_FOR_ROAM_INTVL);
  645. cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
  646. cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
  647. cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
  648. ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  649. NO_SYNC_WMIFLAG);
  650. return 0;
  651. }
  652. int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
  653. {
  654. struct sk_buff *skb;
  655. struct roam_ctrl_cmd *cmd;
  656. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  657. if (!skb)
  658. return -ENOMEM;
  659. cmd = (struct roam_ctrl_cmd *) skb->data;
  660. memcpy(cmd->info.bssid, bssid, ETH_ALEN);
  661. cmd->roam_ctrl = WMI_FORCE_ROAM;
  662. ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
  663. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  664. NO_SYNC_WMIFLAG);
  665. }
  666. int ath6kl_wmi_ap_set_beacon_intvl_cmd(struct wmi *wmi, u8 if_idx,
  667. u32 beacon_intvl)
  668. {
  669. struct sk_buff *skb;
  670. struct set_beacon_int_cmd *cmd;
  671. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  672. if (!skb)
  673. return -ENOMEM;
  674. cmd = (struct set_beacon_int_cmd *) skb->data;
  675. cmd->beacon_intvl = cpu_to_le32(beacon_intvl);
  676. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  677. WMI_SET_BEACON_INT_CMDID, NO_SYNC_WMIFLAG);
  678. }
  679. int ath6kl_wmi_ap_set_dtim_cmd(struct wmi *wmi, u8 if_idx, u32 dtim_period)
  680. {
  681. struct sk_buff *skb;
  682. struct set_dtim_cmd *cmd;
  683. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  684. if (!skb)
  685. return -ENOMEM;
  686. cmd = (struct set_dtim_cmd *) skb->data;
  687. cmd->dtim_period = cpu_to_le32(dtim_period);
  688. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  689. WMI_AP_SET_DTIM_CMDID, NO_SYNC_WMIFLAG);
  690. }
  691. int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
  692. {
  693. struct sk_buff *skb;
  694. struct roam_ctrl_cmd *cmd;
  695. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  696. if (!skb)
  697. return -ENOMEM;
  698. cmd = (struct roam_ctrl_cmd *) skb->data;
  699. cmd->info.roam_mode = mode;
  700. cmd->roam_ctrl = WMI_SET_ROAM_MODE;
  701. ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
  702. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  703. NO_SYNC_WMIFLAG);
  704. }
  705. static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
  706. struct ath6kl_vif *vif)
  707. {
  708. struct wmi_connect_event *ev;
  709. u8 *pie, *peie;
  710. if (len < sizeof(struct wmi_connect_event))
  711. return -EINVAL;
  712. ev = (struct wmi_connect_event *) datap;
  713. if (vif->nw_type == AP_NETWORK) {
  714. /* AP mode start/STA connected event */
  715. struct net_device *dev = vif->ndev;
  716. if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
  717. ath6kl_dbg(ATH6KL_DBG_WMI,
  718. "%s: freq %d bssid %pM (AP started)\n",
  719. __func__, le16_to_cpu(ev->u.ap_bss.ch),
  720. ev->u.ap_bss.bssid);
  721. ath6kl_connect_ap_mode_bss(
  722. vif, le16_to_cpu(ev->u.ap_bss.ch));
  723. } else {
  724. ath6kl_dbg(ATH6KL_DBG_WMI,
  725. "%s: aid %u mac_addr %pM auth=%u keymgmt=%u cipher=%u apsd_info=%u (STA connected)\n",
  726. __func__, ev->u.ap_sta.aid,
  727. ev->u.ap_sta.mac_addr,
  728. ev->u.ap_sta.auth,
  729. ev->u.ap_sta.keymgmt,
  730. le16_to_cpu(ev->u.ap_sta.cipher),
  731. ev->u.ap_sta.apsd_info);
  732. ath6kl_connect_ap_mode_sta(
  733. vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
  734. ev->u.ap_sta.keymgmt,
  735. le16_to_cpu(ev->u.ap_sta.cipher),
  736. ev->u.ap_sta.auth, ev->assoc_req_len,
  737. ev->assoc_info + ev->beacon_ie_len,
  738. ev->u.ap_sta.apsd_info);
  739. }
  740. return 0;
  741. }
  742. /* STA/IBSS mode connection event */
  743. ath6kl_dbg(ATH6KL_DBG_WMI,
  744. "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
  745. le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
  746. le16_to_cpu(ev->u.sta.listen_intvl),
  747. le16_to_cpu(ev->u.sta.beacon_intvl),
  748. le32_to_cpu(ev->u.sta.nw_type));
  749. /* Start of assoc rsp IEs */
  750. pie = ev->assoc_info + ev->beacon_ie_len +
  751. ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
  752. /* End of assoc rsp IEs */
  753. peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
  754. ev->assoc_resp_len;
  755. while (pie < peie) {
  756. switch (*pie) {
  757. case WLAN_EID_VENDOR_SPECIFIC:
  758. if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
  759. pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
  760. /* WMM OUT (00:50:F2) */
  761. if (pie[1] > 5 &&
  762. pie[6] == WMM_PARAM_OUI_SUBTYPE)
  763. wmi->is_wmm_enabled = true;
  764. }
  765. break;
  766. }
  767. if (wmi->is_wmm_enabled)
  768. break;
  769. pie += pie[1] + 2;
  770. }
  771. ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
  772. ev->u.sta.bssid,
  773. le16_to_cpu(ev->u.sta.listen_intvl),
  774. le16_to_cpu(ev->u.sta.beacon_intvl),
  775. le32_to_cpu(ev->u.sta.nw_type),
  776. ev->beacon_ie_len, ev->assoc_req_len,
  777. ev->assoc_resp_len, ev->assoc_info);
  778. return 0;
  779. }
  780. static struct country_code_to_enum_rd *
  781. ath6kl_regd_find_country(u16 countryCode)
  782. {
  783. int i;
  784. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  785. if (allCountries[i].countryCode == countryCode)
  786. return &allCountries[i];
  787. }
  788. return NULL;
  789. }
  790. static struct reg_dmn_pair_mapping *
  791. ath6kl_get_regpair(u16 regdmn)
  792. {
  793. int i;
  794. if (regdmn == NO_ENUMRD)
  795. return NULL;
  796. for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
  797. if (regDomainPairs[i].reg_domain == regdmn)
  798. return &regDomainPairs[i];
  799. }
  800. return NULL;
  801. }
  802. static struct country_code_to_enum_rd *
  803. ath6kl_regd_find_country_by_rd(u16 regdmn)
  804. {
  805. int i;
  806. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  807. if (allCountries[i].regDmnEnum == regdmn)
  808. return &allCountries[i];
  809. }
  810. return NULL;
  811. }
  812. static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
  813. {
  814. struct ath6kl_wmi_regdomain *ev;
  815. struct country_code_to_enum_rd *country = NULL;
  816. struct reg_dmn_pair_mapping *regpair = NULL;
  817. char alpha2[2];
  818. u32 reg_code;
  819. ev = (struct ath6kl_wmi_regdomain *) datap;
  820. reg_code = le32_to_cpu(ev->reg_code);
  821. if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG) {
  822. country = ath6kl_regd_find_country((u16) reg_code);
  823. } else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
  824. regpair = ath6kl_get_regpair((u16) reg_code);
  825. country = ath6kl_regd_find_country_by_rd((u16) reg_code);
  826. if (regpair)
  827. ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
  828. regpair->reg_domain);
  829. else
  830. ath6kl_warn("Regpair not found reg_code 0x%0x\n",
  831. reg_code);
  832. }
  833. if (country && wmi->parent_dev->wiphy_registered) {
  834. alpha2[0] = country->isoName[0];
  835. alpha2[1] = country->isoName[1];
  836. regulatory_hint(wmi->parent_dev->wiphy, alpha2);
  837. ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
  838. alpha2[0], alpha2[1]);
  839. }
  840. }
  841. static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
  842. struct ath6kl_vif *vif)
  843. {
  844. struct wmi_disconnect_event *ev;
  845. wmi->traffic_class = 100;
  846. if (len < sizeof(struct wmi_disconnect_event))
  847. return -EINVAL;
  848. ev = (struct wmi_disconnect_event *) datap;
  849. ath6kl_dbg(ATH6KL_DBG_WMI,
  850. "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
  851. le16_to_cpu(ev->proto_reason_status), ev->bssid,
  852. ev->disconn_reason, ev->assoc_resp_len);
  853. wmi->is_wmm_enabled = false;
  854. ath6kl_disconnect_event(vif, ev->disconn_reason,
  855. ev->bssid, ev->assoc_resp_len, ev->assoc_info,
  856. le16_to_cpu(ev->proto_reason_status));
  857. return 0;
  858. }
  859. static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
  860. {
  861. struct wmi_peer_node_event *ev;
  862. if (len < sizeof(struct wmi_peer_node_event))
  863. return -EINVAL;
  864. ev = (struct wmi_peer_node_event *) datap;
  865. if (ev->event_code == PEER_NODE_JOIN_EVENT)
  866. ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
  867. ev->peer_mac_addr);
  868. else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
  869. ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
  870. ev->peer_mac_addr);
  871. return 0;
  872. }
  873. static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
  874. struct ath6kl_vif *vif)
  875. {
  876. struct wmi_tkip_micerr_event *ev;
  877. if (len < sizeof(struct wmi_tkip_micerr_event))
  878. return -EINVAL;
  879. ev = (struct wmi_tkip_micerr_event *) datap;
  880. ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
  881. return 0;
  882. }
  883. void ath6kl_wmi_sscan_timer(unsigned long ptr)
  884. {
  885. struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
  886. cfg80211_sched_scan_results(vif->ar->wiphy);
  887. }
  888. static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
  889. struct ath6kl_vif *vif)
  890. {
  891. struct wmi_bss_info_hdr2 *bih;
  892. u8 *buf;
  893. struct ieee80211_channel *channel;
  894. struct ath6kl *ar = wmi->parent_dev;
  895. struct cfg80211_bss *bss;
  896. if (len <= sizeof(struct wmi_bss_info_hdr2))
  897. return -EINVAL;
  898. bih = (struct wmi_bss_info_hdr2 *) datap;
  899. buf = datap + sizeof(struct wmi_bss_info_hdr2);
  900. len -= sizeof(struct wmi_bss_info_hdr2);
  901. ath6kl_dbg(ATH6KL_DBG_WMI,
  902. "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
  903. "frame_type=%d\n",
  904. bih->ch, bih->snr, bih->snr - 95, bih->bssid,
  905. bih->frame_type);
  906. if (bih->frame_type != BEACON_FTYPE &&
  907. bih->frame_type != PROBERESP_FTYPE)
  908. return 0; /* Only update BSS table for now */
  909. if (bih->frame_type == BEACON_FTYPE &&
  910. test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
  911. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  912. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  913. NONE_BSS_FILTER, 0);
  914. }
  915. channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
  916. if (channel == NULL)
  917. return -EINVAL;
  918. if (len < 8 + 2 + 2)
  919. return -EINVAL;
  920. if (bih->frame_type == BEACON_FTYPE &&
  921. test_bit(CONNECTED, &vif->flags) &&
  922. memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
  923. const u8 *tim;
  924. tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
  925. len - 8 - 2 - 2);
  926. if (tim && tim[1] >= 2) {
  927. vif->assoc_bss_dtim_period = tim[3];
  928. set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
  929. }
  930. }
  931. bss = cfg80211_inform_bss(ar->wiphy, channel,
  932. bih->frame_type == BEACON_FTYPE ?
  933. CFG80211_BSS_FTYPE_BEACON :
  934. CFG80211_BSS_FTYPE_PRESP,
  935. bih->bssid, get_unaligned_le64((__le64 *)buf),
  936. get_unaligned_le16(((__le16 *)buf) + 5),
  937. get_unaligned_le16(((__le16 *)buf) + 4),
  938. buf + 8 + 2 + 2, len - 8 - 2 - 2,
  939. (bih->snr - 95) * 100, GFP_ATOMIC);
  940. if (bss == NULL)
  941. return -ENOMEM;
  942. cfg80211_put_bss(ar->wiphy, bss);
  943. /*
  944. * Firmware doesn't return any event when scheduled scan has
  945. * finished, so we need to use a timer to find out when there are
  946. * no more results.
  947. *
  948. * The timer is started from the first bss info received, otherwise
  949. * the timer would not ever fire if the scan interval is short
  950. * enough.
  951. */
  952. if (test_bit(SCHED_SCANNING, &vif->flags) &&
  953. !timer_pending(&vif->sched_scan_timer)) {
  954. mod_timer(&vif->sched_scan_timer, jiffies +
  955. msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
  956. }
  957. return 0;
  958. }
  959. /* Inactivity timeout of a fatpipe(pstream) at the target */
  960. static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
  961. int len)
  962. {
  963. struct wmi_pstream_timeout_event *ev;
  964. if (len < sizeof(struct wmi_pstream_timeout_event))
  965. return -EINVAL;
  966. ev = (struct wmi_pstream_timeout_event *) datap;
  967. /*
  968. * When the pstream (fat pipe == AC) timesout, it means there were
  969. * no thinStreams within this pstream & it got implicitly created
  970. * due to data flow on this AC. We start the inactivity timer only
  971. * for implicitly created pstream. Just reset the host state.
  972. */
  973. spin_lock_bh(&wmi->lock);
  974. wmi->stream_exist_for_ac[ev->traffic_class] = 0;
  975. wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
  976. spin_unlock_bh(&wmi->lock);
  977. /* Indicate inactivity to driver layer for this fatpipe (pstream) */
  978. ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
  979. return 0;
  980. }
  981. static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
  982. {
  983. struct wmi_bit_rate_reply *reply;
  984. s32 rate;
  985. u32 sgi, index;
  986. if (len < sizeof(struct wmi_bit_rate_reply))
  987. return -EINVAL;
  988. reply = (struct wmi_bit_rate_reply *) datap;
  989. ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
  990. if (reply->rate_index == (s8) RATE_AUTO) {
  991. rate = RATE_AUTO;
  992. } else {
  993. index = reply->rate_index & 0x7f;
  994. if (WARN_ON_ONCE(index > (RATE_MCS_7_40 + 1)))
  995. return -EINVAL;
  996. sgi = (reply->rate_index & 0x80) ? 1 : 0;
  997. rate = wmi_rate_tbl[index][sgi];
  998. }
  999. ath6kl_wakeup_event(wmi->parent_dev);
  1000. return 0;
  1001. }
  1002. static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
  1003. {
  1004. ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
  1005. return 0;
  1006. }
  1007. static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1008. {
  1009. if (len < sizeof(struct wmi_fix_rates_reply))
  1010. return -EINVAL;
  1011. ath6kl_wakeup_event(wmi->parent_dev);
  1012. return 0;
  1013. }
  1014. static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1015. {
  1016. if (len < sizeof(struct wmi_channel_list_reply))
  1017. return -EINVAL;
  1018. ath6kl_wakeup_event(wmi->parent_dev);
  1019. return 0;
  1020. }
  1021. static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1022. {
  1023. struct wmi_tx_pwr_reply *reply;
  1024. if (len < sizeof(struct wmi_tx_pwr_reply))
  1025. return -EINVAL;
  1026. reply = (struct wmi_tx_pwr_reply *) datap;
  1027. ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
  1028. return 0;
  1029. }
  1030. static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1031. {
  1032. if (len < sizeof(struct wmi_get_keepalive_cmd))
  1033. return -EINVAL;
  1034. ath6kl_wakeup_event(wmi->parent_dev);
  1035. return 0;
  1036. }
  1037. static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
  1038. struct ath6kl_vif *vif)
  1039. {
  1040. struct wmi_scan_complete_event *ev;
  1041. ev = (struct wmi_scan_complete_event *) datap;
  1042. ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
  1043. wmi->is_probe_ssid = false;
  1044. return 0;
  1045. }
  1046. static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
  1047. int len, struct ath6kl_vif *vif)
  1048. {
  1049. struct wmi_neighbor_report_event *ev;
  1050. u8 i;
  1051. if (len < sizeof(*ev))
  1052. return -EINVAL;
  1053. ev = (struct wmi_neighbor_report_event *) datap;
  1054. if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
  1055. > len) {
  1056. ath6kl_dbg(ATH6KL_DBG_WMI,
  1057. "truncated neighbor event (num=%d len=%d)\n",
  1058. ev->num_neighbors, len);
  1059. return -EINVAL;
  1060. }
  1061. for (i = 0; i < ev->num_neighbors; i++) {
  1062. ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
  1063. i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
  1064. ev->neighbor[i].bss_flags);
  1065. cfg80211_pmksa_candidate_notify(vif->ndev, i,
  1066. ev->neighbor[i].bssid,
  1067. !!(ev->neighbor[i].bss_flags &
  1068. WMI_PREAUTH_CAPABLE_BSS),
  1069. GFP_ATOMIC);
  1070. }
  1071. return 0;
  1072. }
  1073. /*
  1074. * Target is reporting a programming error. This is for
  1075. * developer aid only. Target only checks a few common violations
  1076. * and it is responsibility of host to do all error checking.
  1077. * Behavior of target after wmi error event is undefined.
  1078. * A reset is recommended.
  1079. */
  1080. static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
  1081. {
  1082. const char *type = "unknown error";
  1083. struct wmi_cmd_error_event *ev;
  1084. ev = (struct wmi_cmd_error_event *) datap;
  1085. switch (ev->err_code) {
  1086. case INVALID_PARAM:
  1087. type = "invalid parameter";
  1088. break;
  1089. case ILLEGAL_STATE:
  1090. type = "invalid state";
  1091. break;
  1092. case INTERNAL_ERROR:
  1093. type = "internal error";
  1094. break;
  1095. }
  1096. ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
  1097. ev->cmd_id, type);
  1098. return 0;
  1099. }
  1100. static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
  1101. struct ath6kl_vif *vif)
  1102. {
  1103. ath6kl_tgt_stats_event(vif, datap, len);
  1104. return 0;
  1105. }
  1106. static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
  1107. struct sq_threshold_params *sq_thresh,
  1108. u32 size)
  1109. {
  1110. u32 index;
  1111. u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
  1112. /* The list is already in sorted order. Get the next lower value */
  1113. for (index = 0; index < size; index++) {
  1114. if (rssi < sq_thresh->upper_threshold[index]) {
  1115. threshold = (u8) sq_thresh->upper_threshold[index];
  1116. break;
  1117. }
  1118. }
  1119. return threshold;
  1120. }
  1121. static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
  1122. struct sq_threshold_params *sq_thresh,
  1123. u32 size)
  1124. {
  1125. u32 index;
  1126. u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
  1127. /* The list is already in sorted order. Get the next lower value */
  1128. for (index = 0; index < size; index++) {
  1129. if (rssi > sq_thresh->lower_threshold[index]) {
  1130. threshold = (u8) sq_thresh->lower_threshold[index];
  1131. break;
  1132. }
  1133. }
  1134. return threshold;
  1135. }
  1136. static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
  1137. struct wmi_rssi_threshold_params_cmd *rssi_cmd)
  1138. {
  1139. struct sk_buff *skb;
  1140. struct wmi_rssi_threshold_params_cmd *cmd;
  1141. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1142. if (!skb)
  1143. return -ENOMEM;
  1144. cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
  1145. memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
  1146. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
  1147. NO_SYNC_WMIFLAG);
  1148. }
  1149. static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
  1150. int len)
  1151. {
  1152. struct wmi_rssi_threshold_event *reply;
  1153. struct wmi_rssi_threshold_params_cmd cmd;
  1154. struct sq_threshold_params *sq_thresh;
  1155. enum wmi_rssi_threshold_val new_threshold;
  1156. u8 upper_rssi_threshold, lower_rssi_threshold;
  1157. s16 rssi;
  1158. int ret;
  1159. if (len < sizeof(struct wmi_rssi_threshold_event))
  1160. return -EINVAL;
  1161. reply = (struct wmi_rssi_threshold_event *) datap;
  1162. new_threshold = (enum wmi_rssi_threshold_val) reply->range;
  1163. rssi = a_sle16_to_cpu(reply->rssi);
  1164. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
  1165. /*
  1166. * Identify the threshold breached and communicate that to the app.
  1167. * After that install a new set of thresholds based on the signal
  1168. * quality reported by the target
  1169. */
  1170. if (new_threshold) {
  1171. /* Upper threshold breached */
  1172. if (rssi < sq_thresh->upper_threshold[0]) {
  1173. ath6kl_dbg(ATH6KL_DBG_WMI,
  1174. "spurious upper rssi threshold event: %d\n",
  1175. rssi);
  1176. } else if ((rssi < sq_thresh->upper_threshold[1]) &&
  1177. (rssi >= sq_thresh->upper_threshold[0])) {
  1178. new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
  1179. } else if ((rssi < sq_thresh->upper_threshold[2]) &&
  1180. (rssi >= sq_thresh->upper_threshold[1])) {
  1181. new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
  1182. } else if ((rssi < sq_thresh->upper_threshold[3]) &&
  1183. (rssi >= sq_thresh->upper_threshold[2])) {
  1184. new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
  1185. } else if ((rssi < sq_thresh->upper_threshold[4]) &&
  1186. (rssi >= sq_thresh->upper_threshold[3])) {
  1187. new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
  1188. } else if ((rssi < sq_thresh->upper_threshold[5]) &&
  1189. (rssi >= sq_thresh->upper_threshold[4])) {
  1190. new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
  1191. } else if (rssi >= sq_thresh->upper_threshold[5]) {
  1192. new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
  1193. }
  1194. } else {
  1195. /* Lower threshold breached */
  1196. if (rssi > sq_thresh->lower_threshold[0]) {
  1197. ath6kl_dbg(ATH6KL_DBG_WMI,
  1198. "spurious lower rssi threshold event: %d %d\n",
  1199. rssi, sq_thresh->lower_threshold[0]);
  1200. } else if ((rssi > sq_thresh->lower_threshold[1]) &&
  1201. (rssi <= sq_thresh->lower_threshold[0])) {
  1202. new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
  1203. } else if ((rssi > sq_thresh->lower_threshold[2]) &&
  1204. (rssi <= sq_thresh->lower_threshold[1])) {
  1205. new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
  1206. } else if ((rssi > sq_thresh->lower_threshold[3]) &&
  1207. (rssi <= sq_thresh->lower_threshold[2])) {
  1208. new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
  1209. } else if ((rssi > sq_thresh->lower_threshold[4]) &&
  1210. (rssi <= sq_thresh->lower_threshold[3])) {
  1211. new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
  1212. } else if ((rssi > sq_thresh->lower_threshold[5]) &&
  1213. (rssi <= sq_thresh->lower_threshold[4])) {
  1214. new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
  1215. } else if (rssi <= sq_thresh->lower_threshold[5]) {
  1216. new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
  1217. }
  1218. }
  1219. /* Calculate and install the next set of thresholds */
  1220. lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
  1221. sq_thresh->lower_threshold_valid_count);
  1222. upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
  1223. sq_thresh->upper_threshold_valid_count);
  1224. /* Issue a wmi command to install the thresholds */
  1225. cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
  1226. cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
  1227. cmd.weight = sq_thresh->weight;
  1228. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1229. ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
  1230. if (ret) {
  1231. ath6kl_err("unable to configure rssi thresholds\n");
  1232. return -EIO;
  1233. }
  1234. return 0;
  1235. }
  1236. static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
  1237. struct ath6kl_vif *vif)
  1238. {
  1239. struct wmi_cac_event *reply;
  1240. struct ieee80211_tspec_ie *ts;
  1241. u16 active_tsids, tsinfo;
  1242. u8 tsid, index;
  1243. u8 ts_id;
  1244. if (len < sizeof(struct wmi_cac_event))
  1245. return -EINVAL;
  1246. reply = (struct wmi_cac_event *) datap;
  1247. if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
  1248. (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
  1249. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1250. tsinfo = le16_to_cpu(ts->tsinfo);
  1251. tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1252. IEEE80211_WMM_IE_TSPEC_TID_MASK;
  1253. ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
  1254. reply->ac, tsid);
  1255. } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
  1256. /*
  1257. * Following assumes that there is only one outstanding
  1258. * ADDTS request when this event is received
  1259. */
  1260. spin_lock_bh(&wmi->lock);
  1261. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1262. spin_unlock_bh(&wmi->lock);
  1263. for (index = 0; index < sizeof(active_tsids) * 8; index++) {
  1264. if ((active_tsids >> index) & 1)
  1265. break;
  1266. }
  1267. if (index < (sizeof(active_tsids) * 8))
  1268. ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
  1269. reply->ac, index);
  1270. }
  1271. /*
  1272. * Clear active tsids and Add missing handling
  1273. * for delete qos stream from AP
  1274. */
  1275. else if (reply->cac_indication == CAC_INDICATION_DELETE) {
  1276. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1277. tsinfo = le16_to_cpu(ts->tsinfo);
  1278. ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1279. IEEE80211_WMM_IE_TSPEC_TID_MASK);
  1280. spin_lock_bh(&wmi->lock);
  1281. wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
  1282. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1283. spin_unlock_bh(&wmi->lock);
  1284. /* Indicate stream inactivity to driver layer only if all tsids
  1285. * within this AC are deleted.
  1286. */
  1287. if (!active_tsids) {
  1288. ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
  1289. false);
  1290. wmi->fat_pipe_exist &= ~(1 << reply->ac);
  1291. }
  1292. }
  1293. return 0;
  1294. }
  1295. static int ath6kl_wmi_txe_notify_event_rx(struct wmi *wmi, u8 *datap, int len,
  1296. struct ath6kl_vif *vif)
  1297. {
  1298. struct wmi_txe_notify_event *ev;
  1299. u32 rate, pkts;
  1300. if (len < sizeof(*ev))
  1301. return -EINVAL;
  1302. if (vif->nw_type != INFRA_NETWORK ||
  1303. !test_bit(ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY,
  1304. vif->ar->fw_capabilities))
  1305. return -EOPNOTSUPP;
  1306. if (vif->sme_state != SME_CONNECTED)
  1307. return -ENOTCONN;
  1308. ev = (struct wmi_txe_notify_event *) datap;
  1309. rate = le32_to_cpu(ev->rate);
  1310. pkts = le32_to_cpu(ev->pkts);
  1311. ath6kl_dbg(ATH6KL_DBG_WMI, "TXE notify event: peer %pM rate %d% pkts %d intvl %ds\n",
  1312. vif->bssid, rate, pkts, vif->txe_intvl);
  1313. cfg80211_cqm_txe_notify(vif->ndev, vif->bssid, pkts,
  1314. rate, vif->txe_intvl, GFP_KERNEL);
  1315. return 0;
  1316. }
  1317. int ath6kl_wmi_set_txe_notify(struct wmi *wmi, u8 idx,
  1318. u32 rate, u32 pkts, u32 intvl)
  1319. {
  1320. struct sk_buff *skb;
  1321. struct wmi_txe_notify_cmd *cmd;
  1322. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1323. if (!skb)
  1324. return -ENOMEM;
  1325. cmd = (struct wmi_txe_notify_cmd *) skb->data;
  1326. cmd->rate = cpu_to_le32(rate);
  1327. cmd->pkts = cpu_to_le32(pkts);
  1328. cmd->intvl = cpu_to_le32(intvl);
  1329. return ath6kl_wmi_cmd_send(wmi, idx, skb, WMI_SET_TXE_NOTIFY_CMDID,
  1330. NO_SYNC_WMIFLAG);
  1331. }
  1332. int ath6kl_wmi_set_rssi_filter_cmd(struct wmi *wmi, u8 if_idx, s8 rssi)
  1333. {
  1334. struct sk_buff *skb;
  1335. struct wmi_set_rssi_filter_cmd *cmd;
  1336. int ret;
  1337. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1338. if (!skb)
  1339. return -ENOMEM;
  1340. cmd = (struct wmi_set_rssi_filter_cmd *) skb->data;
  1341. cmd->rssi = rssi;
  1342. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_RSSI_FILTER_CMDID,
  1343. NO_SYNC_WMIFLAG);
  1344. return ret;
  1345. }
  1346. static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
  1347. struct wmi_snr_threshold_params_cmd *snr_cmd)
  1348. {
  1349. struct sk_buff *skb;
  1350. struct wmi_snr_threshold_params_cmd *cmd;
  1351. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1352. if (!skb)
  1353. return -ENOMEM;
  1354. cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
  1355. memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
  1356. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
  1357. NO_SYNC_WMIFLAG);
  1358. }
  1359. static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
  1360. int len)
  1361. {
  1362. struct wmi_snr_threshold_event *reply;
  1363. struct sq_threshold_params *sq_thresh;
  1364. struct wmi_snr_threshold_params_cmd cmd;
  1365. enum wmi_snr_threshold_val new_threshold;
  1366. u8 upper_snr_threshold, lower_snr_threshold;
  1367. s16 snr;
  1368. int ret;
  1369. if (len < sizeof(struct wmi_snr_threshold_event))
  1370. return -EINVAL;
  1371. reply = (struct wmi_snr_threshold_event *) datap;
  1372. new_threshold = (enum wmi_snr_threshold_val) reply->range;
  1373. snr = reply->snr;
  1374. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
  1375. /*
  1376. * Identify the threshold breached and communicate that to the app.
  1377. * After that install a new set of thresholds based on the signal
  1378. * quality reported by the target.
  1379. */
  1380. if (new_threshold) {
  1381. /* Upper threshold breached */
  1382. if (snr < sq_thresh->upper_threshold[0]) {
  1383. ath6kl_dbg(ATH6KL_DBG_WMI,
  1384. "spurious upper snr threshold event: %d\n",
  1385. snr);
  1386. } else if ((snr < sq_thresh->upper_threshold[1]) &&
  1387. (snr >= sq_thresh->upper_threshold[0])) {
  1388. new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
  1389. } else if ((snr < sq_thresh->upper_threshold[2]) &&
  1390. (snr >= sq_thresh->upper_threshold[1])) {
  1391. new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
  1392. } else if ((snr < sq_thresh->upper_threshold[3]) &&
  1393. (snr >= sq_thresh->upper_threshold[2])) {
  1394. new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
  1395. } else if (snr >= sq_thresh->upper_threshold[3]) {
  1396. new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
  1397. }
  1398. } else {
  1399. /* Lower threshold breached */
  1400. if (snr > sq_thresh->lower_threshold[0]) {
  1401. ath6kl_dbg(ATH6KL_DBG_WMI,
  1402. "spurious lower snr threshold event: %d\n",
  1403. sq_thresh->lower_threshold[0]);
  1404. } else if ((snr > sq_thresh->lower_threshold[1]) &&
  1405. (snr <= sq_thresh->lower_threshold[0])) {
  1406. new_threshold = WMI_SNR_THRESHOLD4_BELOW;
  1407. } else if ((snr > sq_thresh->lower_threshold[2]) &&
  1408. (snr <= sq_thresh->lower_threshold[1])) {
  1409. new_threshold = WMI_SNR_THRESHOLD3_BELOW;
  1410. } else if ((snr > sq_thresh->lower_threshold[3]) &&
  1411. (snr <= sq_thresh->lower_threshold[2])) {
  1412. new_threshold = WMI_SNR_THRESHOLD2_BELOW;
  1413. } else if (snr <= sq_thresh->lower_threshold[3]) {
  1414. new_threshold = WMI_SNR_THRESHOLD1_BELOW;
  1415. }
  1416. }
  1417. /* Calculate and install the next set of thresholds */
  1418. lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
  1419. sq_thresh->lower_threshold_valid_count);
  1420. upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
  1421. sq_thresh->upper_threshold_valid_count);
  1422. /* Issue a wmi command to install the thresholds */
  1423. cmd.thresh_above1_val = upper_snr_threshold;
  1424. cmd.thresh_below1_val = lower_snr_threshold;
  1425. cmd.weight = sq_thresh->weight;
  1426. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1427. ath6kl_dbg(ATH6KL_DBG_WMI,
  1428. "snr: %d, threshold: %d, lower: %d, upper: %d\n",
  1429. snr, new_threshold,
  1430. lower_snr_threshold, upper_snr_threshold);
  1431. ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
  1432. if (ret) {
  1433. ath6kl_err("unable to configure snr threshold\n");
  1434. return -EIO;
  1435. }
  1436. return 0;
  1437. }
  1438. static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
  1439. {
  1440. u16 ap_info_entry_size;
  1441. struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
  1442. struct wmi_ap_info_v1 *ap_info_v1;
  1443. u8 index;
  1444. if (len < sizeof(struct wmi_aplist_event) ||
  1445. ev->ap_list_ver != APLIST_VER1)
  1446. return -EINVAL;
  1447. ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
  1448. ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
  1449. ath6kl_dbg(ATH6KL_DBG_WMI,
  1450. "number of APs in aplist event: %d\n", ev->num_ap);
  1451. if (len < (int) (sizeof(struct wmi_aplist_event) +
  1452. (ev->num_ap - 1) * ap_info_entry_size))
  1453. return -EINVAL;
  1454. /* AP list version 1 contents */
  1455. for (index = 0; index < ev->num_ap; index++) {
  1456. ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
  1457. index, ap_info_v1->bssid, ap_info_v1->channel);
  1458. ap_info_v1++;
  1459. }
  1460. return 0;
  1461. }
  1462. int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
  1463. enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
  1464. {
  1465. struct wmi_cmd_hdr *cmd_hdr;
  1466. enum htc_endpoint_id ep_id = wmi->ep_id;
  1467. int ret;
  1468. u16 info1;
  1469. if (WARN_ON(skb == NULL ||
  1470. (if_idx > (wmi->parent_dev->vif_max - 1)))) {
  1471. dev_kfree_skb(skb);
  1472. return -EINVAL;
  1473. }
  1474. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
  1475. cmd_id, skb->len, sync_flag);
  1476. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
  1477. skb->data, skb->len);
  1478. if (sync_flag >= END_WMIFLAG) {
  1479. dev_kfree_skb(skb);
  1480. return -EINVAL;
  1481. }
  1482. if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
  1483. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1484. /*
  1485. * Make sure all data currently queued is transmitted before
  1486. * the cmd execution. Establish a new sync point.
  1487. */
  1488. ath6kl_wmi_sync_point(wmi, if_idx);
  1489. }
  1490. skb_push(skb, sizeof(struct wmi_cmd_hdr));
  1491. cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
  1492. cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
  1493. info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
  1494. cmd_hdr->info1 = cpu_to_le16(info1);
  1495. /* Only for OPT_TX_CMD, use BE endpoint. */
  1496. if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
  1497. ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
  1498. false, false, 0, NULL, if_idx);
  1499. if (ret) {
  1500. dev_kfree_skb(skb);
  1501. return ret;
  1502. }
  1503. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
  1504. }
  1505. ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1506. if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
  1507. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1508. /*
  1509. * Make sure all new data queued waits for the command to
  1510. * execute. Establish a new sync point.
  1511. */
  1512. ath6kl_wmi_sync_point(wmi, if_idx);
  1513. }
  1514. return 0;
  1515. }
  1516. int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
  1517. enum network_type nw_type,
  1518. enum dot11_auth_mode dot11_auth_mode,
  1519. enum auth_mode auth_mode,
  1520. enum crypto_type pairwise_crypto,
  1521. u8 pairwise_crypto_len,
  1522. enum crypto_type group_crypto,
  1523. u8 group_crypto_len, int ssid_len, u8 *ssid,
  1524. u8 *bssid, u16 channel, u32 ctrl_flags,
  1525. u8 nw_subtype)
  1526. {
  1527. struct sk_buff *skb;
  1528. struct wmi_connect_cmd *cc;
  1529. int ret;
  1530. ath6kl_dbg(ATH6KL_DBG_WMI,
  1531. "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
  1532. "type %d dot11_auth %d auth %d pairwise %d group %d\n",
  1533. bssid, channel, ctrl_flags, ssid_len, nw_type,
  1534. dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
  1535. ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
  1536. wmi->traffic_class = 100;
  1537. if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
  1538. return -EINVAL;
  1539. if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
  1540. return -EINVAL;
  1541. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
  1542. if (!skb)
  1543. return -ENOMEM;
  1544. cc = (struct wmi_connect_cmd *) skb->data;
  1545. if (ssid_len)
  1546. memcpy(cc->ssid, ssid, ssid_len);
  1547. cc->ssid_len = ssid_len;
  1548. cc->nw_type = nw_type;
  1549. cc->dot11_auth_mode = dot11_auth_mode;
  1550. cc->auth_mode = auth_mode;
  1551. cc->prwise_crypto_type = pairwise_crypto;
  1552. cc->prwise_crypto_len = pairwise_crypto_len;
  1553. cc->grp_crypto_type = group_crypto;
  1554. cc->grp_crypto_len = group_crypto_len;
  1555. cc->ch = cpu_to_le16(channel);
  1556. cc->ctrl_flags = cpu_to_le32(ctrl_flags);
  1557. cc->nw_subtype = nw_subtype;
  1558. if (bssid != NULL)
  1559. memcpy(cc->bssid, bssid, ETH_ALEN);
  1560. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
  1561. NO_SYNC_WMIFLAG);
  1562. return ret;
  1563. }
  1564. int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
  1565. u16 channel)
  1566. {
  1567. struct sk_buff *skb;
  1568. struct wmi_reconnect_cmd *cc;
  1569. int ret;
  1570. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
  1571. bssid, channel);
  1572. wmi->traffic_class = 100;
  1573. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
  1574. if (!skb)
  1575. return -ENOMEM;
  1576. cc = (struct wmi_reconnect_cmd *) skb->data;
  1577. cc->channel = cpu_to_le16(channel);
  1578. if (bssid != NULL)
  1579. memcpy(cc->bssid, bssid, ETH_ALEN);
  1580. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
  1581. NO_SYNC_WMIFLAG);
  1582. return ret;
  1583. }
  1584. int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
  1585. {
  1586. int ret;
  1587. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
  1588. wmi->traffic_class = 100;
  1589. /* Disconnect command does not need to do a SYNC before. */
  1590. ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
  1591. return ret;
  1592. }
  1593. /* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
  1594. * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
  1595. * mgmt operations using station interface.
  1596. */
  1597. static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
  1598. enum wmi_scan_type scan_type,
  1599. u32 force_fgscan, u32 is_legacy,
  1600. u32 home_dwell_time,
  1601. u32 force_scan_interval,
  1602. s8 num_chan, u16 *ch_list)
  1603. {
  1604. struct sk_buff *skb;
  1605. struct wmi_start_scan_cmd *sc;
  1606. s8 size;
  1607. int i, ret;
  1608. size = sizeof(struct wmi_start_scan_cmd);
  1609. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1610. return -EINVAL;
  1611. if (num_chan > WMI_MAX_CHANNELS)
  1612. return -EINVAL;
  1613. if (num_chan)
  1614. size += sizeof(u16) * (num_chan - 1);
  1615. skb = ath6kl_wmi_get_new_buf(size);
  1616. if (!skb)
  1617. return -ENOMEM;
  1618. sc = (struct wmi_start_scan_cmd *) skb->data;
  1619. sc->scan_type = scan_type;
  1620. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1621. sc->is_legacy = cpu_to_le32(is_legacy);
  1622. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1623. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1624. sc->num_ch = num_chan;
  1625. for (i = 0; i < num_chan; i++)
  1626. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1627. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
  1628. NO_SYNC_WMIFLAG);
  1629. return ret;
  1630. }
  1631. /*
  1632. * beginscan supports (compared to old startscan) P2P mgmt operations using
  1633. * station interface, send additional information like supported rates to
  1634. * advertise and xmit rates for probe requests
  1635. */
  1636. int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
  1637. enum wmi_scan_type scan_type,
  1638. u32 force_fgscan, u32 is_legacy,
  1639. u32 home_dwell_time, u32 force_scan_interval,
  1640. s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
  1641. {
  1642. struct ieee80211_supported_band *sband;
  1643. struct sk_buff *skb;
  1644. struct wmi_begin_scan_cmd *sc;
  1645. s8 size, *supp_rates;
  1646. int i, band, ret;
  1647. struct ath6kl *ar = wmi->parent_dev;
  1648. int num_rates;
  1649. u32 ratemask;
  1650. if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  1651. ar->fw_capabilities)) {
  1652. return ath6kl_wmi_startscan_cmd(wmi, if_idx,
  1653. scan_type, force_fgscan,
  1654. is_legacy, home_dwell_time,
  1655. force_scan_interval,
  1656. num_chan, ch_list);
  1657. }
  1658. size = sizeof(struct wmi_begin_scan_cmd);
  1659. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1660. return -EINVAL;
  1661. if (num_chan > WMI_MAX_CHANNELS)
  1662. return -EINVAL;
  1663. if (num_chan)
  1664. size += sizeof(u16) * (num_chan - 1);
  1665. skb = ath6kl_wmi_get_new_buf(size);
  1666. if (!skb)
  1667. return -ENOMEM;
  1668. sc = (struct wmi_begin_scan_cmd *) skb->data;
  1669. sc->scan_type = scan_type;
  1670. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1671. sc->is_legacy = cpu_to_le32(is_legacy);
  1672. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1673. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1674. sc->no_cck = cpu_to_le32(no_cck);
  1675. sc->num_ch = num_chan;
  1676. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1677. sband = ar->wiphy->bands[band];
  1678. if (!sband)
  1679. continue;
  1680. if (WARN_ON(band >= ATH6KL_NUM_BANDS))
  1681. break;
  1682. ratemask = rates[band];
  1683. supp_rates = sc->supp_rates[band].rates;
  1684. num_rates = 0;
  1685. for (i = 0; i < sband->n_bitrates; i++) {
  1686. if ((BIT(i) & ratemask) == 0)
  1687. continue; /* skip rate */
  1688. supp_rates[num_rates++] =
  1689. (u8) (sband->bitrates[i].bitrate / 5);
  1690. }
  1691. sc->supp_rates[band].nrates = num_rates;
  1692. }
  1693. for (i = 0; i < num_chan; i++)
  1694. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1695. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
  1696. NO_SYNC_WMIFLAG);
  1697. return ret;
  1698. }
  1699. int ath6kl_wmi_enable_sched_scan_cmd(struct wmi *wmi, u8 if_idx, bool enable)
  1700. {
  1701. struct sk_buff *skb;
  1702. struct wmi_enable_sched_scan_cmd *sc;
  1703. int ret;
  1704. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1705. if (!skb)
  1706. return -ENOMEM;
  1707. ath6kl_dbg(ATH6KL_DBG_WMI, "%s scheduled scan on vif %d\n",
  1708. enable ? "enabling" : "disabling", if_idx);
  1709. sc = (struct wmi_enable_sched_scan_cmd *) skb->data;
  1710. sc->enable = enable ? 1 : 0;
  1711. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  1712. WMI_ENABLE_SCHED_SCAN_CMDID,
  1713. NO_SYNC_WMIFLAG);
  1714. return ret;
  1715. }
  1716. int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
  1717. u16 fg_start_sec,
  1718. u16 fg_end_sec, u16 bg_sec,
  1719. u16 minact_chdw_msec, u16 maxact_chdw_msec,
  1720. u16 pas_chdw_msec, u8 short_scan_ratio,
  1721. u8 scan_ctrl_flag, u32 max_dfsch_act_time,
  1722. u16 maxact_scan_per_ssid)
  1723. {
  1724. struct sk_buff *skb;
  1725. struct wmi_scan_params_cmd *sc;
  1726. int ret;
  1727. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1728. if (!skb)
  1729. return -ENOMEM;
  1730. sc = (struct wmi_scan_params_cmd *) skb->data;
  1731. sc->fg_start_period = cpu_to_le16(fg_start_sec);
  1732. sc->fg_end_period = cpu_to_le16(fg_end_sec);
  1733. sc->bg_period = cpu_to_le16(bg_sec);
  1734. sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
  1735. sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
  1736. sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
  1737. sc->short_scan_ratio = short_scan_ratio;
  1738. sc->scan_ctrl_flags = scan_ctrl_flag;
  1739. sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
  1740. sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
  1741. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
  1742. NO_SYNC_WMIFLAG);
  1743. return ret;
  1744. }
  1745. int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
  1746. {
  1747. struct sk_buff *skb;
  1748. struct wmi_bss_filter_cmd *cmd;
  1749. int ret;
  1750. if (filter >= LAST_BSS_FILTER)
  1751. return -EINVAL;
  1752. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1753. if (!skb)
  1754. return -ENOMEM;
  1755. cmd = (struct wmi_bss_filter_cmd *) skb->data;
  1756. cmd->bss_filter = filter;
  1757. cmd->ie_mask = cpu_to_le32(ie_mask);
  1758. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
  1759. NO_SYNC_WMIFLAG);
  1760. return ret;
  1761. }
  1762. int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
  1763. u8 ssid_len, u8 *ssid)
  1764. {
  1765. struct sk_buff *skb;
  1766. struct wmi_probed_ssid_cmd *cmd;
  1767. int ret;
  1768. if (index >= MAX_PROBED_SSIDS)
  1769. return -EINVAL;
  1770. if (ssid_len > sizeof(cmd->ssid))
  1771. return -EINVAL;
  1772. if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
  1773. return -EINVAL;
  1774. if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
  1775. return -EINVAL;
  1776. if (flag & SPECIFIC_SSID_FLAG)
  1777. wmi->is_probe_ssid = true;
  1778. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1779. if (!skb)
  1780. return -ENOMEM;
  1781. cmd = (struct wmi_probed_ssid_cmd *) skb->data;
  1782. cmd->entry_index = index;
  1783. cmd->flag = flag;
  1784. cmd->ssid_len = ssid_len;
  1785. memcpy(cmd->ssid, ssid, ssid_len);
  1786. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
  1787. NO_SYNC_WMIFLAG);
  1788. return ret;
  1789. }
  1790. int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
  1791. u16 listen_interval,
  1792. u16 listen_beacons)
  1793. {
  1794. struct sk_buff *skb;
  1795. struct wmi_listen_int_cmd *cmd;
  1796. int ret;
  1797. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1798. if (!skb)
  1799. return -ENOMEM;
  1800. cmd = (struct wmi_listen_int_cmd *) skb->data;
  1801. cmd->listen_intvl = cpu_to_le16(listen_interval);
  1802. cmd->num_beacons = cpu_to_le16(listen_beacons);
  1803. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
  1804. NO_SYNC_WMIFLAG);
  1805. return ret;
  1806. }
  1807. int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
  1808. u16 bmiss_time, u16 num_beacons)
  1809. {
  1810. struct sk_buff *skb;
  1811. struct wmi_bmiss_time_cmd *cmd;
  1812. int ret;
  1813. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1814. if (!skb)
  1815. return -ENOMEM;
  1816. cmd = (struct wmi_bmiss_time_cmd *) skb->data;
  1817. cmd->bmiss_time = cpu_to_le16(bmiss_time);
  1818. cmd->num_beacons = cpu_to_le16(num_beacons);
  1819. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
  1820. NO_SYNC_WMIFLAG);
  1821. return ret;
  1822. }
  1823. int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
  1824. {
  1825. struct sk_buff *skb;
  1826. struct wmi_power_mode_cmd *cmd;
  1827. int ret;
  1828. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1829. if (!skb)
  1830. return -ENOMEM;
  1831. cmd = (struct wmi_power_mode_cmd *) skb->data;
  1832. cmd->pwr_mode = pwr_mode;
  1833. wmi->pwr_mode = pwr_mode;
  1834. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
  1835. NO_SYNC_WMIFLAG);
  1836. return ret;
  1837. }
  1838. int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
  1839. u16 ps_poll_num, u16 dtim_policy,
  1840. u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
  1841. u16 ps_fail_event_policy)
  1842. {
  1843. struct sk_buff *skb;
  1844. struct wmi_power_params_cmd *pm;
  1845. int ret;
  1846. skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
  1847. if (!skb)
  1848. return -ENOMEM;
  1849. pm = (struct wmi_power_params_cmd *)skb->data;
  1850. pm->idle_period = cpu_to_le16(idle_period);
  1851. pm->pspoll_number = cpu_to_le16(ps_poll_num);
  1852. pm->dtim_policy = cpu_to_le16(dtim_policy);
  1853. pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
  1854. pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
  1855. pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
  1856. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
  1857. NO_SYNC_WMIFLAG);
  1858. return ret;
  1859. }
  1860. int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
  1861. {
  1862. struct sk_buff *skb;
  1863. struct wmi_disc_timeout_cmd *cmd;
  1864. int ret;
  1865. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1866. if (!skb)
  1867. return -ENOMEM;
  1868. cmd = (struct wmi_disc_timeout_cmd *) skb->data;
  1869. cmd->discon_timeout = timeout;
  1870. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
  1871. NO_SYNC_WMIFLAG);
  1872. if (ret == 0)
  1873. ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
  1874. return ret;
  1875. }
  1876. int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
  1877. enum crypto_type key_type,
  1878. u8 key_usage, u8 key_len,
  1879. u8 *key_rsc, unsigned int key_rsc_len,
  1880. u8 *key_material,
  1881. u8 key_op_ctrl, u8 *mac_addr,
  1882. enum wmi_sync_flag sync_flag)
  1883. {
  1884. struct sk_buff *skb;
  1885. struct wmi_add_cipher_key_cmd *cmd;
  1886. int ret;
  1887. ath6kl_dbg(ATH6KL_DBG_WMI,
  1888. "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n",
  1889. key_index, key_type, key_usage, key_len, key_op_ctrl);
  1890. if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
  1891. (key_material == NULL) || key_rsc_len > 8)
  1892. return -EINVAL;
  1893. if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
  1894. return -EINVAL;
  1895. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1896. if (!skb)
  1897. return -ENOMEM;
  1898. cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
  1899. cmd->key_index = key_index;
  1900. cmd->key_type = key_type;
  1901. cmd->key_usage = key_usage;
  1902. cmd->key_len = key_len;
  1903. memcpy(cmd->key, key_material, key_len);
  1904. if (key_rsc != NULL)
  1905. memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
  1906. cmd->key_op_ctrl = key_op_ctrl;
  1907. if (mac_addr)
  1908. memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
  1909. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
  1910. sync_flag);
  1911. return ret;
  1912. }
  1913. int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, const u8 *krk)
  1914. {
  1915. struct sk_buff *skb;
  1916. struct wmi_add_krk_cmd *cmd;
  1917. int ret;
  1918. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1919. if (!skb)
  1920. return -ENOMEM;
  1921. cmd = (struct wmi_add_krk_cmd *) skb->data;
  1922. memcpy(cmd->krk, krk, WMI_KRK_LEN);
  1923. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
  1924. NO_SYNC_WMIFLAG);
  1925. return ret;
  1926. }
  1927. int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
  1928. {
  1929. struct sk_buff *skb;
  1930. struct wmi_delete_cipher_key_cmd *cmd;
  1931. int ret;
  1932. if (key_index > WMI_MAX_KEY_INDEX)
  1933. return -EINVAL;
  1934. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1935. if (!skb)
  1936. return -ENOMEM;
  1937. cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
  1938. cmd->key_index = key_index;
  1939. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
  1940. NO_SYNC_WMIFLAG);
  1941. return ret;
  1942. }
  1943. int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
  1944. const u8 *pmkid, bool set)
  1945. {
  1946. struct sk_buff *skb;
  1947. struct wmi_setpmkid_cmd *cmd;
  1948. int ret;
  1949. if (bssid == NULL)
  1950. return -EINVAL;
  1951. if (set && pmkid == NULL)
  1952. return -EINVAL;
  1953. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1954. if (!skb)
  1955. return -ENOMEM;
  1956. cmd = (struct wmi_setpmkid_cmd *) skb->data;
  1957. memcpy(cmd->bssid, bssid, ETH_ALEN);
  1958. if (set) {
  1959. memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
  1960. cmd->enable = PMKID_ENABLE;
  1961. } else {
  1962. memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
  1963. cmd->enable = PMKID_DISABLE;
  1964. }
  1965. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
  1966. NO_SYNC_WMIFLAG);
  1967. return ret;
  1968. }
  1969. static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
  1970. enum htc_endpoint_id ep_id, u8 if_idx)
  1971. {
  1972. struct wmi_data_hdr *data_hdr;
  1973. int ret;
  1974. if (WARN_ON(skb == NULL || ep_id == wmi->ep_id)) {
  1975. dev_kfree_skb(skb);
  1976. return -EINVAL;
  1977. }
  1978. skb_push(skb, sizeof(struct wmi_data_hdr));
  1979. data_hdr = (struct wmi_data_hdr *) skb->data;
  1980. data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  1981. data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
  1982. ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1983. return ret;
  1984. }
  1985. static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
  1986. {
  1987. struct sk_buff *skb;
  1988. struct wmi_sync_cmd *cmd;
  1989. struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
  1990. enum htc_endpoint_id ep_id;
  1991. u8 index, num_pri_streams = 0;
  1992. int ret = 0;
  1993. memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
  1994. spin_lock_bh(&wmi->lock);
  1995. for (index = 0; index < WMM_NUM_AC; index++) {
  1996. if (wmi->fat_pipe_exist & (1 << index)) {
  1997. num_pri_streams++;
  1998. data_sync_bufs[num_pri_streams - 1].traffic_class =
  1999. index;
  2000. }
  2001. }
  2002. spin_unlock_bh(&wmi->lock);
  2003. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2004. if (!skb)
  2005. return -ENOMEM;
  2006. cmd = (struct wmi_sync_cmd *) skb->data;
  2007. /*
  2008. * In the SYNC cmd sent on the control Ep, send a bitmap
  2009. * of the data eps on which the Data Sync will be sent
  2010. */
  2011. cmd->data_sync_map = wmi->fat_pipe_exist;
  2012. for (index = 0; index < num_pri_streams; index++) {
  2013. data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
  2014. if (data_sync_bufs[index].skb == NULL) {
  2015. ret = -ENOMEM;
  2016. break;
  2017. }
  2018. }
  2019. /*
  2020. * If buffer allocation for any of the dataSync fails,
  2021. * then do not send the Synchronize cmd on the control ep
  2022. */
  2023. if (ret)
  2024. goto free_cmd_skb;
  2025. /*
  2026. * Send sync cmd followed by sync data messages on all
  2027. * endpoints being used
  2028. */
  2029. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
  2030. NO_SYNC_WMIFLAG);
  2031. if (ret)
  2032. goto free_data_skb;
  2033. for (index = 0; index < num_pri_streams; index++) {
  2034. if (WARN_ON(!data_sync_bufs[index].skb))
  2035. goto free_data_skb;
  2036. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
  2037. data_sync_bufs[index].
  2038. traffic_class);
  2039. ret =
  2040. ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
  2041. ep_id, if_idx);
  2042. data_sync_bufs[index].skb = NULL;
  2043. if (ret)
  2044. goto free_data_skb;
  2045. }
  2046. return 0;
  2047. free_cmd_skb:
  2048. /* free up any resources left over (possibly due to an error) */
  2049. dev_kfree_skb(skb);
  2050. free_data_skb:
  2051. for (index = 0; index < num_pri_streams; index++)
  2052. dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].skb);
  2053. return ret;
  2054. }
  2055. int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
  2056. struct wmi_create_pstream_cmd *params)
  2057. {
  2058. struct sk_buff *skb;
  2059. struct wmi_create_pstream_cmd *cmd;
  2060. u8 fatpipe_exist_for_ac = 0;
  2061. s32 min_phy = 0;
  2062. s32 nominal_phy = 0;
  2063. int ret;
  2064. if (!((params->user_pri <= 0x7) &&
  2065. (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
  2066. (params->traffic_direc == UPLINK_TRAFFIC ||
  2067. params->traffic_direc == DNLINK_TRAFFIC ||
  2068. params->traffic_direc == BIDIR_TRAFFIC) &&
  2069. (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
  2070. params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
  2071. (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
  2072. params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
  2073. params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
  2074. (params->tsid == WMI_IMPLICIT_PSTREAM ||
  2075. params->tsid <= WMI_MAX_THINSTREAM))) {
  2076. return -EINVAL;
  2077. }
  2078. /*
  2079. * Check nominal PHY rate is >= minimalPHY,
  2080. * so that DUT can allow TSRS IE
  2081. */
  2082. /* Get the physical rate (units of bps) */
  2083. min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
  2084. /* Check minimal phy < nominal phy rate */
  2085. if (params->nominal_phy >= min_phy) {
  2086. /* unit of 500 kbps */
  2087. nominal_phy = (params->nominal_phy * 1000) / 500;
  2088. ath6kl_dbg(ATH6KL_DBG_WMI,
  2089. "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
  2090. min_phy, nominal_phy);
  2091. params->nominal_phy = nominal_phy;
  2092. } else {
  2093. params->nominal_phy = 0;
  2094. }
  2095. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2096. if (!skb)
  2097. return -ENOMEM;
  2098. ath6kl_dbg(ATH6KL_DBG_WMI,
  2099. "sending create_pstream_cmd: ac=%d tsid:%d\n",
  2100. params->traffic_class, params->tsid);
  2101. cmd = (struct wmi_create_pstream_cmd *) skb->data;
  2102. memcpy(cmd, params, sizeof(*cmd));
  2103. /* This is an implicitly created Fat pipe */
  2104. if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
  2105. spin_lock_bh(&wmi->lock);
  2106. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  2107. (1 << params->traffic_class));
  2108. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  2109. spin_unlock_bh(&wmi->lock);
  2110. } else {
  2111. /* explicitly created thin stream within a fat pipe */
  2112. spin_lock_bh(&wmi->lock);
  2113. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  2114. (1 << params->traffic_class));
  2115. wmi->stream_exist_for_ac[params->traffic_class] |=
  2116. (1 << params->tsid);
  2117. /*
  2118. * If a thinstream becomes active, the fat pipe automatically
  2119. * becomes active
  2120. */
  2121. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  2122. spin_unlock_bh(&wmi->lock);
  2123. }
  2124. /*
  2125. * Indicate activty change to driver layer only if this is the
  2126. * first TSID to get created in this AC explicitly or an implicit
  2127. * fat pipe is getting created.
  2128. */
  2129. if (!fatpipe_exist_for_ac)
  2130. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2131. params->traffic_class, true);
  2132. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
  2133. NO_SYNC_WMIFLAG);
  2134. return ret;
  2135. }
  2136. int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
  2137. u8 tsid)
  2138. {
  2139. struct sk_buff *skb;
  2140. struct wmi_delete_pstream_cmd *cmd;
  2141. u16 active_tsids = 0;
  2142. int ret;
  2143. if (traffic_class > 3) {
  2144. ath6kl_err("invalid traffic class: %d\n", traffic_class);
  2145. return -EINVAL;
  2146. }
  2147. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2148. if (!skb)
  2149. return -ENOMEM;
  2150. cmd = (struct wmi_delete_pstream_cmd *) skb->data;
  2151. cmd->traffic_class = traffic_class;
  2152. cmd->tsid = tsid;
  2153. spin_lock_bh(&wmi->lock);
  2154. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  2155. spin_unlock_bh(&wmi->lock);
  2156. if (!(active_tsids & (1 << tsid))) {
  2157. dev_kfree_skb(skb);
  2158. ath6kl_dbg(ATH6KL_DBG_WMI,
  2159. "TSID %d doesn't exist for traffic class: %d\n",
  2160. tsid, traffic_class);
  2161. return -ENODATA;
  2162. }
  2163. ath6kl_dbg(ATH6KL_DBG_WMI,
  2164. "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
  2165. traffic_class, tsid);
  2166. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
  2167. SYNC_BEFORE_WMIFLAG);
  2168. spin_lock_bh(&wmi->lock);
  2169. wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
  2170. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  2171. spin_unlock_bh(&wmi->lock);
  2172. /*
  2173. * Indicate stream inactivity to driver layer only if all tsids
  2174. * within this AC are deleted.
  2175. */
  2176. if (!active_tsids) {
  2177. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2178. traffic_class, false);
  2179. wmi->fat_pipe_exist &= ~(1 << traffic_class);
  2180. }
  2181. return ret;
  2182. }
  2183. int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
  2184. __be32 ips0, __be32 ips1)
  2185. {
  2186. struct sk_buff *skb;
  2187. struct wmi_set_ip_cmd *cmd;
  2188. int ret;
  2189. /* Multicast address are not valid */
  2190. if (ipv4_is_multicast(ips0) ||
  2191. ipv4_is_multicast(ips1))
  2192. return -EINVAL;
  2193. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
  2194. if (!skb)
  2195. return -ENOMEM;
  2196. cmd = (struct wmi_set_ip_cmd *) skb->data;
  2197. cmd->ips[0] = ips0;
  2198. cmd->ips[1] = ips1;
  2199. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
  2200. NO_SYNC_WMIFLAG);
  2201. return ret;
  2202. }
  2203. static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
  2204. {
  2205. u16 active_tsids;
  2206. u8 stream_exist;
  2207. int i;
  2208. /*
  2209. * Relinquish credits from all implicitly created pstreams
  2210. * since when we go to sleep. If user created explicit
  2211. * thinstreams exists with in a fatpipe leave them intact
  2212. * for the user to delete.
  2213. */
  2214. spin_lock_bh(&wmi->lock);
  2215. stream_exist = wmi->fat_pipe_exist;
  2216. spin_unlock_bh(&wmi->lock);
  2217. for (i = 0; i < WMM_NUM_AC; i++) {
  2218. if (stream_exist & (1 << i)) {
  2219. /*
  2220. * FIXME: Is this lock & unlock inside
  2221. * for loop correct? may need rework.
  2222. */
  2223. spin_lock_bh(&wmi->lock);
  2224. active_tsids = wmi->stream_exist_for_ac[i];
  2225. spin_unlock_bh(&wmi->lock);
  2226. /*
  2227. * If there are no user created thin streams
  2228. * delete the fatpipe
  2229. */
  2230. if (!active_tsids) {
  2231. stream_exist &= ~(1 << i);
  2232. /*
  2233. * Indicate inactivity to driver layer for
  2234. * this fatpipe (pstream)
  2235. */
  2236. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2237. i, false);
  2238. }
  2239. }
  2240. }
  2241. /* FIXME: Can we do this assignment without locking ? */
  2242. spin_lock_bh(&wmi->lock);
  2243. wmi->fat_pipe_exist = stream_exist;
  2244. spin_unlock_bh(&wmi->lock);
  2245. }
  2246. static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
  2247. const struct cfg80211_bitrate_mask *mask)
  2248. {
  2249. struct sk_buff *skb;
  2250. int ret, mode, band;
  2251. u64 mcsrate, ratemask[ATH6KL_NUM_BANDS];
  2252. struct wmi_set_tx_select_rates64_cmd *cmd;
  2253. memset(&ratemask, 0, sizeof(ratemask));
  2254. /* only check 2.4 and 5 GHz bands, skip the rest */
  2255. for (band = 0; band <= NL80211_BAND_5GHZ; band++) {
  2256. /* copy legacy rate mask */
  2257. ratemask[band] = mask->control[band].legacy;
  2258. if (band == NL80211_BAND_5GHZ)
  2259. ratemask[band] =
  2260. mask->control[band].legacy << 4;
  2261. /* copy mcs rate mask */
  2262. mcsrate = mask->control[band].ht_mcs[1];
  2263. mcsrate <<= 8;
  2264. mcsrate |= mask->control[band].ht_mcs[0];
  2265. ratemask[band] |= mcsrate << 12;
  2266. ratemask[band] |= mcsrate << 28;
  2267. }
  2268. ath6kl_dbg(ATH6KL_DBG_WMI,
  2269. "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
  2270. ratemask[0], ratemask[1]);
  2271. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
  2272. if (!skb)
  2273. return -ENOMEM;
  2274. cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
  2275. for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
  2276. /* A mode operate in 5GHZ band */
  2277. if (mode == WMI_RATES_MODE_11A ||
  2278. mode == WMI_RATES_MODE_11A_HT20 ||
  2279. mode == WMI_RATES_MODE_11A_HT40)
  2280. band = NL80211_BAND_5GHZ;
  2281. else
  2282. band = NL80211_BAND_2GHZ;
  2283. cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
  2284. }
  2285. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2286. WMI_SET_TX_SELECT_RATES_CMDID,
  2287. NO_SYNC_WMIFLAG);
  2288. return ret;
  2289. }
  2290. static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
  2291. const struct cfg80211_bitrate_mask *mask)
  2292. {
  2293. struct sk_buff *skb;
  2294. int ret, mode, band;
  2295. u32 mcsrate, ratemask[ATH6KL_NUM_BANDS];
  2296. struct wmi_set_tx_select_rates32_cmd *cmd;
  2297. memset(&ratemask, 0, sizeof(ratemask));
  2298. /* only check 2.4 and 5 GHz bands, skip the rest */
  2299. for (band = 0; band <= NL80211_BAND_5GHZ; band++) {
  2300. /* copy legacy rate mask */
  2301. ratemask[band] = mask->control[band].legacy;
  2302. if (band == NL80211_BAND_5GHZ)
  2303. ratemask[band] =
  2304. mask->control[band].legacy << 4;
  2305. /* copy mcs rate mask */
  2306. mcsrate = mask->control[band].ht_mcs[0];
  2307. ratemask[band] |= mcsrate << 12;
  2308. ratemask[band] |= mcsrate << 20;
  2309. }
  2310. ath6kl_dbg(ATH6KL_DBG_WMI,
  2311. "Ratemask 32 bit: 2.4:%x 5:%x\n",
  2312. ratemask[0], ratemask[1]);
  2313. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
  2314. if (!skb)
  2315. return -ENOMEM;
  2316. cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
  2317. for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
  2318. /* A mode operate in 5GHZ band */
  2319. if (mode == WMI_RATES_MODE_11A ||
  2320. mode == WMI_RATES_MODE_11A_HT20 ||
  2321. mode == WMI_RATES_MODE_11A_HT40)
  2322. band = NL80211_BAND_5GHZ;
  2323. else
  2324. band = NL80211_BAND_2GHZ;
  2325. cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
  2326. }
  2327. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2328. WMI_SET_TX_SELECT_RATES_CMDID,
  2329. NO_SYNC_WMIFLAG);
  2330. return ret;
  2331. }
  2332. int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
  2333. const struct cfg80211_bitrate_mask *mask)
  2334. {
  2335. struct ath6kl *ar = wmi->parent_dev;
  2336. if (test_bit(ATH6KL_FW_CAPABILITY_64BIT_RATES,
  2337. ar->fw_capabilities))
  2338. return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
  2339. else
  2340. return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
  2341. }
  2342. int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
  2343. enum ath6kl_host_mode host_mode)
  2344. {
  2345. struct sk_buff *skb;
  2346. struct wmi_set_host_sleep_mode_cmd *cmd;
  2347. int ret;
  2348. if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
  2349. (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
  2350. ath6kl_err("invalid host sleep mode: %d\n", host_mode);
  2351. return -EINVAL;
  2352. }
  2353. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2354. if (!skb)
  2355. return -ENOMEM;
  2356. cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
  2357. if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
  2358. ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
  2359. cmd->asleep = cpu_to_le32(1);
  2360. } else {
  2361. cmd->awake = cpu_to_le32(1);
  2362. }
  2363. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2364. WMI_SET_HOST_SLEEP_MODE_CMDID,
  2365. NO_SYNC_WMIFLAG);
  2366. return ret;
  2367. }
  2368. /* This command has zero length payload */
  2369. static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
  2370. struct ath6kl_vif *vif)
  2371. {
  2372. struct ath6kl *ar = wmi->parent_dev;
  2373. set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
  2374. wake_up(&ar->event_wq);
  2375. return 0;
  2376. }
  2377. int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
  2378. enum ath6kl_wow_mode wow_mode,
  2379. u32 filter, u16 host_req_delay)
  2380. {
  2381. struct sk_buff *skb;
  2382. struct wmi_set_wow_mode_cmd *cmd;
  2383. int ret;
  2384. if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
  2385. wow_mode != ATH6KL_WOW_MODE_DISABLE) {
  2386. ath6kl_err("invalid wow mode: %d\n", wow_mode);
  2387. return -EINVAL;
  2388. }
  2389. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2390. if (!skb)
  2391. return -ENOMEM;
  2392. cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
  2393. cmd->enable_wow = cpu_to_le32(wow_mode);
  2394. cmd->filter = cpu_to_le32(filter);
  2395. cmd->host_req_delay = cpu_to_le16(host_req_delay);
  2396. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
  2397. NO_SYNC_WMIFLAG);
  2398. return ret;
  2399. }
  2400. int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2401. u8 list_id, u8 filter_size,
  2402. u8 filter_offset, const u8 *filter,
  2403. const u8 *mask)
  2404. {
  2405. struct sk_buff *skb;
  2406. struct wmi_add_wow_pattern_cmd *cmd;
  2407. u16 size;
  2408. u8 *filter_mask;
  2409. int ret;
  2410. /*
  2411. * Allocate additional memory in the buffer to hold
  2412. * filter and mask value, which is twice of filter_size.
  2413. */
  2414. size = sizeof(*cmd) + (2 * filter_size);
  2415. skb = ath6kl_wmi_get_new_buf(size);
  2416. if (!skb)
  2417. return -ENOMEM;
  2418. cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
  2419. cmd->filter_list_id = list_id;
  2420. cmd->filter_size = filter_size;
  2421. cmd->filter_offset = filter_offset;
  2422. memcpy(cmd->filter, filter, filter_size);
  2423. filter_mask = (u8 *) (cmd->filter + filter_size);
  2424. memcpy(filter_mask, mask, filter_size);
  2425. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
  2426. NO_SYNC_WMIFLAG);
  2427. return ret;
  2428. }
  2429. int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2430. u16 list_id, u16 filter_id)
  2431. {
  2432. struct sk_buff *skb;
  2433. struct wmi_del_wow_pattern_cmd *cmd;
  2434. int ret;
  2435. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2436. if (!skb)
  2437. return -ENOMEM;
  2438. cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
  2439. cmd->filter_list_id = cpu_to_le16(list_id);
  2440. cmd->filter_id = cpu_to_le16(filter_id);
  2441. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
  2442. NO_SYNC_WMIFLAG);
  2443. return ret;
  2444. }
  2445. static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
  2446. enum wmix_command_id cmd_id,
  2447. enum wmi_sync_flag sync_flag)
  2448. {
  2449. struct wmix_cmd_hdr *cmd_hdr;
  2450. int ret;
  2451. skb_push(skb, sizeof(struct wmix_cmd_hdr));
  2452. cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
  2453. cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
  2454. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
  2455. return ret;
  2456. }
  2457. int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
  2458. {
  2459. struct sk_buff *skb;
  2460. struct wmix_hb_challenge_resp_cmd *cmd;
  2461. int ret;
  2462. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2463. if (!skb)
  2464. return -ENOMEM;
  2465. cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
  2466. cmd->cookie = cpu_to_le32(cookie);
  2467. cmd->source = cpu_to_le32(source);
  2468. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
  2469. NO_SYNC_WMIFLAG);
  2470. return ret;
  2471. }
  2472. int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
  2473. {
  2474. struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
  2475. struct sk_buff *skb;
  2476. int ret;
  2477. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2478. if (!skb)
  2479. return -ENOMEM;
  2480. cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
  2481. cmd->valid = cpu_to_le32(valid);
  2482. cmd->config = cpu_to_le32(config);
  2483. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
  2484. NO_SYNC_WMIFLAG);
  2485. return ret;
  2486. }
  2487. int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
  2488. {
  2489. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
  2490. }
  2491. int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
  2492. {
  2493. struct sk_buff *skb;
  2494. struct wmi_set_tx_pwr_cmd *cmd;
  2495. int ret;
  2496. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
  2497. if (!skb)
  2498. return -ENOMEM;
  2499. cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
  2500. cmd->dbM = dbM;
  2501. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
  2502. NO_SYNC_WMIFLAG);
  2503. return ret;
  2504. }
  2505. int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
  2506. {
  2507. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
  2508. }
  2509. int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
  2510. {
  2511. return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
  2512. }
  2513. int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
  2514. u8 preamble_policy)
  2515. {
  2516. struct sk_buff *skb;
  2517. struct wmi_set_lpreamble_cmd *cmd;
  2518. int ret;
  2519. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
  2520. if (!skb)
  2521. return -ENOMEM;
  2522. cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
  2523. cmd->status = status;
  2524. cmd->preamble_policy = preamble_policy;
  2525. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
  2526. NO_SYNC_WMIFLAG);
  2527. return ret;
  2528. }
  2529. int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
  2530. {
  2531. struct sk_buff *skb;
  2532. struct wmi_set_rts_cmd *cmd;
  2533. int ret;
  2534. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
  2535. if (!skb)
  2536. return -ENOMEM;
  2537. cmd = (struct wmi_set_rts_cmd *) skb->data;
  2538. cmd->threshold = cpu_to_le16(threshold);
  2539. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
  2540. NO_SYNC_WMIFLAG);
  2541. return ret;
  2542. }
  2543. int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
  2544. {
  2545. struct sk_buff *skb;
  2546. struct wmi_set_wmm_txop_cmd *cmd;
  2547. int ret;
  2548. if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
  2549. return -EINVAL;
  2550. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
  2551. if (!skb)
  2552. return -ENOMEM;
  2553. cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
  2554. cmd->txop_enable = cfg;
  2555. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
  2556. NO_SYNC_WMIFLAG);
  2557. return ret;
  2558. }
  2559. int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
  2560. u8 keep_alive_intvl)
  2561. {
  2562. struct sk_buff *skb;
  2563. struct wmi_set_keepalive_cmd *cmd;
  2564. int ret;
  2565. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2566. if (!skb)
  2567. return -ENOMEM;
  2568. cmd = (struct wmi_set_keepalive_cmd *) skb->data;
  2569. cmd->keep_alive_intvl = keep_alive_intvl;
  2570. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
  2571. NO_SYNC_WMIFLAG);
  2572. if (ret == 0)
  2573. ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
  2574. return ret;
  2575. }
  2576. int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
  2577. enum nl80211_band band,
  2578. struct ath6kl_htcap *htcap)
  2579. {
  2580. struct sk_buff *skb;
  2581. struct wmi_set_htcap_cmd *cmd;
  2582. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2583. if (!skb)
  2584. return -ENOMEM;
  2585. cmd = (struct wmi_set_htcap_cmd *) skb->data;
  2586. /*
  2587. * NOTE: Band in firmware matches enum nl80211_band, it is unlikely
  2588. * this will be changed in firmware. If at all there is any change in
  2589. * band value, the host needs to be fixed.
  2590. */
  2591. cmd->band = band;
  2592. cmd->ht_enable = !!htcap->ht_enable;
  2593. cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
  2594. cmd->ht40_supported =
  2595. !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
  2596. cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
  2597. cmd->intolerant_40mhz =
  2598. !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
  2599. cmd->max_ampdu_len_exp = htcap->ampdu_factor;
  2600. ath6kl_dbg(ATH6KL_DBG_WMI,
  2601. "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
  2602. cmd->band, cmd->ht_enable, cmd->ht40_supported,
  2603. cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
  2604. cmd->max_ampdu_len_exp);
  2605. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
  2606. NO_SYNC_WMIFLAG);
  2607. }
  2608. int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
  2609. {
  2610. struct sk_buff *skb;
  2611. int ret;
  2612. skb = ath6kl_wmi_get_new_buf(len);
  2613. if (!skb)
  2614. return -ENOMEM;
  2615. memcpy(skb->data, buf, len);
  2616. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
  2617. return ret;
  2618. }
  2619. int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
  2620. {
  2621. struct sk_buff *skb;
  2622. struct wmi_mcast_filter_cmd *cmd;
  2623. int ret;
  2624. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2625. if (!skb)
  2626. return -ENOMEM;
  2627. cmd = (struct wmi_mcast_filter_cmd *) skb->data;
  2628. cmd->mcast_all_enable = mc_all_on;
  2629. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
  2630. NO_SYNC_WMIFLAG);
  2631. return ret;
  2632. }
  2633. int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
  2634. u8 *filter, bool add_filter)
  2635. {
  2636. struct sk_buff *skb;
  2637. struct wmi_mcast_filter_add_del_cmd *cmd;
  2638. int ret;
  2639. if ((filter[0] != 0x33 || filter[1] != 0x33) &&
  2640. (filter[0] != 0x01 || filter[1] != 0x00 ||
  2641. filter[2] != 0x5e || filter[3] > 0x7f)) {
  2642. ath6kl_warn("invalid multicast filter address\n");
  2643. return -EINVAL;
  2644. }
  2645. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2646. if (!skb)
  2647. return -ENOMEM;
  2648. cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
  2649. memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
  2650. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2651. add_filter ? WMI_SET_MCAST_FILTER_CMDID :
  2652. WMI_DEL_MCAST_FILTER_CMDID,
  2653. NO_SYNC_WMIFLAG);
  2654. return ret;
  2655. }
  2656. int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
  2657. {
  2658. struct sk_buff *skb;
  2659. struct wmi_sta_bmiss_enhance_cmd *cmd;
  2660. int ret;
  2661. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2662. if (!skb)
  2663. return -ENOMEM;
  2664. cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
  2665. cmd->enable = enhance ? 1 : 0;
  2666. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2667. WMI_STA_BMISS_ENHANCE_CMDID,
  2668. NO_SYNC_WMIFLAG);
  2669. return ret;
  2670. }
  2671. int ath6kl_wmi_set_regdomain_cmd(struct wmi *wmi, const char *alpha2)
  2672. {
  2673. struct sk_buff *skb;
  2674. struct wmi_set_regdomain_cmd *cmd;
  2675. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2676. if (!skb)
  2677. return -ENOMEM;
  2678. cmd = (struct wmi_set_regdomain_cmd *) skb->data;
  2679. memcpy(cmd->iso_name, alpha2, 2);
  2680. return ath6kl_wmi_cmd_send(wmi, 0, skb,
  2681. WMI_SET_REGDOMAIN_CMDID,
  2682. NO_SYNC_WMIFLAG);
  2683. }
  2684. s32 ath6kl_wmi_get_rate(struct wmi *wmi, s8 rate_index)
  2685. {
  2686. struct ath6kl *ar = wmi->parent_dev;
  2687. u8 sgi = 0;
  2688. s32 ret;
  2689. if (rate_index == RATE_AUTO)
  2690. return 0;
  2691. /* SGI is stored as the MSB of the rate_index */
  2692. if (rate_index & RATE_INDEX_MSB) {
  2693. rate_index &= RATE_INDEX_WITHOUT_SGI_MASK;
  2694. sgi = 1;
  2695. }
  2696. if (test_bit(ATH6KL_FW_CAPABILITY_RATETABLE_MCS15,
  2697. ar->fw_capabilities)) {
  2698. if (WARN_ON(rate_index >= ARRAY_SIZE(wmi_rate_tbl_mcs15)))
  2699. return 0;
  2700. ret = wmi_rate_tbl_mcs15[(u32) rate_index][sgi];
  2701. } else {
  2702. if (WARN_ON(rate_index >= ARRAY_SIZE(wmi_rate_tbl)))
  2703. return 0;
  2704. ret = wmi_rate_tbl[(u32) rate_index][sgi];
  2705. }
  2706. return ret;
  2707. }
  2708. static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
  2709. u32 len)
  2710. {
  2711. struct wmi_pmkid_list_reply *reply;
  2712. u32 expected_len;
  2713. if (len < sizeof(struct wmi_pmkid_list_reply))
  2714. return -EINVAL;
  2715. reply = (struct wmi_pmkid_list_reply *)datap;
  2716. expected_len = sizeof(reply->num_pmkid) +
  2717. le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
  2718. if (len < expected_len)
  2719. return -EINVAL;
  2720. return 0;
  2721. }
  2722. static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2723. struct ath6kl_vif *vif)
  2724. {
  2725. struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
  2726. aggr_recv_addba_req_evt(vif, cmd->tid,
  2727. le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
  2728. return 0;
  2729. }
  2730. static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2731. struct ath6kl_vif *vif)
  2732. {
  2733. struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
  2734. aggr_recv_delba_req_evt(vif, cmd->tid);
  2735. return 0;
  2736. }
  2737. /* AP mode functions */
  2738. int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
  2739. struct wmi_connect_cmd *p)
  2740. {
  2741. struct sk_buff *skb;
  2742. struct wmi_connect_cmd *cm;
  2743. int res;
  2744. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2745. if (!skb)
  2746. return -ENOMEM;
  2747. cm = (struct wmi_connect_cmd *) skb->data;
  2748. memcpy(cm, p, sizeof(*cm));
  2749. res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
  2750. NO_SYNC_WMIFLAG);
  2751. ath6kl_dbg(ATH6KL_DBG_WMI,
  2752. "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
  2753. __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
  2754. le32_to_cpu(p->ctrl_flags), res);
  2755. return res;
  2756. }
  2757. int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
  2758. u16 reason)
  2759. {
  2760. struct sk_buff *skb;
  2761. struct wmi_ap_set_mlme_cmd *cm;
  2762. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2763. if (!skb)
  2764. return -ENOMEM;
  2765. cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
  2766. memcpy(cm->mac, mac, ETH_ALEN);
  2767. cm->reason = cpu_to_le16(reason);
  2768. cm->cmd = cmd;
  2769. ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
  2770. cm->reason);
  2771. return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
  2772. NO_SYNC_WMIFLAG);
  2773. }
  2774. int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
  2775. {
  2776. struct sk_buff *skb;
  2777. struct wmi_ap_hidden_ssid_cmd *cmd;
  2778. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2779. if (!skb)
  2780. return -ENOMEM;
  2781. cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
  2782. cmd->hidden_ssid = enable ? 1 : 0;
  2783. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
  2784. NO_SYNC_WMIFLAG);
  2785. }
  2786. /* This command will be used to enable/disable AP uAPSD feature */
  2787. int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
  2788. {
  2789. struct wmi_ap_set_apsd_cmd *cmd;
  2790. struct sk_buff *skb;
  2791. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2792. if (!skb)
  2793. return -ENOMEM;
  2794. cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
  2795. cmd->enable = enable;
  2796. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
  2797. NO_SYNC_WMIFLAG);
  2798. }
  2799. int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
  2800. u16 aid, u16 bitmap, u32 flags)
  2801. {
  2802. struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
  2803. struct sk_buff *skb;
  2804. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2805. if (!skb)
  2806. return -ENOMEM;
  2807. cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
  2808. cmd->aid = cpu_to_le16(aid);
  2809. cmd->bitmap = cpu_to_le16(bitmap);
  2810. cmd->flags = cpu_to_le32(flags);
  2811. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2812. WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
  2813. NO_SYNC_WMIFLAG);
  2814. }
  2815. static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
  2816. struct ath6kl_vif *vif)
  2817. {
  2818. struct wmi_pspoll_event *ev;
  2819. if (len < sizeof(struct wmi_pspoll_event))
  2820. return -EINVAL;
  2821. ev = (struct wmi_pspoll_event *) datap;
  2822. ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
  2823. return 0;
  2824. }
  2825. static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
  2826. struct ath6kl_vif *vif)
  2827. {
  2828. ath6kl_dtimexpiry_event(vif);
  2829. return 0;
  2830. }
  2831. int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
  2832. bool flag)
  2833. {
  2834. struct sk_buff *skb;
  2835. struct wmi_ap_set_pvb_cmd *cmd;
  2836. int ret;
  2837. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
  2838. if (!skb)
  2839. return -ENOMEM;
  2840. cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
  2841. cmd->aid = cpu_to_le16(aid);
  2842. cmd->rsvd = cpu_to_le16(0);
  2843. cmd->flag = cpu_to_le32(flag);
  2844. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
  2845. NO_SYNC_WMIFLAG);
  2846. return ret;
  2847. }
  2848. int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
  2849. u8 rx_meta_ver,
  2850. bool rx_dot11_hdr, bool defrag_on_host)
  2851. {
  2852. struct sk_buff *skb;
  2853. struct wmi_rx_frame_format_cmd *cmd;
  2854. int ret;
  2855. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2856. if (!skb)
  2857. return -ENOMEM;
  2858. cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
  2859. cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
  2860. cmd->defrag_on_host = defrag_on_host ? 1 : 0;
  2861. cmd->meta_ver = rx_meta_ver;
  2862. /* Delete the local aggr state, on host */
  2863. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
  2864. NO_SYNC_WMIFLAG);
  2865. return ret;
  2866. }
  2867. int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
  2868. const u8 *ie, u8 ie_len)
  2869. {
  2870. struct sk_buff *skb;
  2871. struct wmi_set_appie_cmd *p;
  2872. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
  2873. if (!skb)
  2874. return -ENOMEM;
  2875. ath6kl_dbg(ATH6KL_DBG_WMI,
  2876. "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
  2877. mgmt_frm_type, ie_len);
  2878. p = (struct wmi_set_appie_cmd *) skb->data;
  2879. p->mgmt_frm_type = mgmt_frm_type;
  2880. p->ie_len = ie_len;
  2881. if (ie != NULL && ie_len > 0)
  2882. memcpy(p->ie_info, ie, ie_len);
  2883. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
  2884. NO_SYNC_WMIFLAG);
  2885. }
  2886. int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
  2887. const u8 *ie_info, u8 ie_len)
  2888. {
  2889. struct sk_buff *skb;
  2890. struct wmi_set_ie_cmd *p;
  2891. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
  2892. if (!skb)
  2893. return -ENOMEM;
  2894. ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
  2895. ie_id, ie_field, ie_len);
  2896. p = (struct wmi_set_ie_cmd *) skb->data;
  2897. p->ie_id = ie_id;
  2898. p->ie_field = ie_field;
  2899. p->ie_len = ie_len;
  2900. if (ie_info && ie_len > 0)
  2901. memcpy(p->ie_info, ie_info, ie_len);
  2902. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
  2903. NO_SYNC_WMIFLAG);
  2904. }
  2905. int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
  2906. {
  2907. struct sk_buff *skb;
  2908. struct wmi_disable_11b_rates_cmd *cmd;
  2909. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2910. if (!skb)
  2911. return -ENOMEM;
  2912. ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
  2913. disable);
  2914. cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
  2915. cmd->disable = disable ? 1 : 0;
  2916. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
  2917. NO_SYNC_WMIFLAG);
  2918. }
  2919. int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
  2920. {
  2921. struct sk_buff *skb;
  2922. struct wmi_remain_on_chnl_cmd *p;
  2923. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2924. if (!skb)
  2925. return -ENOMEM;
  2926. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
  2927. freq, dur);
  2928. p = (struct wmi_remain_on_chnl_cmd *) skb->data;
  2929. p->freq = cpu_to_le32(freq);
  2930. p->duration = cpu_to_le32(dur);
  2931. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
  2932. NO_SYNC_WMIFLAG);
  2933. }
  2934. /* ath6kl_wmi_send_action_cmd is to be deprecated. Use
  2935. * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
  2936. * mgmt operations using station interface.
  2937. */
  2938. static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
  2939. u32 freq, u32 wait, const u8 *data,
  2940. u16 data_len)
  2941. {
  2942. struct sk_buff *skb;
  2943. struct wmi_send_action_cmd *p;
  2944. u8 *buf;
  2945. if (wait)
  2946. return -EINVAL; /* Offload for wait not supported */
  2947. buf = kmalloc(data_len, GFP_KERNEL);
  2948. if (!buf)
  2949. return -ENOMEM;
  2950. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2951. if (!skb) {
  2952. kfree(buf);
  2953. return -ENOMEM;
  2954. }
  2955. kfree(wmi->last_mgmt_tx_frame);
  2956. memcpy(buf, data, data_len);
  2957. wmi->last_mgmt_tx_frame = buf;
  2958. wmi->last_mgmt_tx_frame_len = data_len;
  2959. ath6kl_dbg(ATH6KL_DBG_WMI,
  2960. "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
  2961. id, freq, wait, data_len);
  2962. p = (struct wmi_send_action_cmd *) skb->data;
  2963. p->id = cpu_to_le32(id);
  2964. p->freq = cpu_to_le32(freq);
  2965. p->wait = cpu_to_le32(wait);
  2966. p->len = cpu_to_le16(data_len);
  2967. memcpy(p->data, data, data_len);
  2968. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
  2969. NO_SYNC_WMIFLAG);
  2970. }
  2971. static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
  2972. u32 freq, u32 wait, const u8 *data,
  2973. u16 data_len, u32 no_cck)
  2974. {
  2975. struct sk_buff *skb;
  2976. struct wmi_send_mgmt_cmd *p;
  2977. u8 *buf;
  2978. if (wait)
  2979. return -EINVAL; /* Offload for wait not supported */
  2980. buf = kmalloc(data_len, GFP_KERNEL);
  2981. if (!buf)
  2982. return -ENOMEM;
  2983. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2984. if (!skb) {
  2985. kfree(buf);
  2986. return -ENOMEM;
  2987. }
  2988. kfree(wmi->last_mgmt_tx_frame);
  2989. memcpy(buf, data, data_len);
  2990. wmi->last_mgmt_tx_frame = buf;
  2991. wmi->last_mgmt_tx_frame_len = data_len;
  2992. ath6kl_dbg(ATH6KL_DBG_WMI,
  2993. "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
  2994. id, freq, wait, data_len);
  2995. p = (struct wmi_send_mgmt_cmd *) skb->data;
  2996. p->id = cpu_to_le32(id);
  2997. p->freq = cpu_to_le32(freq);
  2998. p->wait = cpu_to_le32(wait);
  2999. p->no_cck = cpu_to_le32(no_cck);
  3000. p->len = cpu_to_le16(data_len);
  3001. memcpy(p->data, data, data_len);
  3002. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
  3003. NO_SYNC_WMIFLAG);
  3004. }
  3005. int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
  3006. u32 wait, const u8 *data, u16 data_len,
  3007. u32 no_cck)
  3008. {
  3009. int status;
  3010. struct ath6kl *ar = wmi->parent_dev;
  3011. if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  3012. ar->fw_capabilities)) {
  3013. /*
  3014. * If capable of doing P2P mgmt operations using
  3015. * station interface, send additional information like
  3016. * supported rates to advertise and xmit rates for
  3017. * probe requests
  3018. */
  3019. status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
  3020. wait, data, data_len,
  3021. no_cck);
  3022. } else {
  3023. status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
  3024. wait, data, data_len);
  3025. }
  3026. return status;
  3027. }
  3028. int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
  3029. const u8 *dst, const u8 *data,
  3030. u16 data_len)
  3031. {
  3032. struct sk_buff *skb;
  3033. struct wmi_p2p_probe_response_cmd *p;
  3034. size_t cmd_len = sizeof(*p) + data_len;
  3035. if (data_len == 0)
  3036. cmd_len++; /* work around target minimum length requirement */
  3037. skb = ath6kl_wmi_get_new_buf(cmd_len);
  3038. if (!skb)
  3039. return -ENOMEM;
  3040. ath6kl_dbg(ATH6KL_DBG_WMI,
  3041. "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
  3042. freq, dst, data_len);
  3043. p = (struct wmi_p2p_probe_response_cmd *) skb->data;
  3044. p->freq = cpu_to_le32(freq);
  3045. memcpy(p->destination_addr, dst, ETH_ALEN);
  3046. p->len = cpu_to_le16(data_len);
  3047. memcpy(p->data, data, data_len);
  3048. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  3049. WMI_SEND_PROBE_RESPONSE_CMDID,
  3050. NO_SYNC_WMIFLAG);
  3051. }
  3052. int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
  3053. {
  3054. struct sk_buff *skb;
  3055. struct wmi_probe_req_report_cmd *p;
  3056. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  3057. if (!skb)
  3058. return -ENOMEM;
  3059. ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
  3060. enable);
  3061. p = (struct wmi_probe_req_report_cmd *) skb->data;
  3062. p->enable = enable ? 1 : 0;
  3063. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
  3064. NO_SYNC_WMIFLAG);
  3065. }
  3066. int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
  3067. {
  3068. struct sk_buff *skb;
  3069. struct wmi_get_p2p_info *p;
  3070. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  3071. if (!skb)
  3072. return -ENOMEM;
  3073. ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
  3074. info_req_flags);
  3075. p = (struct wmi_get_p2p_info *) skb->data;
  3076. p->info_req_flags = cpu_to_le32(info_req_flags);
  3077. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
  3078. NO_SYNC_WMIFLAG);
  3079. }
  3080. int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
  3081. {
  3082. ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
  3083. return ath6kl_wmi_simple_cmd(wmi, if_idx,
  3084. WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
  3085. }
  3086. int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
  3087. {
  3088. struct sk_buff *skb;
  3089. struct wmi_set_inact_period_cmd *cmd;
  3090. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  3091. if (!skb)
  3092. return -ENOMEM;
  3093. cmd = (struct wmi_set_inact_period_cmd *) skb->data;
  3094. cmd->inact_period = cpu_to_le32(inact_timeout);
  3095. cmd->num_null_func = 0;
  3096. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
  3097. NO_SYNC_WMIFLAG);
  3098. }
  3099. static void ath6kl_wmi_hb_challenge_resp_event(struct wmi *wmi, u8 *datap,
  3100. int len)
  3101. {
  3102. struct wmix_hb_challenge_resp_cmd *cmd;
  3103. if (len < sizeof(struct wmix_hb_challenge_resp_cmd))
  3104. return;
  3105. cmd = (struct wmix_hb_challenge_resp_cmd *) datap;
  3106. ath6kl_recovery_hb_event(wmi->parent_dev,
  3107. le32_to_cpu(cmd->cookie));
  3108. }
  3109. static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
  3110. {
  3111. struct wmix_cmd_hdr *cmd;
  3112. u32 len;
  3113. u16 id;
  3114. u8 *datap;
  3115. int ret = 0;
  3116. if (skb->len < sizeof(struct wmix_cmd_hdr)) {
  3117. ath6kl_err("bad packet 1\n");
  3118. return -EINVAL;
  3119. }
  3120. cmd = (struct wmix_cmd_hdr *) skb->data;
  3121. id = le32_to_cpu(cmd->cmd_id);
  3122. skb_pull(skb, sizeof(struct wmix_cmd_hdr));
  3123. datap = skb->data;
  3124. len = skb->len;
  3125. switch (id) {
  3126. case WMIX_HB_CHALLENGE_RESP_EVENTID:
  3127. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
  3128. ath6kl_wmi_hb_challenge_resp_event(wmi, datap, len);
  3129. break;
  3130. case WMIX_DBGLOG_EVENTID:
  3131. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
  3132. ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
  3133. break;
  3134. default:
  3135. ath6kl_warn("unknown cmd id 0x%x\n", id);
  3136. ret = -EINVAL;
  3137. break;
  3138. }
  3139. return ret;
  3140. }
  3141. static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
  3142. {
  3143. return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
  3144. }
  3145. /* Process interface specific wmi events, caller would free the datap */
  3146. static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
  3147. u8 *datap, u32 len)
  3148. {
  3149. struct ath6kl_vif *vif;
  3150. vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
  3151. if (!vif) {
  3152. ath6kl_dbg(ATH6KL_DBG_WMI,
  3153. "Wmi event for unavailable vif, vif_index:%d\n",
  3154. if_idx);
  3155. return -EINVAL;
  3156. }
  3157. switch (cmd_id) {
  3158. case WMI_CONNECT_EVENTID:
  3159. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
  3160. return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
  3161. case WMI_DISCONNECT_EVENTID:
  3162. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
  3163. return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
  3164. case WMI_TKIP_MICERR_EVENTID:
  3165. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
  3166. return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
  3167. case WMI_BSSINFO_EVENTID:
  3168. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
  3169. return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
  3170. case WMI_NEIGHBOR_REPORT_EVENTID:
  3171. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
  3172. return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
  3173. vif);
  3174. case WMI_SCAN_COMPLETE_EVENTID:
  3175. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
  3176. return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
  3177. case WMI_REPORT_STATISTICS_EVENTID:
  3178. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
  3179. return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
  3180. case WMI_CAC_EVENTID:
  3181. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
  3182. return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
  3183. case WMI_PSPOLL_EVENTID:
  3184. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
  3185. return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
  3186. case WMI_DTIMEXPIRY_EVENTID:
  3187. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
  3188. return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
  3189. case WMI_ADDBA_REQ_EVENTID:
  3190. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
  3191. return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
  3192. case WMI_DELBA_REQ_EVENTID:
  3193. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
  3194. return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
  3195. case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
  3196. ath6kl_dbg(ATH6KL_DBG_WMI,
  3197. "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
  3198. return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
  3199. case WMI_REMAIN_ON_CHNL_EVENTID:
  3200. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
  3201. return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
  3202. case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
  3203. ath6kl_dbg(ATH6KL_DBG_WMI,
  3204. "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
  3205. return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
  3206. len, vif);
  3207. case WMI_TX_STATUS_EVENTID:
  3208. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
  3209. return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
  3210. case WMI_RX_PROBE_REQ_EVENTID:
  3211. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
  3212. return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
  3213. case WMI_RX_ACTION_EVENTID:
  3214. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
  3215. return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
  3216. case WMI_TXE_NOTIFY_EVENTID:
  3217. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
  3218. return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
  3219. default:
  3220. ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
  3221. return -EINVAL;
  3222. }
  3223. return 0;
  3224. }
  3225. static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
  3226. {
  3227. struct wmi_cmd_hdr *cmd;
  3228. int ret = 0;
  3229. u32 len;
  3230. u16 id;
  3231. u8 if_idx;
  3232. u8 *datap;
  3233. cmd = (struct wmi_cmd_hdr *) skb->data;
  3234. id = le16_to_cpu(cmd->cmd_id);
  3235. if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
  3236. skb_pull(skb, sizeof(struct wmi_cmd_hdr));
  3237. datap = skb->data;
  3238. len = skb->len;
  3239. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
  3240. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
  3241. datap, len);
  3242. switch (id) {
  3243. case WMI_GET_BITRATE_CMDID:
  3244. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
  3245. ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
  3246. break;
  3247. case WMI_GET_CHANNEL_LIST_CMDID:
  3248. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
  3249. ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
  3250. break;
  3251. case WMI_GET_TX_PWR_CMDID:
  3252. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
  3253. ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
  3254. break;
  3255. case WMI_READY_EVENTID:
  3256. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
  3257. ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
  3258. break;
  3259. case WMI_PEER_NODE_EVENTID:
  3260. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
  3261. ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
  3262. break;
  3263. case WMI_REGDOMAIN_EVENTID:
  3264. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
  3265. ath6kl_wmi_regdomain_event(wmi, datap, len);
  3266. break;
  3267. case WMI_PSTREAM_TIMEOUT_EVENTID:
  3268. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
  3269. ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
  3270. break;
  3271. case WMI_CMDERROR_EVENTID:
  3272. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
  3273. ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
  3274. break;
  3275. case WMI_RSSI_THRESHOLD_EVENTID:
  3276. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
  3277. ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
  3278. break;
  3279. case WMI_ERROR_REPORT_EVENTID:
  3280. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
  3281. break;
  3282. case WMI_OPT_RX_FRAME_EVENTID:
  3283. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
  3284. /* this event has been deprecated */
  3285. break;
  3286. case WMI_REPORT_ROAM_TBL_EVENTID:
  3287. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
  3288. ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
  3289. break;
  3290. case WMI_EXTENSION_EVENTID:
  3291. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
  3292. ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
  3293. break;
  3294. case WMI_CHANNEL_CHANGE_EVENTID:
  3295. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
  3296. break;
  3297. case WMI_REPORT_ROAM_DATA_EVENTID:
  3298. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
  3299. break;
  3300. case WMI_TEST_EVENTID:
  3301. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
  3302. ret = ath6kl_wmi_test_rx(wmi, datap, len);
  3303. break;
  3304. case WMI_GET_FIXRATES_CMDID:
  3305. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
  3306. ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
  3307. break;
  3308. case WMI_TX_RETRY_ERR_EVENTID:
  3309. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
  3310. break;
  3311. case WMI_SNR_THRESHOLD_EVENTID:
  3312. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
  3313. ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
  3314. break;
  3315. case WMI_LQ_THRESHOLD_EVENTID:
  3316. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
  3317. break;
  3318. case WMI_APLIST_EVENTID:
  3319. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
  3320. ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
  3321. break;
  3322. case WMI_GET_KEEPALIVE_CMDID:
  3323. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
  3324. ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
  3325. break;
  3326. case WMI_GET_WOW_LIST_EVENTID:
  3327. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
  3328. break;
  3329. case WMI_GET_PMKID_LIST_EVENTID:
  3330. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
  3331. ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
  3332. break;
  3333. case WMI_SET_PARAMS_REPLY_EVENTID:
  3334. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
  3335. break;
  3336. case WMI_ADDBA_RESP_EVENTID:
  3337. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
  3338. break;
  3339. case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
  3340. ath6kl_dbg(ATH6KL_DBG_WMI,
  3341. "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
  3342. break;
  3343. case WMI_REPORT_BTCOEX_STATS_EVENTID:
  3344. ath6kl_dbg(ATH6KL_DBG_WMI,
  3345. "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
  3346. break;
  3347. case WMI_TX_COMPLETE_EVENTID:
  3348. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
  3349. ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
  3350. break;
  3351. case WMI_P2P_CAPABILITIES_EVENTID:
  3352. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
  3353. ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
  3354. break;
  3355. case WMI_P2P_INFO_EVENTID:
  3356. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
  3357. ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
  3358. break;
  3359. default:
  3360. /* may be the event is interface specific */
  3361. ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
  3362. break;
  3363. }
  3364. dev_kfree_skb(skb);
  3365. return ret;
  3366. }
  3367. /* Control Path */
  3368. int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
  3369. {
  3370. if (WARN_ON(skb == NULL))
  3371. return -EINVAL;
  3372. if (skb->len < sizeof(struct wmi_cmd_hdr)) {
  3373. ath6kl_err("bad packet 1\n");
  3374. dev_kfree_skb(skb);
  3375. return -EINVAL;
  3376. }
  3377. trace_ath6kl_wmi_event(skb->data, skb->len);
  3378. return ath6kl_wmi_proc_events(wmi, skb);
  3379. }
  3380. void ath6kl_wmi_reset(struct wmi *wmi)
  3381. {
  3382. spin_lock_bh(&wmi->lock);
  3383. wmi->fat_pipe_exist = 0;
  3384. memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
  3385. spin_unlock_bh(&wmi->lock);
  3386. }
  3387. void *ath6kl_wmi_init(struct ath6kl *dev)
  3388. {
  3389. struct wmi *wmi;
  3390. wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
  3391. if (!wmi)
  3392. return NULL;
  3393. spin_lock_init(&wmi->lock);
  3394. wmi->parent_dev = dev;
  3395. wmi->pwr_mode = REC_POWER;
  3396. ath6kl_wmi_reset(wmi);
  3397. return wmi;
  3398. }
  3399. void ath6kl_wmi_shutdown(struct wmi *wmi)
  3400. {
  3401. if (!wmi)
  3402. return;
  3403. kfree(wmi->last_mgmt_tx_frame);
  3404. kfree(wmi);
  3405. }