wmi.c 108 KB

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