wmi.c 108 KB

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