wmi.c 108 KB

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