wmi.c 108 KB

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