wmi.c 108 KB

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