wmi.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166
  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 0:
  360. memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
  361. memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
  362. break;
  363. case IEEE80211_FCTL_TODS:
  364. memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
  365. memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
  366. break;
  367. case IEEE80211_FCTL_FROMDS:
  368. memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
  369. memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
  370. break;
  371. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  372. break;
  373. }
  374. skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
  375. skb_push(skb, sizeof(eth_hdr));
  376. datap = skb->data;
  377. memcpy(datap, &eth_hdr, sizeof(eth_hdr));
  378. return 0;
  379. }
  380. /*
  381. * Performs 802.3 to DIX encapsulation for received packets.
  382. * Assumes the entire 802.3 header is contiguous.
  383. */
  384. int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
  385. {
  386. struct ath6kl_llc_snap_hdr *llc_hdr;
  387. struct ethhdr eth_hdr;
  388. u8 *datap;
  389. if (WARN_ON(skb == NULL))
  390. return -EINVAL;
  391. datap = skb->data;
  392. memcpy(&eth_hdr, datap, sizeof(eth_hdr));
  393. llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
  394. eth_hdr.h_proto = llc_hdr->eth_type;
  395. skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
  396. datap = skb->data;
  397. memcpy(datap, &eth_hdr, sizeof(eth_hdr));
  398. return 0;
  399. }
  400. static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
  401. {
  402. struct tx_complete_msg_v1 *msg_v1;
  403. struct wmi_tx_complete_event *evt;
  404. int index;
  405. u16 size;
  406. evt = (struct wmi_tx_complete_event *) datap;
  407. ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
  408. evt->num_msg, evt->msg_len, evt->msg_type);
  409. for (index = 0; index < evt->num_msg; index++) {
  410. size = sizeof(struct wmi_tx_complete_event) +
  411. (index * sizeof(struct tx_complete_msg_v1));
  412. msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
  413. ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
  414. msg_v1->status, msg_v1->pkt_id,
  415. msg_v1->rate_idx, msg_v1->ack_failures);
  416. }
  417. return 0;
  418. }
  419. static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
  420. int len, struct ath6kl_vif *vif)
  421. {
  422. struct wmi_remain_on_chnl_event *ev;
  423. u32 freq;
  424. u32 dur;
  425. struct ieee80211_channel *chan;
  426. struct ath6kl *ar = wmi->parent_dev;
  427. u32 id;
  428. if (len < sizeof(*ev))
  429. return -EINVAL;
  430. ev = (struct wmi_remain_on_chnl_event *) datap;
  431. freq = le32_to_cpu(ev->freq);
  432. dur = le32_to_cpu(ev->duration);
  433. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
  434. freq, dur);
  435. chan = ieee80211_get_channel(ar->wiphy, freq);
  436. if (!chan) {
  437. ath6kl_dbg(ATH6KL_DBG_WMI,
  438. "remain_on_chnl: Unknown channel (freq=%u)\n",
  439. freq);
  440. return -EINVAL;
  441. }
  442. id = vif->last_roc_id;
  443. cfg80211_ready_on_channel(&vif->wdev, id, chan,
  444. dur, GFP_ATOMIC);
  445. return 0;
  446. }
  447. static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
  448. u8 *datap, int len,
  449. struct ath6kl_vif *vif)
  450. {
  451. struct wmi_cancel_remain_on_chnl_event *ev;
  452. u32 freq;
  453. u32 dur;
  454. struct ieee80211_channel *chan;
  455. struct ath6kl *ar = wmi->parent_dev;
  456. u32 id;
  457. if (len < sizeof(*ev))
  458. return -EINVAL;
  459. ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
  460. freq = le32_to_cpu(ev->freq);
  461. dur = le32_to_cpu(ev->duration);
  462. ath6kl_dbg(ATH6KL_DBG_WMI,
  463. "cancel_remain_on_chnl: freq=%u dur=%u status=%u\n",
  464. freq, dur, ev->status);
  465. chan = ieee80211_get_channel(ar->wiphy, freq);
  466. if (!chan) {
  467. ath6kl_dbg(ATH6KL_DBG_WMI,
  468. "cancel_remain_on_chnl: Unknown channel (freq=%u)\n",
  469. freq);
  470. return -EINVAL;
  471. }
  472. if (vif->last_cancel_roc_id &&
  473. vif->last_cancel_roc_id + 1 == vif->last_roc_id)
  474. id = vif->last_cancel_roc_id; /* event for cancel command */
  475. else
  476. id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
  477. vif->last_cancel_roc_id = 0;
  478. cfg80211_remain_on_channel_expired(&vif->wdev, id, chan, GFP_ATOMIC);
  479. return 0;
  480. }
  481. static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
  482. struct ath6kl_vif *vif)
  483. {
  484. struct wmi_tx_status_event *ev;
  485. u32 id;
  486. if (len < sizeof(*ev))
  487. return -EINVAL;
  488. ev = (struct wmi_tx_status_event *) datap;
  489. id = le32_to_cpu(ev->id);
  490. ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
  491. id, ev->ack_status);
  492. if (wmi->last_mgmt_tx_frame) {
  493. cfg80211_mgmt_tx_status(&vif->wdev, id,
  494. wmi->last_mgmt_tx_frame,
  495. wmi->last_mgmt_tx_frame_len,
  496. !!ev->ack_status, GFP_ATOMIC);
  497. kfree(wmi->last_mgmt_tx_frame);
  498. wmi->last_mgmt_tx_frame = NULL;
  499. wmi->last_mgmt_tx_frame_len = 0;
  500. }
  501. return 0;
  502. }
  503. static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  504. struct ath6kl_vif *vif)
  505. {
  506. struct wmi_p2p_rx_probe_req_event *ev;
  507. u32 freq;
  508. u16 dlen;
  509. if (len < sizeof(*ev))
  510. return -EINVAL;
  511. ev = (struct wmi_p2p_rx_probe_req_event *) datap;
  512. freq = le32_to_cpu(ev->freq);
  513. dlen = le16_to_cpu(ev->len);
  514. if (datap + len < ev->data + dlen) {
  515. ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n",
  516. len, dlen);
  517. return -EINVAL;
  518. }
  519. ath6kl_dbg(ATH6KL_DBG_WMI,
  520. "rx_probe_req: len=%u freq=%u probe_req_report=%d\n",
  521. dlen, freq, vif->probe_req_report);
  522. if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
  523. cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
  524. return 0;
  525. }
  526. static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
  527. {
  528. struct wmi_p2p_capabilities_event *ev;
  529. u16 dlen;
  530. if (len < sizeof(*ev))
  531. return -EINVAL;
  532. ev = (struct wmi_p2p_capabilities_event *) datap;
  533. dlen = le16_to_cpu(ev->len);
  534. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
  535. return 0;
  536. }
  537. static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
  538. struct ath6kl_vif *vif)
  539. {
  540. struct wmi_rx_action_event *ev;
  541. u32 freq;
  542. u16 dlen;
  543. if (len < sizeof(*ev))
  544. return -EINVAL;
  545. ev = (struct wmi_rx_action_event *) datap;
  546. freq = le32_to_cpu(ev->freq);
  547. dlen = le16_to_cpu(ev->len);
  548. if (datap + len < ev->data + dlen) {
  549. ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n",
  550. len, dlen);
  551. return -EINVAL;
  552. }
  553. ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
  554. cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
  555. return 0;
  556. }
  557. static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
  558. {
  559. struct wmi_p2p_info_event *ev;
  560. u32 flags;
  561. u16 dlen;
  562. if (len < sizeof(*ev))
  563. return -EINVAL;
  564. ev = (struct wmi_p2p_info_event *) datap;
  565. flags = le32_to_cpu(ev->info_req_flags);
  566. dlen = le16_to_cpu(ev->len);
  567. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
  568. if (flags & P2P_FLAG_CAPABILITIES_REQ) {
  569. struct wmi_p2p_capabilities *cap;
  570. if (dlen < sizeof(*cap))
  571. return -EINVAL;
  572. cap = (struct wmi_p2p_capabilities *) ev->data;
  573. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
  574. cap->go_power_save);
  575. }
  576. if (flags & P2P_FLAG_MACADDR_REQ) {
  577. struct wmi_p2p_macaddr *mac;
  578. if (dlen < sizeof(*mac))
  579. return -EINVAL;
  580. mac = (struct wmi_p2p_macaddr *) ev->data;
  581. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
  582. mac->mac_addr);
  583. }
  584. if (flags & P2P_FLAG_HMODEL_REQ) {
  585. struct wmi_p2p_hmodel *mod;
  586. if (dlen < sizeof(*mod))
  587. return -EINVAL;
  588. mod = (struct wmi_p2p_hmodel *) ev->data;
  589. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
  590. mod->p2p_model,
  591. mod->p2p_model ? "host" : "firmware");
  592. }
  593. return 0;
  594. }
  595. static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
  596. {
  597. struct sk_buff *skb;
  598. skb = ath6kl_buf_alloc(size);
  599. if (!skb)
  600. return NULL;
  601. skb_put(skb, size);
  602. if (size)
  603. memset(skb->data, 0, size);
  604. return skb;
  605. }
  606. /* Send a "simple" wmi command -- one with no arguments */
  607. static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
  608. enum wmi_cmd_id cmd_id)
  609. {
  610. struct sk_buff *skb;
  611. int ret;
  612. skb = ath6kl_wmi_get_new_buf(0);
  613. if (!skb)
  614. return -ENOMEM;
  615. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
  616. return ret;
  617. }
  618. static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
  619. {
  620. struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
  621. if (len < sizeof(struct wmi_ready_event_2))
  622. return -EINVAL;
  623. ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
  624. le32_to_cpu(ev->sw_version),
  625. le32_to_cpu(ev->abi_version), ev->phy_cap);
  626. return 0;
  627. }
  628. /*
  629. * Mechanism to modify the roaming behavior in the firmware. The lower rssi
  630. * at which the station has to roam can be passed with
  631. * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
  632. * in dBm.
  633. */
  634. int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
  635. {
  636. struct sk_buff *skb;
  637. struct roam_ctrl_cmd *cmd;
  638. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  639. if (!skb)
  640. return -ENOMEM;
  641. cmd = (struct roam_ctrl_cmd *) skb->data;
  642. cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
  643. cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
  644. DEF_SCAN_FOR_ROAM_INTVL);
  645. cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
  646. cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
  647. cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
  648. ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  649. NO_SYNC_WMIFLAG);
  650. return 0;
  651. }
  652. int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
  653. {
  654. struct sk_buff *skb;
  655. struct roam_ctrl_cmd *cmd;
  656. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  657. if (!skb)
  658. return -ENOMEM;
  659. cmd = (struct roam_ctrl_cmd *) skb->data;
  660. memcpy(cmd->info.bssid, bssid, ETH_ALEN);
  661. cmd->roam_ctrl = WMI_FORCE_ROAM;
  662. ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
  663. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  664. NO_SYNC_WMIFLAG);
  665. }
  666. int ath6kl_wmi_ap_set_beacon_intvl_cmd(struct wmi *wmi, u8 if_idx,
  667. u32 beacon_intvl)
  668. {
  669. struct sk_buff *skb;
  670. struct set_beacon_int_cmd *cmd;
  671. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  672. if (!skb)
  673. return -ENOMEM;
  674. cmd = (struct set_beacon_int_cmd *) skb->data;
  675. cmd->beacon_intvl = cpu_to_le32(beacon_intvl);
  676. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  677. WMI_SET_BEACON_INT_CMDID, NO_SYNC_WMIFLAG);
  678. }
  679. int ath6kl_wmi_ap_set_dtim_cmd(struct wmi *wmi, u8 if_idx, u32 dtim_period)
  680. {
  681. struct sk_buff *skb;
  682. struct set_dtim_cmd *cmd;
  683. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  684. if (!skb)
  685. return -ENOMEM;
  686. cmd = (struct set_dtim_cmd *) skb->data;
  687. cmd->dtim_period = cpu_to_le32(dtim_period);
  688. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  689. WMI_AP_SET_DTIM_CMDID, NO_SYNC_WMIFLAG);
  690. }
  691. int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
  692. {
  693. struct sk_buff *skb;
  694. struct roam_ctrl_cmd *cmd;
  695. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  696. if (!skb)
  697. return -ENOMEM;
  698. cmd = (struct roam_ctrl_cmd *) skb->data;
  699. cmd->info.roam_mode = mode;
  700. cmd->roam_ctrl = WMI_SET_ROAM_MODE;
  701. ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
  702. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  703. NO_SYNC_WMIFLAG);
  704. }
  705. static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
  706. struct ath6kl_vif *vif)
  707. {
  708. struct wmi_connect_event *ev;
  709. u8 *pie, *peie;
  710. if (len < sizeof(struct wmi_connect_event))
  711. return -EINVAL;
  712. ev = (struct wmi_connect_event *) datap;
  713. if (vif->nw_type == AP_NETWORK) {
  714. /* AP mode start/STA connected event */
  715. struct net_device *dev = vif->ndev;
  716. if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
  717. ath6kl_dbg(ATH6KL_DBG_WMI,
  718. "%s: freq %d bssid %pM (AP started)\n",
  719. __func__, le16_to_cpu(ev->u.ap_bss.ch),
  720. ev->u.ap_bss.bssid);
  721. ath6kl_connect_ap_mode_bss(
  722. vif, le16_to_cpu(ev->u.ap_bss.ch));
  723. } else {
  724. ath6kl_dbg(ATH6KL_DBG_WMI,
  725. "%s: aid %u mac_addr %pM auth=%u keymgmt=%u cipher=%u apsd_info=%u (STA connected)\n",
  726. __func__, ev->u.ap_sta.aid,
  727. ev->u.ap_sta.mac_addr,
  728. ev->u.ap_sta.auth,
  729. ev->u.ap_sta.keymgmt,
  730. le16_to_cpu(ev->u.ap_sta.cipher),
  731. ev->u.ap_sta.apsd_info);
  732. ath6kl_connect_ap_mode_sta(
  733. vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
  734. ev->u.ap_sta.keymgmt,
  735. le16_to_cpu(ev->u.ap_sta.cipher),
  736. ev->u.ap_sta.auth, ev->assoc_req_len,
  737. ev->assoc_info + ev->beacon_ie_len,
  738. ev->u.ap_sta.apsd_info);
  739. }
  740. return 0;
  741. }
  742. /* STA/IBSS mode connection event */
  743. ath6kl_dbg(ATH6KL_DBG_WMI,
  744. "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
  745. le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
  746. le16_to_cpu(ev->u.sta.listen_intvl),
  747. le16_to_cpu(ev->u.sta.beacon_intvl),
  748. le32_to_cpu(ev->u.sta.nw_type));
  749. /* Start of assoc rsp IEs */
  750. pie = ev->assoc_info + ev->beacon_ie_len +
  751. ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
  752. /* End of assoc rsp IEs */
  753. peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
  754. ev->assoc_resp_len;
  755. while (pie < peie) {
  756. switch (*pie) {
  757. case WLAN_EID_VENDOR_SPECIFIC:
  758. if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
  759. pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
  760. /* WMM OUT (00:50:F2) */
  761. if (pie[1] > 5 &&
  762. pie[6] == WMM_PARAM_OUI_SUBTYPE)
  763. wmi->is_wmm_enabled = true;
  764. }
  765. break;
  766. }
  767. if (wmi->is_wmm_enabled)
  768. break;
  769. pie += pie[1] + 2;
  770. }
  771. ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
  772. ev->u.sta.bssid,
  773. le16_to_cpu(ev->u.sta.listen_intvl),
  774. le16_to_cpu(ev->u.sta.beacon_intvl),
  775. le32_to_cpu(ev->u.sta.nw_type),
  776. ev->beacon_ie_len, ev->assoc_req_len,
  777. ev->assoc_resp_len, ev->assoc_info);
  778. return 0;
  779. }
  780. static struct country_code_to_enum_rd *
  781. ath6kl_regd_find_country(u16 countryCode)
  782. {
  783. int i;
  784. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  785. if (allCountries[i].countryCode == countryCode)
  786. return &allCountries[i];
  787. }
  788. return NULL;
  789. }
  790. static struct reg_dmn_pair_mapping *
  791. ath6kl_get_regpair(u16 regdmn)
  792. {
  793. int i;
  794. if (regdmn == NO_ENUMRD)
  795. return NULL;
  796. for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
  797. if (regDomainPairs[i].reg_domain == regdmn)
  798. return &regDomainPairs[i];
  799. }
  800. return NULL;
  801. }
  802. static struct country_code_to_enum_rd *
  803. ath6kl_regd_find_country_by_rd(u16 regdmn)
  804. {
  805. int i;
  806. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  807. if (allCountries[i].regDmnEnum == regdmn)
  808. return &allCountries[i];
  809. }
  810. return NULL;
  811. }
  812. static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
  813. {
  814. struct ath6kl_wmi_regdomain *ev;
  815. struct country_code_to_enum_rd *country = NULL;
  816. struct reg_dmn_pair_mapping *regpair = NULL;
  817. char alpha2[2];
  818. u32 reg_code;
  819. ev = (struct ath6kl_wmi_regdomain *) datap;
  820. reg_code = le32_to_cpu(ev->reg_code);
  821. if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG) {
  822. country = ath6kl_regd_find_country((u16) reg_code);
  823. } else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
  824. regpair = ath6kl_get_regpair((u16) reg_code);
  825. country = ath6kl_regd_find_country_by_rd((u16) reg_code);
  826. if (regpair)
  827. ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
  828. regpair->reg_domain);
  829. else
  830. ath6kl_warn("Regpair not found reg_code 0x%0x\n",
  831. reg_code);
  832. }
  833. if (country && wmi->parent_dev->wiphy_registered) {
  834. alpha2[0] = country->isoName[0];
  835. alpha2[1] = country->isoName[1];
  836. regulatory_hint(wmi->parent_dev->wiphy, alpha2);
  837. ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
  838. alpha2[0], alpha2[1]);
  839. }
  840. }
  841. static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
  842. struct ath6kl_vif *vif)
  843. {
  844. struct wmi_disconnect_event *ev;
  845. wmi->traffic_class = 100;
  846. if (len < sizeof(struct wmi_disconnect_event))
  847. return -EINVAL;
  848. ev = (struct wmi_disconnect_event *) datap;
  849. ath6kl_dbg(ATH6KL_DBG_WMI,
  850. "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
  851. le16_to_cpu(ev->proto_reason_status), ev->bssid,
  852. ev->disconn_reason, ev->assoc_resp_len);
  853. wmi->is_wmm_enabled = false;
  854. ath6kl_disconnect_event(vif, ev->disconn_reason,
  855. ev->bssid, ev->assoc_resp_len, ev->assoc_info,
  856. le16_to_cpu(ev->proto_reason_status));
  857. return 0;
  858. }
  859. static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
  860. {
  861. struct wmi_peer_node_event *ev;
  862. if (len < sizeof(struct wmi_peer_node_event))
  863. return -EINVAL;
  864. ev = (struct wmi_peer_node_event *) datap;
  865. if (ev->event_code == PEER_NODE_JOIN_EVENT)
  866. ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
  867. ev->peer_mac_addr);
  868. else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
  869. ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
  870. ev->peer_mac_addr);
  871. return 0;
  872. }
  873. static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
  874. struct ath6kl_vif *vif)
  875. {
  876. struct wmi_tkip_micerr_event *ev;
  877. if (len < sizeof(struct wmi_tkip_micerr_event))
  878. return -EINVAL;
  879. ev = (struct wmi_tkip_micerr_event *) datap;
  880. ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
  881. return 0;
  882. }
  883. void ath6kl_wmi_sscan_timer(unsigned long ptr)
  884. {
  885. struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
  886. cfg80211_sched_scan_results(vif->ar->wiphy);
  887. }
  888. static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
  889. struct ath6kl_vif *vif)
  890. {
  891. struct wmi_bss_info_hdr2 *bih;
  892. u8 *buf;
  893. struct ieee80211_channel *channel;
  894. struct ath6kl *ar = wmi->parent_dev;
  895. struct cfg80211_bss *bss;
  896. if (len <= sizeof(struct wmi_bss_info_hdr2))
  897. return -EINVAL;
  898. bih = (struct wmi_bss_info_hdr2 *) datap;
  899. buf = datap + sizeof(struct wmi_bss_info_hdr2);
  900. len -= sizeof(struct wmi_bss_info_hdr2);
  901. ath6kl_dbg(ATH6KL_DBG_WMI,
  902. "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
  903. "frame_type=%d\n",
  904. bih->ch, bih->snr, bih->snr - 95, bih->bssid,
  905. bih->frame_type);
  906. if (bih->frame_type != BEACON_FTYPE &&
  907. bih->frame_type != PROBERESP_FTYPE)
  908. return 0; /* Only update BSS table for now */
  909. if (bih->frame_type == BEACON_FTYPE &&
  910. test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
  911. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  912. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  913. NONE_BSS_FILTER, 0);
  914. }
  915. channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
  916. if (channel == NULL)
  917. return -EINVAL;
  918. if (len < 8 + 2 + 2)
  919. return -EINVAL;
  920. if (bih->frame_type == BEACON_FTYPE &&
  921. test_bit(CONNECTED, &vif->flags) &&
  922. memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
  923. const u8 *tim;
  924. tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
  925. len - 8 - 2 - 2);
  926. if (tim && tim[1] >= 2) {
  927. vif->assoc_bss_dtim_period = tim[3];
  928. set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
  929. }
  930. }
  931. bss = cfg80211_inform_bss(ar->wiphy, channel,
  932. bih->frame_type == BEACON_FTYPE ?
  933. CFG80211_BSS_FTYPE_BEACON :
  934. CFG80211_BSS_FTYPE_PRESP,
  935. bih->bssid, get_unaligned_le64((__le64 *)buf),
  936. get_unaligned_le16(((__le16 *)buf) + 5),
  937. get_unaligned_le16(((__le16 *)buf) + 4),
  938. buf + 8 + 2 + 2, len - 8 - 2 - 2,
  939. (bih->snr - 95) * 100, GFP_ATOMIC);
  940. if (bss == NULL)
  941. return -ENOMEM;
  942. cfg80211_put_bss(ar->wiphy, bss);
  943. /*
  944. * Firmware doesn't return any event when scheduled scan has
  945. * finished, so we need to use a timer to find out when there are
  946. * no more results.
  947. *
  948. * The timer is started from the first bss info received, otherwise
  949. * the timer would not ever fire if the scan interval is short
  950. * enough.
  951. */
  952. if (test_bit(SCHED_SCANNING, &vif->flags) &&
  953. !timer_pending(&vif->sched_scan_timer)) {
  954. mod_timer(&vif->sched_scan_timer, jiffies +
  955. msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
  956. }
  957. return 0;
  958. }
  959. /* Inactivity timeout of a fatpipe(pstream) at the target */
  960. static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
  961. int len)
  962. {
  963. struct wmi_pstream_timeout_event *ev;
  964. if (len < sizeof(struct wmi_pstream_timeout_event))
  965. return -EINVAL;
  966. ev = (struct wmi_pstream_timeout_event *) datap;
  967. /*
  968. * When the pstream (fat pipe == AC) timesout, it means there were
  969. * no thinStreams within this pstream & it got implicitly created
  970. * due to data flow on this AC. We start the inactivity timer only
  971. * for implicitly created pstream. Just reset the host state.
  972. */
  973. spin_lock_bh(&wmi->lock);
  974. wmi->stream_exist_for_ac[ev->traffic_class] = 0;
  975. wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
  976. spin_unlock_bh(&wmi->lock);
  977. /* Indicate inactivity to driver layer for this fatpipe (pstream) */
  978. ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
  979. return 0;
  980. }
  981. static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
  982. {
  983. struct wmi_bit_rate_reply *reply;
  984. s32 rate;
  985. u32 sgi, index;
  986. if (len < sizeof(struct wmi_bit_rate_reply))
  987. return -EINVAL;
  988. reply = (struct wmi_bit_rate_reply *) datap;
  989. ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
  990. if (reply->rate_index == (s8) RATE_AUTO) {
  991. rate = RATE_AUTO;
  992. } else {
  993. index = reply->rate_index & 0x7f;
  994. if (WARN_ON_ONCE(index > (RATE_MCS_7_40 + 1)))
  995. return -EINVAL;
  996. sgi = (reply->rate_index & 0x80) ? 1 : 0;
  997. rate = wmi_rate_tbl[index][sgi];
  998. }
  999. ath6kl_wakeup_event(wmi->parent_dev);
  1000. return 0;
  1001. }
  1002. static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
  1003. {
  1004. ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
  1005. return 0;
  1006. }
  1007. static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1008. {
  1009. if (len < sizeof(struct wmi_fix_rates_reply))
  1010. return -EINVAL;
  1011. ath6kl_wakeup_event(wmi->parent_dev);
  1012. return 0;
  1013. }
  1014. static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1015. {
  1016. if (len < sizeof(struct wmi_channel_list_reply))
  1017. return -EINVAL;
  1018. ath6kl_wakeup_event(wmi->parent_dev);
  1019. return 0;
  1020. }
  1021. static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1022. {
  1023. struct wmi_tx_pwr_reply *reply;
  1024. if (len < sizeof(struct wmi_tx_pwr_reply))
  1025. return -EINVAL;
  1026. reply = (struct wmi_tx_pwr_reply *) datap;
  1027. ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
  1028. return 0;
  1029. }
  1030. static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1031. {
  1032. if (len < sizeof(struct wmi_get_keepalive_cmd))
  1033. return -EINVAL;
  1034. ath6kl_wakeup_event(wmi->parent_dev);
  1035. return 0;
  1036. }
  1037. static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
  1038. struct ath6kl_vif *vif)
  1039. {
  1040. struct wmi_scan_complete_event *ev;
  1041. ev = (struct wmi_scan_complete_event *) datap;
  1042. ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
  1043. wmi->is_probe_ssid = false;
  1044. return 0;
  1045. }
  1046. static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
  1047. int len, struct ath6kl_vif *vif)
  1048. {
  1049. struct wmi_neighbor_report_event *ev;
  1050. u8 i;
  1051. if (len < sizeof(*ev))
  1052. return -EINVAL;
  1053. ev = (struct wmi_neighbor_report_event *) datap;
  1054. if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
  1055. > len) {
  1056. ath6kl_dbg(ATH6KL_DBG_WMI,
  1057. "truncated neighbor event (num=%d len=%d)\n",
  1058. ev->num_neighbors, len);
  1059. return -EINVAL;
  1060. }
  1061. for (i = 0; i < ev->num_neighbors; i++) {
  1062. ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
  1063. i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
  1064. ev->neighbor[i].bss_flags);
  1065. cfg80211_pmksa_candidate_notify(vif->ndev, i,
  1066. ev->neighbor[i].bssid,
  1067. !!(ev->neighbor[i].bss_flags &
  1068. WMI_PREAUTH_CAPABLE_BSS),
  1069. GFP_ATOMIC);
  1070. }
  1071. return 0;
  1072. }
  1073. /*
  1074. * Target is reporting a programming error. This is for
  1075. * developer aid only. Target only checks a few common violations
  1076. * and it is responsibility of host to do all error checking.
  1077. * Behavior of target after wmi error event is undefined.
  1078. * A reset is recommended.
  1079. */
  1080. static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
  1081. {
  1082. const char *type = "unknown error";
  1083. struct wmi_cmd_error_event *ev;
  1084. ev = (struct wmi_cmd_error_event *) datap;
  1085. switch (ev->err_code) {
  1086. case INVALID_PARAM:
  1087. type = "invalid parameter";
  1088. break;
  1089. case ILLEGAL_STATE:
  1090. type = "invalid state";
  1091. break;
  1092. case INTERNAL_ERROR:
  1093. type = "internal error";
  1094. break;
  1095. }
  1096. ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
  1097. ev->cmd_id, type);
  1098. return 0;
  1099. }
  1100. static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
  1101. struct ath6kl_vif *vif)
  1102. {
  1103. ath6kl_tgt_stats_event(vif, datap, len);
  1104. return 0;
  1105. }
  1106. static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
  1107. struct sq_threshold_params *sq_thresh,
  1108. u32 size)
  1109. {
  1110. u32 index;
  1111. u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
  1112. /* The list is already in sorted order. Get the next lower value */
  1113. for (index = 0; index < size; index++) {
  1114. if (rssi < sq_thresh->upper_threshold[index]) {
  1115. threshold = (u8) sq_thresh->upper_threshold[index];
  1116. break;
  1117. }
  1118. }
  1119. return threshold;
  1120. }
  1121. static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
  1122. struct sq_threshold_params *sq_thresh,
  1123. u32 size)
  1124. {
  1125. u32 index;
  1126. u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
  1127. /* The list is already in sorted order. Get the next lower value */
  1128. for (index = 0; index < size; index++) {
  1129. if (rssi > sq_thresh->lower_threshold[index]) {
  1130. threshold = (u8) sq_thresh->lower_threshold[index];
  1131. break;
  1132. }
  1133. }
  1134. return threshold;
  1135. }
  1136. static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
  1137. struct wmi_rssi_threshold_params_cmd *rssi_cmd)
  1138. {
  1139. struct sk_buff *skb;
  1140. struct wmi_rssi_threshold_params_cmd *cmd;
  1141. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1142. if (!skb)
  1143. return -ENOMEM;
  1144. cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
  1145. memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
  1146. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
  1147. NO_SYNC_WMIFLAG);
  1148. }
  1149. static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
  1150. int len)
  1151. {
  1152. struct wmi_rssi_threshold_event *reply;
  1153. struct wmi_rssi_threshold_params_cmd cmd;
  1154. struct sq_threshold_params *sq_thresh;
  1155. enum wmi_rssi_threshold_val new_threshold;
  1156. u8 upper_rssi_threshold, lower_rssi_threshold;
  1157. s16 rssi;
  1158. int ret;
  1159. if (len < sizeof(struct wmi_rssi_threshold_event))
  1160. return -EINVAL;
  1161. reply = (struct wmi_rssi_threshold_event *) datap;
  1162. new_threshold = (enum wmi_rssi_threshold_val) reply->range;
  1163. rssi = a_sle16_to_cpu(reply->rssi);
  1164. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
  1165. /*
  1166. * Identify the threshold breached and communicate that to the app.
  1167. * After that install a new set of thresholds based on the signal
  1168. * quality reported by the target
  1169. */
  1170. if (new_threshold) {
  1171. /* Upper threshold breached */
  1172. if (rssi < sq_thresh->upper_threshold[0]) {
  1173. ath6kl_dbg(ATH6KL_DBG_WMI,
  1174. "spurious upper rssi threshold event: %d\n",
  1175. rssi);
  1176. } else if ((rssi < sq_thresh->upper_threshold[1]) &&
  1177. (rssi >= sq_thresh->upper_threshold[0])) {
  1178. new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
  1179. } else if ((rssi < sq_thresh->upper_threshold[2]) &&
  1180. (rssi >= sq_thresh->upper_threshold[1])) {
  1181. new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
  1182. } else if ((rssi < sq_thresh->upper_threshold[3]) &&
  1183. (rssi >= sq_thresh->upper_threshold[2])) {
  1184. new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
  1185. } else if ((rssi < sq_thresh->upper_threshold[4]) &&
  1186. (rssi >= sq_thresh->upper_threshold[3])) {
  1187. new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
  1188. } else if ((rssi < sq_thresh->upper_threshold[5]) &&
  1189. (rssi >= sq_thresh->upper_threshold[4])) {
  1190. new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
  1191. } else if (rssi >= sq_thresh->upper_threshold[5]) {
  1192. new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
  1193. }
  1194. } else {
  1195. /* Lower threshold breached */
  1196. if (rssi > sq_thresh->lower_threshold[0]) {
  1197. ath6kl_dbg(ATH6KL_DBG_WMI,
  1198. "spurious lower rssi threshold event: %d %d\n",
  1199. rssi, sq_thresh->lower_threshold[0]);
  1200. } else if ((rssi > sq_thresh->lower_threshold[1]) &&
  1201. (rssi <= sq_thresh->lower_threshold[0])) {
  1202. new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
  1203. } else if ((rssi > sq_thresh->lower_threshold[2]) &&
  1204. (rssi <= sq_thresh->lower_threshold[1])) {
  1205. new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
  1206. } else if ((rssi > sq_thresh->lower_threshold[3]) &&
  1207. (rssi <= sq_thresh->lower_threshold[2])) {
  1208. new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
  1209. } else if ((rssi > sq_thresh->lower_threshold[4]) &&
  1210. (rssi <= sq_thresh->lower_threshold[3])) {
  1211. new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
  1212. } else if ((rssi > sq_thresh->lower_threshold[5]) &&
  1213. (rssi <= sq_thresh->lower_threshold[4])) {
  1214. new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
  1215. } else if (rssi <= sq_thresh->lower_threshold[5]) {
  1216. new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
  1217. }
  1218. }
  1219. /* Calculate and install the next set of thresholds */
  1220. lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
  1221. sq_thresh->lower_threshold_valid_count);
  1222. upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
  1223. sq_thresh->upper_threshold_valid_count);
  1224. /* Issue a wmi command to install the thresholds */
  1225. cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
  1226. cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
  1227. cmd.weight = sq_thresh->weight;
  1228. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1229. ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
  1230. if (ret) {
  1231. ath6kl_err("unable to configure rssi thresholds\n");
  1232. return -EIO;
  1233. }
  1234. return 0;
  1235. }
  1236. static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
  1237. struct ath6kl_vif *vif)
  1238. {
  1239. struct wmi_cac_event *reply;
  1240. struct ieee80211_tspec_ie *ts;
  1241. u16 active_tsids, tsinfo;
  1242. u8 tsid, index;
  1243. u8 ts_id;
  1244. if (len < sizeof(struct wmi_cac_event))
  1245. return -EINVAL;
  1246. reply = (struct wmi_cac_event *) datap;
  1247. if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
  1248. (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
  1249. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1250. tsinfo = le16_to_cpu(ts->tsinfo);
  1251. tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1252. IEEE80211_WMM_IE_TSPEC_TID_MASK;
  1253. ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
  1254. reply->ac, tsid);
  1255. } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
  1256. /*
  1257. * Following assumes that there is only one outstanding
  1258. * ADDTS request when this event is received
  1259. */
  1260. spin_lock_bh(&wmi->lock);
  1261. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1262. spin_unlock_bh(&wmi->lock);
  1263. for (index = 0; index < sizeof(active_tsids) * 8; index++) {
  1264. if ((active_tsids >> index) & 1)
  1265. break;
  1266. }
  1267. if (index < (sizeof(active_tsids) * 8))
  1268. ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
  1269. reply->ac, index);
  1270. }
  1271. /*
  1272. * Clear active tsids and Add missing handling
  1273. * for delete qos stream from AP
  1274. */
  1275. else if (reply->cac_indication == CAC_INDICATION_DELETE) {
  1276. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1277. tsinfo = le16_to_cpu(ts->tsinfo);
  1278. ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1279. IEEE80211_WMM_IE_TSPEC_TID_MASK);
  1280. spin_lock_bh(&wmi->lock);
  1281. wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
  1282. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1283. spin_unlock_bh(&wmi->lock);
  1284. /* Indicate stream inactivity to driver layer only if all tsids
  1285. * within this AC are deleted.
  1286. */
  1287. if (!active_tsids) {
  1288. ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
  1289. false);
  1290. wmi->fat_pipe_exist &= ~(1 << reply->ac);
  1291. }
  1292. }
  1293. return 0;
  1294. }
  1295. static int ath6kl_wmi_txe_notify_event_rx(struct wmi *wmi, u8 *datap, int len,
  1296. struct ath6kl_vif *vif)
  1297. {
  1298. struct wmi_txe_notify_event *ev;
  1299. u32 rate, pkts;
  1300. if (len < sizeof(*ev))
  1301. return -EINVAL;
  1302. if (vif->sme_state != SME_CONNECTED)
  1303. return -ENOTCONN;
  1304. ev = (struct wmi_txe_notify_event *) datap;
  1305. rate = le32_to_cpu(ev->rate);
  1306. pkts = le32_to_cpu(ev->pkts);
  1307. ath6kl_dbg(ATH6KL_DBG_WMI, "TXE notify event: peer %pM rate %d% pkts %d intvl %ds\n",
  1308. vif->bssid, rate, pkts, vif->txe_intvl);
  1309. cfg80211_cqm_txe_notify(vif->ndev, vif->bssid, pkts,
  1310. rate, vif->txe_intvl, GFP_KERNEL);
  1311. return 0;
  1312. }
  1313. int ath6kl_wmi_set_txe_notify(struct wmi *wmi, u8 idx,
  1314. u32 rate, u32 pkts, u32 intvl)
  1315. {
  1316. struct sk_buff *skb;
  1317. struct wmi_txe_notify_cmd *cmd;
  1318. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1319. if (!skb)
  1320. return -ENOMEM;
  1321. cmd = (struct wmi_txe_notify_cmd *) skb->data;
  1322. cmd->rate = cpu_to_le32(rate);
  1323. cmd->pkts = cpu_to_le32(pkts);
  1324. cmd->intvl = cpu_to_le32(intvl);
  1325. return ath6kl_wmi_cmd_send(wmi, idx, skb, WMI_SET_TXE_NOTIFY_CMDID,
  1326. NO_SYNC_WMIFLAG);
  1327. }
  1328. int ath6kl_wmi_set_rssi_filter_cmd(struct wmi *wmi, u8 if_idx, s8 rssi)
  1329. {
  1330. struct sk_buff *skb;
  1331. struct wmi_set_rssi_filter_cmd *cmd;
  1332. int ret;
  1333. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1334. if (!skb)
  1335. return -ENOMEM;
  1336. cmd = (struct wmi_set_rssi_filter_cmd *) skb->data;
  1337. cmd->rssi = rssi;
  1338. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_RSSI_FILTER_CMDID,
  1339. NO_SYNC_WMIFLAG);
  1340. return ret;
  1341. }
  1342. static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
  1343. struct wmi_snr_threshold_params_cmd *snr_cmd)
  1344. {
  1345. struct sk_buff *skb;
  1346. struct wmi_snr_threshold_params_cmd *cmd;
  1347. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1348. if (!skb)
  1349. return -ENOMEM;
  1350. cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
  1351. memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
  1352. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
  1353. NO_SYNC_WMIFLAG);
  1354. }
  1355. static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
  1356. int len)
  1357. {
  1358. struct wmi_snr_threshold_event *reply;
  1359. struct sq_threshold_params *sq_thresh;
  1360. struct wmi_snr_threshold_params_cmd cmd;
  1361. enum wmi_snr_threshold_val new_threshold;
  1362. u8 upper_snr_threshold, lower_snr_threshold;
  1363. s16 snr;
  1364. int ret;
  1365. if (len < sizeof(struct wmi_snr_threshold_event))
  1366. return -EINVAL;
  1367. reply = (struct wmi_snr_threshold_event *) datap;
  1368. new_threshold = (enum wmi_snr_threshold_val) reply->range;
  1369. snr = reply->snr;
  1370. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
  1371. /*
  1372. * Identify the threshold breached and communicate that to the app.
  1373. * After that install a new set of thresholds based on the signal
  1374. * quality reported by the target.
  1375. */
  1376. if (new_threshold) {
  1377. /* Upper threshold breached */
  1378. if (snr < sq_thresh->upper_threshold[0]) {
  1379. ath6kl_dbg(ATH6KL_DBG_WMI,
  1380. "spurious upper snr threshold event: %d\n",
  1381. snr);
  1382. } else if ((snr < sq_thresh->upper_threshold[1]) &&
  1383. (snr >= sq_thresh->upper_threshold[0])) {
  1384. new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
  1385. } else if ((snr < sq_thresh->upper_threshold[2]) &&
  1386. (snr >= sq_thresh->upper_threshold[1])) {
  1387. new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
  1388. } else if ((snr < sq_thresh->upper_threshold[3]) &&
  1389. (snr >= sq_thresh->upper_threshold[2])) {
  1390. new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
  1391. } else if (snr >= sq_thresh->upper_threshold[3]) {
  1392. new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
  1393. }
  1394. } else {
  1395. /* Lower threshold breached */
  1396. if (snr > sq_thresh->lower_threshold[0]) {
  1397. ath6kl_dbg(ATH6KL_DBG_WMI,
  1398. "spurious lower snr threshold event: %d\n",
  1399. sq_thresh->lower_threshold[0]);
  1400. } else if ((snr > sq_thresh->lower_threshold[1]) &&
  1401. (snr <= sq_thresh->lower_threshold[0])) {
  1402. new_threshold = WMI_SNR_THRESHOLD4_BELOW;
  1403. } else if ((snr > sq_thresh->lower_threshold[2]) &&
  1404. (snr <= sq_thresh->lower_threshold[1])) {
  1405. new_threshold = WMI_SNR_THRESHOLD3_BELOW;
  1406. } else if ((snr > sq_thresh->lower_threshold[3]) &&
  1407. (snr <= sq_thresh->lower_threshold[2])) {
  1408. new_threshold = WMI_SNR_THRESHOLD2_BELOW;
  1409. } else if (snr <= sq_thresh->lower_threshold[3]) {
  1410. new_threshold = WMI_SNR_THRESHOLD1_BELOW;
  1411. }
  1412. }
  1413. /* Calculate and install the next set of thresholds */
  1414. lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
  1415. sq_thresh->lower_threshold_valid_count);
  1416. upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
  1417. sq_thresh->upper_threshold_valid_count);
  1418. /* Issue a wmi command to install the thresholds */
  1419. cmd.thresh_above1_val = upper_snr_threshold;
  1420. cmd.thresh_below1_val = lower_snr_threshold;
  1421. cmd.weight = sq_thresh->weight;
  1422. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1423. ath6kl_dbg(ATH6KL_DBG_WMI,
  1424. "snr: %d, threshold: %d, lower: %d, upper: %d\n",
  1425. snr, new_threshold,
  1426. lower_snr_threshold, upper_snr_threshold);
  1427. ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
  1428. if (ret) {
  1429. ath6kl_err("unable to configure snr threshold\n");
  1430. return -EIO;
  1431. }
  1432. return 0;
  1433. }
  1434. static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
  1435. {
  1436. u16 ap_info_entry_size;
  1437. struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
  1438. struct wmi_ap_info_v1 *ap_info_v1;
  1439. u8 index;
  1440. if (len < sizeof(struct wmi_aplist_event) ||
  1441. ev->ap_list_ver != APLIST_VER1)
  1442. return -EINVAL;
  1443. ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
  1444. ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
  1445. ath6kl_dbg(ATH6KL_DBG_WMI,
  1446. "number of APs in aplist event: %d\n", ev->num_ap);
  1447. if (len < (int) (sizeof(struct wmi_aplist_event) +
  1448. (ev->num_ap - 1) * ap_info_entry_size))
  1449. return -EINVAL;
  1450. /* AP list version 1 contents */
  1451. for (index = 0; index < ev->num_ap; index++) {
  1452. ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
  1453. index, ap_info_v1->bssid, ap_info_v1->channel);
  1454. ap_info_v1++;
  1455. }
  1456. return 0;
  1457. }
  1458. int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
  1459. enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
  1460. {
  1461. struct wmi_cmd_hdr *cmd_hdr;
  1462. enum htc_endpoint_id ep_id = wmi->ep_id;
  1463. int ret;
  1464. u16 info1;
  1465. if (WARN_ON(skb == NULL ||
  1466. (if_idx > (wmi->parent_dev->vif_max - 1)))) {
  1467. dev_kfree_skb(skb);
  1468. return -EINVAL;
  1469. }
  1470. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
  1471. cmd_id, skb->len, sync_flag);
  1472. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
  1473. skb->data, skb->len);
  1474. if (sync_flag >= END_WMIFLAG) {
  1475. dev_kfree_skb(skb);
  1476. return -EINVAL;
  1477. }
  1478. if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
  1479. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1480. /*
  1481. * Make sure all data currently queued is transmitted before
  1482. * the cmd execution. Establish a new sync point.
  1483. */
  1484. ath6kl_wmi_sync_point(wmi, if_idx);
  1485. }
  1486. skb_push(skb, sizeof(struct wmi_cmd_hdr));
  1487. cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
  1488. cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
  1489. info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
  1490. cmd_hdr->info1 = cpu_to_le16(info1);
  1491. /* Only for OPT_TX_CMD, use BE endpoint. */
  1492. if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
  1493. ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
  1494. false, false, 0, NULL, if_idx);
  1495. if (ret) {
  1496. dev_kfree_skb(skb);
  1497. return ret;
  1498. }
  1499. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
  1500. }
  1501. ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1502. if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
  1503. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1504. /*
  1505. * Make sure all new data queued waits for the command to
  1506. * execute. Establish a new sync point.
  1507. */
  1508. ath6kl_wmi_sync_point(wmi, if_idx);
  1509. }
  1510. return 0;
  1511. }
  1512. int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
  1513. enum network_type nw_type,
  1514. enum dot11_auth_mode dot11_auth_mode,
  1515. enum auth_mode auth_mode,
  1516. enum crypto_type pairwise_crypto,
  1517. u8 pairwise_crypto_len,
  1518. enum crypto_type group_crypto,
  1519. u8 group_crypto_len, int ssid_len, u8 *ssid,
  1520. u8 *bssid, u16 channel, u32 ctrl_flags,
  1521. u8 nw_subtype)
  1522. {
  1523. struct sk_buff *skb;
  1524. struct wmi_connect_cmd *cc;
  1525. int ret;
  1526. ath6kl_dbg(ATH6KL_DBG_WMI,
  1527. "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
  1528. "type %d dot11_auth %d auth %d pairwise %d group %d\n",
  1529. bssid, channel, ctrl_flags, ssid_len, nw_type,
  1530. dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
  1531. ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
  1532. wmi->traffic_class = 100;
  1533. if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
  1534. return -EINVAL;
  1535. if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
  1536. return -EINVAL;
  1537. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
  1538. if (!skb)
  1539. return -ENOMEM;
  1540. cc = (struct wmi_connect_cmd *) skb->data;
  1541. if (ssid_len)
  1542. memcpy(cc->ssid, ssid, ssid_len);
  1543. cc->ssid_len = ssid_len;
  1544. cc->nw_type = nw_type;
  1545. cc->dot11_auth_mode = dot11_auth_mode;
  1546. cc->auth_mode = auth_mode;
  1547. cc->prwise_crypto_type = pairwise_crypto;
  1548. cc->prwise_crypto_len = pairwise_crypto_len;
  1549. cc->grp_crypto_type = group_crypto;
  1550. cc->grp_crypto_len = group_crypto_len;
  1551. cc->ch = cpu_to_le16(channel);
  1552. cc->ctrl_flags = cpu_to_le32(ctrl_flags);
  1553. cc->nw_subtype = nw_subtype;
  1554. if (bssid != NULL)
  1555. memcpy(cc->bssid, bssid, ETH_ALEN);
  1556. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
  1557. NO_SYNC_WMIFLAG);
  1558. return ret;
  1559. }
  1560. int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
  1561. u16 channel)
  1562. {
  1563. struct sk_buff *skb;
  1564. struct wmi_reconnect_cmd *cc;
  1565. int ret;
  1566. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
  1567. bssid, channel);
  1568. wmi->traffic_class = 100;
  1569. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
  1570. if (!skb)
  1571. return -ENOMEM;
  1572. cc = (struct wmi_reconnect_cmd *) skb->data;
  1573. cc->channel = cpu_to_le16(channel);
  1574. if (bssid != NULL)
  1575. memcpy(cc->bssid, bssid, ETH_ALEN);
  1576. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
  1577. NO_SYNC_WMIFLAG);
  1578. return ret;
  1579. }
  1580. int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
  1581. {
  1582. int ret;
  1583. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
  1584. wmi->traffic_class = 100;
  1585. /* Disconnect command does not need to do a SYNC before. */
  1586. ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
  1587. return ret;
  1588. }
  1589. /* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
  1590. * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
  1591. * mgmt operations using station interface.
  1592. */
  1593. static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
  1594. enum wmi_scan_type scan_type,
  1595. u32 force_fgscan, u32 is_legacy,
  1596. u32 home_dwell_time,
  1597. u32 force_scan_interval,
  1598. s8 num_chan, u16 *ch_list)
  1599. {
  1600. struct sk_buff *skb;
  1601. struct wmi_start_scan_cmd *sc;
  1602. s8 size;
  1603. int i, ret;
  1604. size = sizeof(struct wmi_start_scan_cmd);
  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. if (num_chan)
  1610. size += sizeof(u16) * (num_chan - 1);
  1611. skb = ath6kl_wmi_get_new_buf(size);
  1612. if (!skb)
  1613. return -ENOMEM;
  1614. sc = (struct wmi_start_scan_cmd *) skb->data;
  1615. sc->scan_type = scan_type;
  1616. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1617. sc->is_legacy = cpu_to_le32(is_legacy);
  1618. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1619. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1620. sc->num_ch = num_chan;
  1621. for (i = 0; i < num_chan; i++)
  1622. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1623. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
  1624. NO_SYNC_WMIFLAG);
  1625. return ret;
  1626. }
  1627. /*
  1628. * beginscan supports (compared to old startscan) P2P mgmt operations using
  1629. * station interface, send additional information like supported rates to
  1630. * advertise and xmit rates for probe requests
  1631. */
  1632. int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
  1633. enum wmi_scan_type scan_type,
  1634. u32 force_fgscan, u32 is_legacy,
  1635. u32 home_dwell_time, u32 force_scan_interval,
  1636. s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
  1637. {
  1638. struct ieee80211_supported_band *sband;
  1639. struct sk_buff *skb;
  1640. struct wmi_begin_scan_cmd *sc;
  1641. s8 size, *supp_rates;
  1642. int i, band, ret;
  1643. struct ath6kl *ar = wmi->parent_dev;
  1644. int num_rates;
  1645. u32 ratemask;
  1646. if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  1647. ar->fw_capabilities)) {
  1648. return ath6kl_wmi_startscan_cmd(wmi, if_idx,
  1649. scan_type, force_fgscan,
  1650. is_legacy, home_dwell_time,
  1651. force_scan_interval,
  1652. num_chan, ch_list);
  1653. }
  1654. size = sizeof(struct wmi_begin_scan_cmd);
  1655. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1656. return -EINVAL;
  1657. if (num_chan > WMI_MAX_CHANNELS)
  1658. return -EINVAL;
  1659. if (num_chan)
  1660. size += sizeof(u16) * (num_chan - 1);
  1661. skb = ath6kl_wmi_get_new_buf(size);
  1662. if (!skb)
  1663. return -ENOMEM;
  1664. sc = (struct wmi_begin_scan_cmd *) skb->data;
  1665. sc->scan_type = scan_type;
  1666. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1667. sc->is_legacy = cpu_to_le32(is_legacy);
  1668. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1669. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1670. sc->no_cck = cpu_to_le32(no_cck);
  1671. sc->num_ch = num_chan;
  1672. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1673. sband = ar->wiphy->bands[band];
  1674. if (!sband)
  1675. continue;
  1676. if (WARN_ON(band >= ATH6KL_NUM_BANDS))
  1677. break;
  1678. ratemask = rates[band];
  1679. supp_rates = sc->supp_rates[band].rates;
  1680. num_rates = 0;
  1681. for (i = 0; i < sband->n_bitrates; i++) {
  1682. if ((BIT(i) & ratemask) == 0)
  1683. continue; /* skip rate */
  1684. supp_rates[num_rates++] =
  1685. (u8) (sband->bitrates[i].bitrate / 5);
  1686. }
  1687. sc->supp_rates[band].nrates = num_rates;
  1688. }
  1689. for (i = 0; i < num_chan; i++)
  1690. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1691. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
  1692. NO_SYNC_WMIFLAG);
  1693. return ret;
  1694. }
  1695. int ath6kl_wmi_enable_sched_scan_cmd(struct wmi *wmi, u8 if_idx, bool enable)
  1696. {
  1697. struct sk_buff *skb;
  1698. struct wmi_enable_sched_scan_cmd *sc;
  1699. int ret;
  1700. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1701. if (!skb)
  1702. return -ENOMEM;
  1703. ath6kl_dbg(ATH6KL_DBG_WMI, "%s scheduled scan on vif %d\n",
  1704. enable ? "enabling" : "disabling", if_idx);
  1705. sc = (struct wmi_enable_sched_scan_cmd *) skb->data;
  1706. sc->enable = enable ? 1 : 0;
  1707. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  1708. WMI_ENABLE_SCHED_SCAN_CMDID,
  1709. NO_SYNC_WMIFLAG);
  1710. return ret;
  1711. }
  1712. int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
  1713. u16 fg_start_sec,
  1714. u16 fg_end_sec, u16 bg_sec,
  1715. u16 minact_chdw_msec, u16 maxact_chdw_msec,
  1716. u16 pas_chdw_msec, u8 short_scan_ratio,
  1717. u8 scan_ctrl_flag, u32 max_dfsch_act_time,
  1718. u16 maxact_scan_per_ssid)
  1719. {
  1720. struct sk_buff *skb;
  1721. struct wmi_scan_params_cmd *sc;
  1722. int ret;
  1723. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1724. if (!skb)
  1725. return -ENOMEM;
  1726. sc = (struct wmi_scan_params_cmd *) skb->data;
  1727. sc->fg_start_period = cpu_to_le16(fg_start_sec);
  1728. sc->fg_end_period = cpu_to_le16(fg_end_sec);
  1729. sc->bg_period = cpu_to_le16(bg_sec);
  1730. sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
  1731. sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
  1732. sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
  1733. sc->short_scan_ratio = short_scan_ratio;
  1734. sc->scan_ctrl_flags = scan_ctrl_flag;
  1735. sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
  1736. sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
  1737. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
  1738. NO_SYNC_WMIFLAG);
  1739. return ret;
  1740. }
  1741. int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
  1742. {
  1743. struct sk_buff *skb;
  1744. struct wmi_bss_filter_cmd *cmd;
  1745. int ret;
  1746. if (filter >= LAST_BSS_FILTER)
  1747. return -EINVAL;
  1748. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1749. if (!skb)
  1750. return -ENOMEM;
  1751. cmd = (struct wmi_bss_filter_cmd *) skb->data;
  1752. cmd->bss_filter = filter;
  1753. cmd->ie_mask = cpu_to_le32(ie_mask);
  1754. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
  1755. NO_SYNC_WMIFLAG);
  1756. return ret;
  1757. }
  1758. int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
  1759. u8 ssid_len, u8 *ssid)
  1760. {
  1761. struct sk_buff *skb;
  1762. struct wmi_probed_ssid_cmd *cmd;
  1763. int ret;
  1764. if (index >= MAX_PROBED_SSIDS)
  1765. return -EINVAL;
  1766. if (ssid_len > sizeof(cmd->ssid))
  1767. return -EINVAL;
  1768. if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
  1769. return -EINVAL;
  1770. if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
  1771. return -EINVAL;
  1772. if (flag & SPECIFIC_SSID_FLAG)
  1773. wmi->is_probe_ssid = true;
  1774. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1775. if (!skb)
  1776. return -ENOMEM;
  1777. cmd = (struct wmi_probed_ssid_cmd *) skb->data;
  1778. cmd->entry_index = index;
  1779. cmd->flag = flag;
  1780. cmd->ssid_len = ssid_len;
  1781. memcpy(cmd->ssid, ssid, ssid_len);
  1782. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
  1783. NO_SYNC_WMIFLAG);
  1784. return ret;
  1785. }
  1786. int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
  1787. u16 listen_interval,
  1788. u16 listen_beacons)
  1789. {
  1790. struct sk_buff *skb;
  1791. struct wmi_listen_int_cmd *cmd;
  1792. int ret;
  1793. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1794. if (!skb)
  1795. return -ENOMEM;
  1796. cmd = (struct wmi_listen_int_cmd *) skb->data;
  1797. cmd->listen_intvl = cpu_to_le16(listen_interval);
  1798. cmd->num_beacons = cpu_to_le16(listen_beacons);
  1799. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
  1800. NO_SYNC_WMIFLAG);
  1801. return ret;
  1802. }
  1803. int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
  1804. u16 bmiss_time, u16 num_beacons)
  1805. {
  1806. struct sk_buff *skb;
  1807. struct wmi_bmiss_time_cmd *cmd;
  1808. int ret;
  1809. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1810. if (!skb)
  1811. return -ENOMEM;
  1812. cmd = (struct wmi_bmiss_time_cmd *) skb->data;
  1813. cmd->bmiss_time = cpu_to_le16(bmiss_time);
  1814. cmd->num_beacons = cpu_to_le16(num_beacons);
  1815. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
  1816. NO_SYNC_WMIFLAG);
  1817. return ret;
  1818. }
  1819. int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
  1820. {
  1821. struct sk_buff *skb;
  1822. struct wmi_power_mode_cmd *cmd;
  1823. int ret;
  1824. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1825. if (!skb)
  1826. return -ENOMEM;
  1827. cmd = (struct wmi_power_mode_cmd *) skb->data;
  1828. cmd->pwr_mode = pwr_mode;
  1829. wmi->pwr_mode = pwr_mode;
  1830. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
  1831. NO_SYNC_WMIFLAG);
  1832. return ret;
  1833. }
  1834. int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
  1835. u16 ps_poll_num, u16 dtim_policy,
  1836. u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
  1837. u16 ps_fail_event_policy)
  1838. {
  1839. struct sk_buff *skb;
  1840. struct wmi_power_params_cmd *pm;
  1841. int ret;
  1842. skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
  1843. if (!skb)
  1844. return -ENOMEM;
  1845. pm = (struct wmi_power_params_cmd *)skb->data;
  1846. pm->idle_period = cpu_to_le16(idle_period);
  1847. pm->pspoll_number = cpu_to_le16(ps_poll_num);
  1848. pm->dtim_policy = cpu_to_le16(dtim_policy);
  1849. pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
  1850. pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
  1851. pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
  1852. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
  1853. NO_SYNC_WMIFLAG);
  1854. return ret;
  1855. }
  1856. int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
  1857. {
  1858. struct sk_buff *skb;
  1859. struct wmi_disc_timeout_cmd *cmd;
  1860. int ret;
  1861. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1862. if (!skb)
  1863. return -ENOMEM;
  1864. cmd = (struct wmi_disc_timeout_cmd *) skb->data;
  1865. cmd->discon_timeout = timeout;
  1866. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
  1867. NO_SYNC_WMIFLAG);
  1868. if (ret == 0)
  1869. ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
  1870. return ret;
  1871. }
  1872. int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
  1873. enum crypto_type key_type,
  1874. u8 key_usage, u8 key_len,
  1875. u8 *key_rsc, unsigned int key_rsc_len,
  1876. u8 *key_material,
  1877. u8 key_op_ctrl, u8 *mac_addr,
  1878. enum wmi_sync_flag sync_flag)
  1879. {
  1880. struct sk_buff *skb;
  1881. struct wmi_add_cipher_key_cmd *cmd;
  1882. int ret;
  1883. ath6kl_dbg(ATH6KL_DBG_WMI,
  1884. "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n",
  1885. key_index, key_type, key_usage, key_len, key_op_ctrl);
  1886. if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
  1887. (key_material == NULL) || key_rsc_len > 8)
  1888. return -EINVAL;
  1889. if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
  1890. return -EINVAL;
  1891. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1892. if (!skb)
  1893. return -ENOMEM;
  1894. cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
  1895. cmd->key_index = key_index;
  1896. cmd->key_type = key_type;
  1897. cmd->key_usage = key_usage;
  1898. cmd->key_len = key_len;
  1899. memcpy(cmd->key, key_material, key_len);
  1900. if (key_rsc != NULL)
  1901. memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
  1902. cmd->key_op_ctrl = key_op_ctrl;
  1903. if (mac_addr)
  1904. memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
  1905. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
  1906. sync_flag);
  1907. return ret;
  1908. }
  1909. int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, const u8 *krk)
  1910. {
  1911. struct sk_buff *skb;
  1912. struct wmi_add_krk_cmd *cmd;
  1913. int ret;
  1914. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1915. if (!skb)
  1916. return -ENOMEM;
  1917. cmd = (struct wmi_add_krk_cmd *) skb->data;
  1918. memcpy(cmd->krk, krk, WMI_KRK_LEN);
  1919. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
  1920. NO_SYNC_WMIFLAG);
  1921. return ret;
  1922. }
  1923. int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
  1924. {
  1925. struct sk_buff *skb;
  1926. struct wmi_delete_cipher_key_cmd *cmd;
  1927. int ret;
  1928. if (key_index > WMI_MAX_KEY_INDEX)
  1929. return -EINVAL;
  1930. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1931. if (!skb)
  1932. return -ENOMEM;
  1933. cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
  1934. cmd->key_index = key_index;
  1935. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
  1936. NO_SYNC_WMIFLAG);
  1937. return ret;
  1938. }
  1939. int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
  1940. const u8 *pmkid, bool set)
  1941. {
  1942. struct sk_buff *skb;
  1943. struct wmi_setpmkid_cmd *cmd;
  1944. int ret;
  1945. if (bssid == NULL)
  1946. return -EINVAL;
  1947. if (set && pmkid == NULL)
  1948. return -EINVAL;
  1949. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1950. if (!skb)
  1951. return -ENOMEM;
  1952. cmd = (struct wmi_setpmkid_cmd *) skb->data;
  1953. memcpy(cmd->bssid, bssid, ETH_ALEN);
  1954. if (set) {
  1955. memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
  1956. cmd->enable = PMKID_ENABLE;
  1957. } else {
  1958. memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
  1959. cmd->enable = PMKID_DISABLE;
  1960. }
  1961. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
  1962. NO_SYNC_WMIFLAG);
  1963. return ret;
  1964. }
  1965. static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
  1966. enum htc_endpoint_id ep_id, u8 if_idx)
  1967. {
  1968. struct wmi_data_hdr *data_hdr;
  1969. int ret;
  1970. if (WARN_ON(skb == NULL || ep_id == wmi->ep_id)) {
  1971. dev_kfree_skb(skb);
  1972. return -EINVAL;
  1973. }
  1974. skb_push(skb, sizeof(struct wmi_data_hdr));
  1975. data_hdr = (struct wmi_data_hdr *) skb->data;
  1976. data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  1977. data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
  1978. ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1979. return ret;
  1980. }
  1981. static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
  1982. {
  1983. struct sk_buff *skb;
  1984. struct wmi_sync_cmd *cmd;
  1985. struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
  1986. enum htc_endpoint_id ep_id;
  1987. u8 index, num_pri_streams = 0;
  1988. int ret = 0;
  1989. memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
  1990. spin_lock_bh(&wmi->lock);
  1991. for (index = 0; index < WMM_NUM_AC; index++) {
  1992. if (wmi->fat_pipe_exist & (1 << index)) {
  1993. num_pri_streams++;
  1994. data_sync_bufs[num_pri_streams - 1].traffic_class =
  1995. index;
  1996. }
  1997. }
  1998. spin_unlock_bh(&wmi->lock);
  1999. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2000. if (!skb)
  2001. return -ENOMEM;
  2002. cmd = (struct wmi_sync_cmd *) skb->data;
  2003. /*
  2004. * In the SYNC cmd sent on the control Ep, send a bitmap
  2005. * of the data eps on which the Data Sync will be sent
  2006. */
  2007. cmd->data_sync_map = wmi->fat_pipe_exist;
  2008. for (index = 0; index < num_pri_streams; index++) {
  2009. data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
  2010. if (data_sync_bufs[index].skb == NULL) {
  2011. ret = -ENOMEM;
  2012. break;
  2013. }
  2014. }
  2015. /*
  2016. * If buffer allocation for any of the dataSync fails,
  2017. * then do not send the Synchronize cmd on the control ep
  2018. */
  2019. if (ret)
  2020. goto free_cmd_skb;
  2021. /*
  2022. * Send sync cmd followed by sync data messages on all
  2023. * endpoints being used
  2024. */
  2025. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
  2026. NO_SYNC_WMIFLAG);
  2027. if (ret)
  2028. goto free_data_skb;
  2029. for (index = 0; index < num_pri_streams; index++) {
  2030. if (WARN_ON(!data_sync_bufs[index].skb))
  2031. goto free_data_skb;
  2032. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
  2033. data_sync_bufs[index].
  2034. traffic_class);
  2035. ret =
  2036. ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
  2037. ep_id, if_idx);
  2038. data_sync_bufs[index].skb = NULL;
  2039. if (ret)
  2040. goto free_data_skb;
  2041. }
  2042. return 0;
  2043. free_cmd_skb:
  2044. /* free up any resources left over (possibly due to an error) */
  2045. dev_kfree_skb(skb);
  2046. free_data_skb:
  2047. for (index = 0; index < num_pri_streams; index++)
  2048. dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].skb);
  2049. return ret;
  2050. }
  2051. int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
  2052. struct wmi_create_pstream_cmd *params)
  2053. {
  2054. struct sk_buff *skb;
  2055. struct wmi_create_pstream_cmd *cmd;
  2056. u8 fatpipe_exist_for_ac = 0;
  2057. s32 min_phy = 0;
  2058. s32 nominal_phy = 0;
  2059. int ret;
  2060. if (!((params->user_pri < 8) &&
  2061. (params->user_pri <= 0x7) &&
  2062. (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
  2063. (params->traffic_direc == UPLINK_TRAFFIC ||
  2064. params->traffic_direc == DNLINK_TRAFFIC ||
  2065. params->traffic_direc == BIDIR_TRAFFIC) &&
  2066. (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
  2067. params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
  2068. (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
  2069. params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
  2070. params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
  2071. (params->tsid == WMI_IMPLICIT_PSTREAM ||
  2072. params->tsid <= WMI_MAX_THINSTREAM))) {
  2073. return -EINVAL;
  2074. }
  2075. /*
  2076. * Check nominal PHY rate is >= minimalPHY,
  2077. * so that DUT can allow TSRS IE
  2078. */
  2079. /* Get the physical rate (units of bps) */
  2080. min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
  2081. /* Check minimal phy < nominal phy rate */
  2082. if (params->nominal_phy >= min_phy) {
  2083. /* unit of 500 kbps */
  2084. nominal_phy = (params->nominal_phy * 1000) / 500;
  2085. ath6kl_dbg(ATH6KL_DBG_WMI,
  2086. "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
  2087. min_phy, nominal_phy);
  2088. params->nominal_phy = nominal_phy;
  2089. } else {
  2090. params->nominal_phy = 0;
  2091. }
  2092. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2093. if (!skb)
  2094. return -ENOMEM;
  2095. ath6kl_dbg(ATH6KL_DBG_WMI,
  2096. "sending create_pstream_cmd: ac=%d tsid:%d\n",
  2097. params->traffic_class, params->tsid);
  2098. cmd = (struct wmi_create_pstream_cmd *) skb->data;
  2099. memcpy(cmd, params, sizeof(*cmd));
  2100. /* This is an implicitly created Fat pipe */
  2101. if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
  2102. spin_lock_bh(&wmi->lock);
  2103. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  2104. (1 << params->traffic_class));
  2105. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  2106. spin_unlock_bh(&wmi->lock);
  2107. } else {
  2108. /* explicitly created thin stream within a fat pipe */
  2109. spin_lock_bh(&wmi->lock);
  2110. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  2111. (1 << params->traffic_class));
  2112. wmi->stream_exist_for_ac[params->traffic_class] |=
  2113. (1 << params->tsid);
  2114. /*
  2115. * If a thinstream becomes active, the fat pipe automatically
  2116. * becomes active
  2117. */
  2118. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  2119. spin_unlock_bh(&wmi->lock);
  2120. }
  2121. /*
  2122. * Indicate activty change to driver layer only if this is the
  2123. * first TSID to get created in this AC explicitly or an implicit
  2124. * fat pipe is getting created.
  2125. */
  2126. if (!fatpipe_exist_for_ac)
  2127. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2128. params->traffic_class, true);
  2129. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
  2130. NO_SYNC_WMIFLAG);
  2131. return ret;
  2132. }
  2133. int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
  2134. u8 tsid)
  2135. {
  2136. struct sk_buff *skb;
  2137. struct wmi_delete_pstream_cmd *cmd;
  2138. u16 active_tsids = 0;
  2139. int ret;
  2140. if (traffic_class > 3) {
  2141. ath6kl_err("invalid traffic class: %d\n", traffic_class);
  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 <= IEEE80211_BAND_5GHZ; band++) {
  2253. /* copy legacy rate mask */
  2254. ratemask[band] = mask->control[band].legacy;
  2255. if (band == IEEE80211_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 = IEEE80211_BAND_5GHZ;
  2278. else
  2279. band = IEEE80211_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 <= IEEE80211_BAND_5GHZ; band++) {
  2297. /* copy legacy rate mask */
  2298. ratemask[band] = mask->control[band].legacy;
  2299. if (band == IEEE80211_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 = IEEE80211_BAND_5GHZ;
  2320. else
  2321. band = IEEE80211_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 ieee80211_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 ieee80211_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 0;
  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 = kmalloc(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. memcpy(buf, data, data_len);
  2954. wmi->last_mgmt_tx_frame = buf;
  2955. wmi->last_mgmt_tx_frame_len = data_len;
  2956. ath6kl_dbg(ATH6KL_DBG_WMI,
  2957. "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
  2958. id, freq, wait, data_len);
  2959. p = (struct wmi_send_action_cmd *) skb->data;
  2960. p->id = cpu_to_le32(id);
  2961. p->freq = cpu_to_le32(freq);
  2962. p->wait = cpu_to_le32(wait);
  2963. p->len = cpu_to_le16(data_len);
  2964. memcpy(p->data, data, data_len);
  2965. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
  2966. NO_SYNC_WMIFLAG);
  2967. }
  2968. static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
  2969. u32 freq, u32 wait, const u8 *data,
  2970. u16 data_len, u32 no_cck)
  2971. {
  2972. struct sk_buff *skb;
  2973. struct wmi_send_mgmt_cmd *p;
  2974. u8 *buf;
  2975. if (wait)
  2976. return -EINVAL; /* Offload for wait not supported */
  2977. buf = kmalloc(data_len, GFP_KERNEL);
  2978. if (!buf)
  2979. return -ENOMEM;
  2980. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2981. if (!skb) {
  2982. kfree(buf);
  2983. return -ENOMEM;
  2984. }
  2985. kfree(wmi->last_mgmt_tx_frame);
  2986. memcpy(buf, data, data_len);
  2987. wmi->last_mgmt_tx_frame = buf;
  2988. wmi->last_mgmt_tx_frame_len = data_len;
  2989. ath6kl_dbg(ATH6KL_DBG_WMI,
  2990. "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
  2991. id, freq, wait, data_len);
  2992. p = (struct wmi_send_mgmt_cmd *) skb->data;
  2993. p->id = cpu_to_le32(id);
  2994. p->freq = cpu_to_le32(freq);
  2995. p->wait = cpu_to_le32(wait);
  2996. p->no_cck = cpu_to_le32(no_cck);
  2997. p->len = cpu_to_le16(data_len);
  2998. memcpy(p->data, data, data_len);
  2999. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
  3000. NO_SYNC_WMIFLAG);
  3001. }
  3002. int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
  3003. u32 wait, const u8 *data, u16 data_len,
  3004. u32 no_cck)
  3005. {
  3006. int status;
  3007. struct ath6kl *ar = wmi->parent_dev;
  3008. if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  3009. ar->fw_capabilities)) {
  3010. /*
  3011. * If capable of doing P2P mgmt operations using
  3012. * station interface, send additional information like
  3013. * supported rates to advertise and xmit rates for
  3014. * probe requests
  3015. */
  3016. status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
  3017. wait, data, data_len,
  3018. no_cck);
  3019. } else {
  3020. status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
  3021. wait, data, data_len);
  3022. }
  3023. return status;
  3024. }
  3025. int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
  3026. const u8 *dst, const u8 *data,
  3027. u16 data_len)
  3028. {
  3029. struct sk_buff *skb;
  3030. struct wmi_p2p_probe_response_cmd *p;
  3031. size_t cmd_len = sizeof(*p) + data_len;
  3032. if (data_len == 0)
  3033. cmd_len++; /* work around target minimum length requirement */
  3034. skb = ath6kl_wmi_get_new_buf(cmd_len);
  3035. if (!skb)
  3036. return -ENOMEM;
  3037. ath6kl_dbg(ATH6KL_DBG_WMI,
  3038. "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
  3039. freq, dst, data_len);
  3040. p = (struct wmi_p2p_probe_response_cmd *) skb->data;
  3041. p->freq = cpu_to_le32(freq);
  3042. memcpy(p->destination_addr, dst, ETH_ALEN);
  3043. p->len = cpu_to_le16(data_len);
  3044. memcpy(p->data, data, data_len);
  3045. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  3046. WMI_SEND_PROBE_RESPONSE_CMDID,
  3047. NO_SYNC_WMIFLAG);
  3048. }
  3049. int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
  3050. {
  3051. struct sk_buff *skb;
  3052. struct wmi_probe_req_report_cmd *p;
  3053. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  3054. if (!skb)
  3055. return -ENOMEM;
  3056. ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
  3057. enable);
  3058. p = (struct wmi_probe_req_report_cmd *) skb->data;
  3059. p->enable = enable ? 1 : 0;
  3060. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
  3061. NO_SYNC_WMIFLAG);
  3062. }
  3063. int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
  3064. {
  3065. struct sk_buff *skb;
  3066. struct wmi_get_p2p_info *p;
  3067. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  3068. if (!skb)
  3069. return -ENOMEM;
  3070. ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
  3071. info_req_flags);
  3072. p = (struct wmi_get_p2p_info *) skb->data;
  3073. p->info_req_flags = cpu_to_le32(info_req_flags);
  3074. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
  3075. NO_SYNC_WMIFLAG);
  3076. }
  3077. int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
  3078. {
  3079. ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
  3080. return ath6kl_wmi_simple_cmd(wmi, if_idx,
  3081. WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
  3082. }
  3083. int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
  3084. {
  3085. struct sk_buff *skb;
  3086. struct wmi_set_inact_period_cmd *cmd;
  3087. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  3088. if (!skb)
  3089. return -ENOMEM;
  3090. cmd = (struct wmi_set_inact_period_cmd *) skb->data;
  3091. cmd->inact_period = cpu_to_le32(inact_timeout);
  3092. cmd->num_null_func = 0;
  3093. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
  3094. NO_SYNC_WMIFLAG);
  3095. }
  3096. static void ath6kl_wmi_hb_challenge_resp_event(struct wmi *wmi, u8 *datap,
  3097. int len)
  3098. {
  3099. struct wmix_hb_challenge_resp_cmd *cmd;
  3100. if (len < sizeof(struct wmix_hb_challenge_resp_cmd))
  3101. return;
  3102. cmd = (struct wmix_hb_challenge_resp_cmd *) datap;
  3103. ath6kl_recovery_hb_event(wmi->parent_dev,
  3104. le32_to_cpu(cmd->cookie));
  3105. }
  3106. static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
  3107. {
  3108. struct wmix_cmd_hdr *cmd;
  3109. u32 len;
  3110. u16 id;
  3111. u8 *datap;
  3112. int ret = 0;
  3113. if (skb->len < sizeof(struct wmix_cmd_hdr)) {
  3114. ath6kl_err("bad packet 1\n");
  3115. return -EINVAL;
  3116. }
  3117. cmd = (struct wmix_cmd_hdr *) skb->data;
  3118. id = le32_to_cpu(cmd->cmd_id);
  3119. skb_pull(skb, sizeof(struct wmix_cmd_hdr));
  3120. datap = skb->data;
  3121. len = skb->len;
  3122. switch (id) {
  3123. case WMIX_HB_CHALLENGE_RESP_EVENTID:
  3124. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
  3125. ath6kl_wmi_hb_challenge_resp_event(wmi, datap, len);
  3126. break;
  3127. case WMIX_DBGLOG_EVENTID:
  3128. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
  3129. ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
  3130. break;
  3131. default:
  3132. ath6kl_warn("unknown cmd id 0x%x\n", id);
  3133. ret = -EINVAL;
  3134. break;
  3135. }
  3136. return ret;
  3137. }
  3138. static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
  3139. {
  3140. return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
  3141. }
  3142. /* Process interface specific wmi events, caller would free the datap */
  3143. static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
  3144. u8 *datap, u32 len)
  3145. {
  3146. struct ath6kl_vif *vif;
  3147. vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
  3148. if (!vif) {
  3149. ath6kl_dbg(ATH6KL_DBG_WMI,
  3150. "Wmi event for unavailable vif, vif_index:%d\n",
  3151. if_idx);
  3152. return -EINVAL;
  3153. }
  3154. switch (cmd_id) {
  3155. case WMI_CONNECT_EVENTID:
  3156. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
  3157. return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
  3158. case WMI_DISCONNECT_EVENTID:
  3159. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
  3160. return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
  3161. case WMI_TKIP_MICERR_EVENTID:
  3162. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
  3163. return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
  3164. case WMI_BSSINFO_EVENTID:
  3165. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
  3166. return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
  3167. case WMI_NEIGHBOR_REPORT_EVENTID:
  3168. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
  3169. return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
  3170. vif);
  3171. case WMI_SCAN_COMPLETE_EVENTID:
  3172. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
  3173. return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
  3174. case WMI_REPORT_STATISTICS_EVENTID:
  3175. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
  3176. return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
  3177. case WMI_CAC_EVENTID:
  3178. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
  3179. return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
  3180. case WMI_PSPOLL_EVENTID:
  3181. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
  3182. return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
  3183. case WMI_DTIMEXPIRY_EVENTID:
  3184. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
  3185. return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
  3186. case WMI_ADDBA_REQ_EVENTID:
  3187. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
  3188. return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
  3189. case WMI_DELBA_REQ_EVENTID:
  3190. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
  3191. return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
  3192. case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
  3193. ath6kl_dbg(ATH6KL_DBG_WMI,
  3194. "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
  3195. return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
  3196. case WMI_REMAIN_ON_CHNL_EVENTID:
  3197. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
  3198. return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
  3199. case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
  3200. ath6kl_dbg(ATH6KL_DBG_WMI,
  3201. "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
  3202. return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
  3203. len, vif);
  3204. case WMI_TX_STATUS_EVENTID:
  3205. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
  3206. return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
  3207. case WMI_RX_PROBE_REQ_EVENTID:
  3208. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
  3209. return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
  3210. case WMI_RX_ACTION_EVENTID:
  3211. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
  3212. return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
  3213. case WMI_TXE_NOTIFY_EVENTID:
  3214. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
  3215. return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
  3216. default:
  3217. ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
  3218. return -EINVAL;
  3219. }
  3220. return 0;
  3221. }
  3222. static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
  3223. {
  3224. struct wmi_cmd_hdr *cmd;
  3225. int ret = 0;
  3226. u32 len;
  3227. u16 id;
  3228. u8 if_idx;
  3229. u8 *datap;
  3230. cmd = (struct wmi_cmd_hdr *) skb->data;
  3231. id = le16_to_cpu(cmd->cmd_id);
  3232. if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
  3233. skb_pull(skb, sizeof(struct wmi_cmd_hdr));
  3234. datap = skb->data;
  3235. len = skb->len;
  3236. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
  3237. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
  3238. datap, len);
  3239. switch (id) {
  3240. case WMI_GET_BITRATE_CMDID:
  3241. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
  3242. ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
  3243. break;
  3244. case WMI_GET_CHANNEL_LIST_CMDID:
  3245. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
  3246. ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
  3247. break;
  3248. case WMI_GET_TX_PWR_CMDID:
  3249. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
  3250. ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
  3251. break;
  3252. case WMI_READY_EVENTID:
  3253. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
  3254. ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
  3255. break;
  3256. case WMI_PEER_NODE_EVENTID:
  3257. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
  3258. ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
  3259. break;
  3260. case WMI_REGDOMAIN_EVENTID:
  3261. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
  3262. ath6kl_wmi_regdomain_event(wmi, datap, len);
  3263. break;
  3264. case WMI_PSTREAM_TIMEOUT_EVENTID:
  3265. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
  3266. ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
  3267. break;
  3268. case WMI_CMDERROR_EVENTID:
  3269. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
  3270. ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
  3271. break;
  3272. case WMI_RSSI_THRESHOLD_EVENTID:
  3273. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
  3274. ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
  3275. break;
  3276. case WMI_ERROR_REPORT_EVENTID:
  3277. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
  3278. break;
  3279. case WMI_OPT_RX_FRAME_EVENTID:
  3280. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
  3281. /* this event has been deprecated */
  3282. break;
  3283. case WMI_REPORT_ROAM_TBL_EVENTID:
  3284. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
  3285. ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
  3286. break;
  3287. case WMI_EXTENSION_EVENTID:
  3288. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
  3289. ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
  3290. break;
  3291. case WMI_CHANNEL_CHANGE_EVENTID:
  3292. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
  3293. break;
  3294. case WMI_REPORT_ROAM_DATA_EVENTID:
  3295. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
  3296. break;
  3297. case WMI_TEST_EVENTID:
  3298. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
  3299. ret = ath6kl_wmi_test_rx(wmi, datap, len);
  3300. break;
  3301. case WMI_GET_FIXRATES_CMDID:
  3302. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
  3303. ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
  3304. break;
  3305. case WMI_TX_RETRY_ERR_EVENTID:
  3306. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
  3307. break;
  3308. case WMI_SNR_THRESHOLD_EVENTID:
  3309. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
  3310. ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
  3311. break;
  3312. case WMI_LQ_THRESHOLD_EVENTID:
  3313. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
  3314. break;
  3315. case WMI_APLIST_EVENTID:
  3316. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
  3317. ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
  3318. break;
  3319. case WMI_GET_KEEPALIVE_CMDID:
  3320. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
  3321. ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
  3322. break;
  3323. case WMI_GET_WOW_LIST_EVENTID:
  3324. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
  3325. break;
  3326. case WMI_GET_PMKID_LIST_EVENTID:
  3327. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
  3328. ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
  3329. break;
  3330. case WMI_SET_PARAMS_REPLY_EVENTID:
  3331. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
  3332. break;
  3333. case WMI_ADDBA_RESP_EVENTID:
  3334. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
  3335. break;
  3336. case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
  3337. ath6kl_dbg(ATH6KL_DBG_WMI,
  3338. "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
  3339. break;
  3340. case WMI_REPORT_BTCOEX_STATS_EVENTID:
  3341. ath6kl_dbg(ATH6KL_DBG_WMI,
  3342. "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
  3343. break;
  3344. case WMI_TX_COMPLETE_EVENTID:
  3345. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
  3346. ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
  3347. break;
  3348. case WMI_P2P_CAPABILITIES_EVENTID:
  3349. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
  3350. ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
  3351. break;
  3352. case WMI_P2P_INFO_EVENTID:
  3353. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
  3354. ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
  3355. break;
  3356. default:
  3357. /* may be the event is interface specific */
  3358. ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
  3359. break;
  3360. }
  3361. dev_kfree_skb(skb);
  3362. return ret;
  3363. }
  3364. /* Control Path */
  3365. int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
  3366. {
  3367. if (WARN_ON(skb == NULL))
  3368. return -EINVAL;
  3369. if (skb->len < sizeof(struct wmi_cmd_hdr)) {
  3370. ath6kl_err("bad packet 1\n");
  3371. dev_kfree_skb(skb);
  3372. return -EINVAL;
  3373. }
  3374. trace_ath6kl_wmi_event(skb->data, skb->len);
  3375. return ath6kl_wmi_proc_events(wmi, skb);
  3376. }
  3377. void ath6kl_wmi_reset(struct wmi *wmi)
  3378. {
  3379. spin_lock_bh(&wmi->lock);
  3380. wmi->fat_pipe_exist = 0;
  3381. memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
  3382. spin_unlock_bh(&wmi->lock);
  3383. }
  3384. void *ath6kl_wmi_init(struct ath6kl *dev)
  3385. {
  3386. struct wmi *wmi;
  3387. wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
  3388. if (!wmi)
  3389. return NULL;
  3390. spin_lock_init(&wmi->lock);
  3391. wmi->parent_dev = dev;
  3392. wmi->pwr_mode = REC_POWER;
  3393. ath6kl_wmi_reset(wmi);
  3394. return wmi;
  3395. }
  3396. void ath6kl_wmi_shutdown(struct wmi *wmi)
  3397. {
  3398. if (!wmi)
  3399. return;
  3400. kfree(wmi->last_mgmt_tx_frame);
  3401. kfree(wmi);
  3402. }