mac80211.c 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <linux/kernel.h>
  66. #include <linux/slab.h>
  67. #include <linux/skbuff.h>
  68. #include <linux/netdevice.h>
  69. #include <linux/etherdevice.h>
  70. #include <linux/ip.h>
  71. #include <linux/if_arp.h>
  72. #include <linux/devcoredump.h>
  73. #include <net/mac80211.h>
  74. #include <net/ieee80211_radiotap.h>
  75. #include <net/tcp.h>
  76. #include "iwl-op-mode.h"
  77. #include "iwl-io.h"
  78. #include "mvm.h"
  79. #include "sta.h"
  80. #include "time-event.h"
  81. #include "iwl-eeprom-parse.h"
  82. #include "fw-api-scan.h"
  83. #include "iwl-phy-db.h"
  84. #include "testmode.h"
  85. #include "iwl-fw-error-dump.h"
  86. #include "iwl-prph.h"
  87. #include "iwl-csr.h"
  88. static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
  89. {
  90. .max = 1,
  91. .types = BIT(NL80211_IFTYPE_STATION),
  92. },
  93. {
  94. .max = 1,
  95. .types = BIT(NL80211_IFTYPE_AP) |
  96. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  97. BIT(NL80211_IFTYPE_P2P_GO),
  98. },
  99. {
  100. .max = 1,
  101. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  102. },
  103. };
  104. static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
  105. {
  106. .num_different_channels = 2,
  107. .max_interfaces = 3,
  108. .limits = iwl_mvm_limits,
  109. .n_limits = ARRAY_SIZE(iwl_mvm_limits),
  110. },
  111. };
  112. #ifdef CONFIG_PM_SLEEP
  113. static const struct nl80211_wowlan_tcp_data_token_feature
  114. iwl_mvm_wowlan_tcp_token_feature = {
  115. .min_len = 0,
  116. .max_len = 255,
  117. .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
  118. };
  119. static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
  120. .tok = &iwl_mvm_wowlan_tcp_token_feature,
  121. .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
  122. sizeof(struct ethhdr) -
  123. sizeof(struct iphdr) -
  124. sizeof(struct tcphdr),
  125. .data_interval_max = 65535, /* __le16 in API */
  126. .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
  127. sizeof(struct ethhdr) -
  128. sizeof(struct iphdr) -
  129. sizeof(struct tcphdr),
  130. .seq = true,
  131. };
  132. #endif
  133. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  134. /*
  135. * Use the reserved field to indicate magic values.
  136. * these values will only be used internally by the driver,
  137. * and won't make it to the fw (reserved will be 0).
  138. * BC_FILTER_MAGIC_IP - configure the val of this attribute to
  139. * be the vif's ip address. in case there is not a single
  140. * ip address (0, or more than 1), this attribute will
  141. * be skipped.
  142. * BC_FILTER_MAGIC_MAC - set the val of this attribute to
  143. * the LSB bytes of the vif's mac address
  144. */
  145. enum {
  146. BC_FILTER_MAGIC_NONE = 0,
  147. BC_FILTER_MAGIC_IP,
  148. BC_FILTER_MAGIC_MAC,
  149. };
  150. static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
  151. {
  152. /* arp */
  153. .discard = 0,
  154. .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
  155. .attrs = {
  156. {
  157. /* frame type - arp, hw type - ethernet */
  158. .offset_type =
  159. BCAST_FILTER_OFFSET_PAYLOAD_START,
  160. .offset = sizeof(rfc1042_header),
  161. .val = cpu_to_be32(0x08060001),
  162. .mask = cpu_to_be32(0xffffffff),
  163. },
  164. {
  165. /* arp dest ip */
  166. .offset_type =
  167. BCAST_FILTER_OFFSET_PAYLOAD_START,
  168. .offset = sizeof(rfc1042_header) + 2 +
  169. sizeof(struct arphdr) +
  170. ETH_ALEN + sizeof(__be32) +
  171. ETH_ALEN,
  172. .mask = cpu_to_be32(0xffffffff),
  173. /* mark it as special field */
  174. .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
  175. },
  176. },
  177. },
  178. {
  179. /* dhcp offer bcast */
  180. .discard = 0,
  181. .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
  182. .attrs = {
  183. {
  184. /* udp dest port - 68 (bootp client)*/
  185. .offset_type = BCAST_FILTER_OFFSET_IP_END,
  186. .offset = offsetof(struct udphdr, dest),
  187. .val = cpu_to_be32(0x00440000),
  188. .mask = cpu_to_be32(0xffff0000),
  189. },
  190. {
  191. /* dhcp - lsb bytes of client hw address */
  192. .offset_type = BCAST_FILTER_OFFSET_IP_END,
  193. .offset = 38,
  194. .mask = cpu_to_be32(0xffffffff),
  195. /* mark it as special field */
  196. .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
  197. },
  198. },
  199. },
  200. /* last filter must be empty */
  201. {},
  202. };
  203. #endif
  204. void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
  205. {
  206. if (!iwl_mvm_is_d0i3_supported(mvm))
  207. return;
  208. IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
  209. spin_lock_bh(&mvm->refs_lock);
  210. mvm->refs[ref_type]++;
  211. spin_unlock_bh(&mvm->refs_lock);
  212. iwl_trans_ref(mvm->trans);
  213. }
  214. void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
  215. {
  216. if (!iwl_mvm_is_d0i3_supported(mvm))
  217. return;
  218. IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
  219. spin_lock_bh(&mvm->refs_lock);
  220. WARN_ON(!mvm->refs[ref_type]--);
  221. spin_unlock_bh(&mvm->refs_lock);
  222. iwl_trans_unref(mvm->trans);
  223. }
  224. static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
  225. enum iwl_mvm_ref_type except_ref)
  226. {
  227. int i, j;
  228. if (!iwl_mvm_is_d0i3_supported(mvm))
  229. return;
  230. spin_lock_bh(&mvm->refs_lock);
  231. for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
  232. if (except_ref == i || !mvm->refs[i])
  233. continue;
  234. IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
  235. i, mvm->refs[i]);
  236. for (j = 0; j < mvm->refs[i]; j++)
  237. iwl_trans_unref(mvm->trans);
  238. mvm->refs[i] = 0;
  239. }
  240. spin_unlock_bh(&mvm->refs_lock);
  241. }
  242. bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
  243. {
  244. int i;
  245. bool taken = false;
  246. if (!iwl_mvm_is_d0i3_supported(mvm))
  247. return true;
  248. spin_lock_bh(&mvm->refs_lock);
  249. for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
  250. if (mvm->refs[i]) {
  251. taken = true;
  252. break;
  253. }
  254. }
  255. spin_unlock_bh(&mvm->refs_lock);
  256. return taken;
  257. }
  258. int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
  259. {
  260. iwl_mvm_ref(mvm, ref_type);
  261. if (!wait_event_timeout(mvm->d0i3_exit_waitq,
  262. !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
  263. HZ)) {
  264. WARN_ON_ONCE(1);
  265. iwl_mvm_unref(mvm, ref_type);
  266. return -EIO;
  267. }
  268. return 0;
  269. }
  270. static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
  271. {
  272. int i;
  273. memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
  274. for (i = 0; i < NUM_PHY_CTX; i++) {
  275. mvm->phy_ctxts[i].id = i;
  276. mvm->phy_ctxts[i].ref = 0;
  277. }
  278. }
  279. int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
  280. {
  281. struct ieee80211_hw *hw = mvm->hw;
  282. int num_mac, ret, i;
  283. /* Tell mac80211 our characteristics */
  284. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  285. IEEE80211_HW_SPECTRUM_MGMT |
  286. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  287. IEEE80211_HW_QUEUE_CONTROL |
  288. IEEE80211_HW_WANT_MONITOR_VIF |
  289. IEEE80211_HW_SUPPORTS_PS |
  290. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  291. IEEE80211_HW_AMPDU_AGGREGATION |
  292. IEEE80211_HW_TIMING_BEACON_ONLY |
  293. IEEE80211_HW_CONNECTION_MONITOR |
  294. IEEE80211_HW_CHANCTX_STA_CSA |
  295. IEEE80211_HW_SUPPORTS_CLONED_SKBS;
  296. hw->queues = mvm->first_agg_queue;
  297. hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
  298. hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
  299. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  300. hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
  301. IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
  302. hw->rate_control_algorithm = "iwl-mvm-rs";
  303. hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
  304. hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
  305. /*
  306. * Enable 11w if advertised by firmware and software crypto
  307. * is not enabled (as the firmware will interpret some mgmt
  308. * packets, so enabling it with software crypto isn't safe)
  309. */
  310. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
  311. !iwlwifi_mod_params.sw_crypto)
  312. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  313. if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN ||
  314. mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
  315. hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
  316. hw->wiphy->features |=
  317. NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
  318. NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
  319. }
  320. hw->sta_data_size = sizeof(struct iwl_mvm_sta);
  321. hw->vif_data_size = sizeof(struct iwl_mvm_vif);
  322. hw->chanctx_data_size = sizeof(u16);
  323. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  324. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  325. BIT(NL80211_IFTYPE_AP) |
  326. BIT(NL80211_IFTYPE_P2P_GO) |
  327. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  328. BIT(NL80211_IFTYPE_ADHOC);
  329. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  330. hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
  331. REGULATORY_DISABLE_BEACON_HINTS;
  332. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
  333. hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  334. hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  335. hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
  336. hw->wiphy->n_iface_combinations =
  337. ARRAY_SIZE(iwl_mvm_iface_combinations);
  338. hw->wiphy->max_remain_on_channel_duration = 10000;
  339. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  340. /* we can compensate an offset of up to 3 channels = 15 MHz */
  341. hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
  342. /* Extract MAC address */
  343. memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
  344. hw->wiphy->addresses = mvm->addresses;
  345. hw->wiphy->n_addresses = 1;
  346. /* Extract additional MAC addresses if available */
  347. num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
  348. min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
  349. for (i = 1; i < num_mac; i++) {
  350. memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
  351. ETH_ALEN);
  352. mvm->addresses[i].addr[5]++;
  353. hw->wiphy->n_addresses++;
  354. }
  355. iwl_mvm_reset_phy_ctxts(mvm);
  356. hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false);
  357. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  358. if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
  359. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  360. &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
  361. if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) {
  362. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  363. &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
  364. if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_BEAMFORMER)
  365. hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
  366. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
  367. }
  368. hw->wiphy->hw_version = mvm->trans->hw_id;
  369. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
  370. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  371. else
  372. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  373. if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
  374. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
  375. hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
  376. hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
  377. /* we create the 802.11 header and zero length SSID IE. */
  378. hw->wiphy->max_sched_scan_ie_len =
  379. SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
  380. }
  381. hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
  382. NL80211_FEATURE_LOW_PRIORITY_SCAN |
  383. NL80211_FEATURE_P2P_GO_OPPPS |
  384. NL80211_FEATURE_DYNAMIC_SMPS |
  385. NL80211_FEATURE_STATIC_SMPS |
  386. NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
  387. if (mvm->fw->ucode_capa.capa[0] &
  388. IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
  389. hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
  390. if (mvm->fw->ucode_capa.capa[0] &
  391. IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
  392. hw->wiphy->features |= NL80211_FEATURE_QUIET;
  393. if (mvm->fw->ucode_capa.capa[0] &
  394. IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
  395. hw->wiphy->features |=
  396. NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
  397. if (mvm->fw->ucode_capa.capa[0] &
  398. IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
  399. hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
  400. mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  401. /* currently FW API supports only one optional cipher scheme */
  402. if (mvm->fw->cs[0].cipher) {
  403. mvm->hw->n_cipher_schemes = 1;
  404. mvm->hw->cipher_schemes = &mvm->fw->cs[0];
  405. }
  406. #ifdef CONFIG_PM_SLEEP
  407. if (iwl_mvm_is_d0i3_supported(mvm) &&
  408. device_can_wakeup(mvm->trans->dev)) {
  409. mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
  410. hw->wiphy->wowlan = &mvm->wowlan;
  411. }
  412. if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
  413. mvm->trans->ops->d3_suspend &&
  414. mvm->trans->ops->d3_resume &&
  415. device_can_wakeup(mvm->trans->dev)) {
  416. mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
  417. WIPHY_WOWLAN_DISCONNECT |
  418. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  419. WIPHY_WOWLAN_RFKILL_RELEASE |
  420. WIPHY_WOWLAN_NET_DETECT;
  421. if (!iwlwifi_mod_params.sw_crypto)
  422. mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  423. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  424. WIPHY_WOWLAN_4WAY_HANDSHAKE;
  425. mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
  426. mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
  427. mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
  428. mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
  429. mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
  430. hw->wiphy->wowlan = &mvm->wowlan;
  431. }
  432. #endif
  433. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  434. /* assign default bcast filtering configuration */
  435. mvm->bcast_filters = iwl_mvm_default_bcast_filters;
  436. #endif
  437. ret = iwl_mvm_leds_init(mvm);
  438. if (ret)
  439. return ret;
  440. if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) {
  441. IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
  442. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  443. }
  444. if (mvm->fw->ucode_capa.capa[0] &
  445. IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) {
  446. IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
  447. hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
  448. }
  449. ret = ieee80211_register_hw(mvm->hw);
  450. if (ret)
  451. iwl_mvm_leds_exit(mvm);
  452. return ret;
  453. }
  454. static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
  455. struct ieee80211_sta *sta,
  456. struct sk_buff *skb)
  457. {
  458. struct iwl_mvm_sta *mvmsta;
  459. bool defer = false;
  460. /*
  461. * double check the IN_D0I3 flag both before and after
  462. * taking the spinlock, in order to prevent taking
  463. * the spinlock when not needed.
  464. */
  465. if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
  466. return false;
  467. spin_lock(&mvm->d0i3_tx_lock);
  468. /*
  469. * testing the flag again ensures the skb dequeue
  470. * loop (on d0i3 exit) hasn't run yet.
  471. */
  472. if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
  473. goto out;
  474. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  475. if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
  476. mvmsta->sta_id != mvm->d0i3_ap_sta_id)
  477. goto out;
  478. __skb_queue_tail(&mvm->d0i3_tx, skb);
  479. ieee80211_stop_queues(mvm->hw);
  480. /* trigger wakeup */
  481. iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
  482. iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
  483. defer = true;
  484. out:
  485. spin_unlock(&mvm->d0i3_tx_lock);
  486. return defer;
  487. }
  488. static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
  489. struct ieee80211_tx_control *control,
  490. struct sk_buff *skb)
  491. {
  492. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  493. struct ieee80211_sta *sta = control->sta;
  494. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  495. struct ieee80211_hdr *hdr = (void *)skb->data;
  496. if (iwl_mvm_is_radio_killed(mvm)) {
  497. IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
  498. goto drop;
  499. }
  500. if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
  501. !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
  502. !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
  503. goto drop;
  504. /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
  505. if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
  506. ieee80211_is_mgmt(hdr->frame_control) &&
  507. !ieee80211_is_deauth(hdr->frame_control) &&
  508. !ieee80211_is_disassoc(hdr->frame_control) &&
  509. !ieee80211_is_action(hdr->frame_control)))
  510. sta = NULL;
  511. if (sta) {
  512. if (iwl_mvm_defer_tx(mvm, sta, skb))
  513. return;
  514. if (iwl_mvm_tx_skb(mvm, skb, sta))
  515. goto drop;
  516. return;
  517. }
  518. if (iwl_mvm_tx_skb_non_sta(mvm, skb))
  519. goto drop;
  520. return;
  521. drop:
  522. ieee80211_free_txskb(hw, skb);
  523. }
  524. static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
  525. {
  526. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
  527. return false;
  528. return true;
  529. }
  530. static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
  531. {
  532. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
  533. return false;
  534. if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
  535. return true;
  536. /* enabled by default */
  537. return true;
  538. }
  539. static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
  540. struct ieee80211_vif *vif,
  541. enum ieee80211_ampdu_mlme_action action,
  542. struct ieee80211_sta *sta, u16 tid,
  543. u16 *ssn, u8 buf_size)
  544. {
  545. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  546. int ret;
  547. bool tx_agg_ref = false;
  548. IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
  549. sta->addr, tid, action);
  550. if (!(mvm->nvm_data->sku_cap_11n_enable))
  551. return -EACCES;
  552. /* return from D0i3 before starting a new Tx aggregation */
  553. switch (action) {
  554. case IEEE80211_AMPDU_TX_START:
  555. case IEEE80211_AMPDU_TX_STOP_CONT:
  556. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  557. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  558. case IEEE80211_AMPDU_TX_OPERATIONAL:
  559. /*
  560. * for tx start, wait synchronously until D0i3 exit to
  561. * get the correct sequence number for the tid.
  562. * additionally, some other ampdu actions use direct
  563. * target access, which is not handled automatically
  564. * by the trans layer (unlike commands), so wait for
  565. * d0i3 exit in these cases as well.
  566. */
  567. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
  568. if (ret)
  569. return ret;
  570. tx_agg_ref = true;
  571. break;
  572. default:
  573. break;
  574. }
  575. mutex_lock(&mvm->mutex);
  576. switch (action) {
  577. case IEEE80211_AMPDU_RX_START:
  578. if (!iwl_enable_rx_ampdu(mvm->cfg)) {
  579. ret = -EINVAL;
  580. break;
  581. }
  582. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
  583. break;
  584. case IEEE80211_AMPDU_RX_STOP:
  585. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
  586. break;
  587. case IEEE80211_AMPDU_TX_START:
  588. if (!iwl_enable_tx_ampdu(mvm->cfg)) {
  589. ret = -EINVAL;
  590. break;
  591. }
  592. ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
  593. break;
  594. case IEEE80211_AMPDU_TX_STOP_CONT:
  595. ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
  596. break;
  597. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  598. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  599. ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
  600. break;
  601. case IEEE80211_AMPDU_TX_OPERATIONAL:
  602. ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
  603. break;
  604. default:
  605. WARN_ON_ONCE(1);
  606. ret = -EINVAL;
  607. break;
  608. }
  609. mutex_unlock(&mvm->mutex);
  610. /*
  611. * If the tid is marked as started, we won't use it for offloaded
  612. * traffic on the next D0i3 entry. It's safe to unref.
  613. */
  614. if (tx_agg_ref)
  615. iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
  616. return ret;
  617. }
  618. static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
  619. struct ieee80211_vif *vif)
  620. {
  621. struct iwl_mvm *mvm = data;
  622. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  623. mvmvif->uploaded = false;
  624. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  625. spin_lock_bh(&mvm->time_event_lock);
  626. iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
  627. spin_unlock_bh(&mvm->time_event_lock);
  628. mvmvif->phy_ctxt = NULL;
  629. memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
  630. }
  631. static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
  632. const void *data, size_t datalen)
  633. {
  634. const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
  635. ssize_t bytes_read;
  636. ssize_t bytes_read_trans;
  637. if (offset < dump_ptrs->op_mode_len) {
  638. bytes_read = min_t(ssize_t, count,
  639. dump_ptrs->op_mode_len - offset);
  640. memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
  641. bytes_read);
  642. offset += bytes_read;
  643. count -= bytes_read;
  644. if (count == 0)
  645. return bytes_read;
  646. } else {
  647. bytes_read = 0;
  648. }
  649. if (!dump_ptrs->trans_ptr)
  650. return bytes_read;
  651. offset -= dump_ptrs->op_mode_len;
  652. bytes_read_trans = min_t(ssize_t, count,
  653. dump_ptrs->trans_ptr->len - offset);
  654. memcpy(buffer + bytes_read,
  655. (u8 *)dump_ptrs->trans_ptr->data + offset,
  656. bytes_read_trans);
  657. return bytes_read + bytes_read_trans;
  658. }
  659. static void iwl_mvm_free_coredump(const void *data)
  660. {
  661. const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
  662. vfree(fw_error_dump->op_mode_ptr);
  663. vfree(fw_error_dump->trans_ptr);
  664. kfree(fw_error_dump);
  665. }
  666. static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
  667. struct iwl_fw_error_dump_data **dump_data)
  668. {
  669. struct iwl_fw_error_dump_fifo *fifo_hdr;
  670. u32 *fifo_data;
  671. u32 fifo_len;
  672. unsigned long flags;
  673. int i, j;
  674. if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags))
  675. return;
  676. /* Pull RXF data from all RXFs */
  677. for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
  678. /*
  679. * Keep aside the additional offset that might be needed for
  680. * next RXF
  681. */
  682. u32 offset_diff = RXF_DIFF_FROM_PREV * i;
  683. fifo_hdr = (void *)(*dump_data)->data;
  684. fifo_data = (void *)fifo_hdr->data;
  685. fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
  686. /* No need to try to read the data if the length is 0 */
  687. if (fifo_len == 0)
  688. continue;
  689. /* Add a TLV for the RXF */
  690. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
  691. (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  692. fifo_hdr->fifo_num = cpu_to_le32(i);
  693. fifo_hdr->available_bytes =
  694. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  695. RXF_RD_D_SPACE +
  696. offset_diff));
  697. fifo_hdr->wr_ptr =
  698. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  699. RXF_RD_WR_PTR +
  700. offset_diff));
  701. fifo_hdr->rd_ptr =
  702. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  703. RXF_RD_RD_PTR +
  704. offset_diff));
  705. fifo_hdr->fence_ptr =
  706. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  707. RXF_RD_FENCE_PTR +
  708. offset_diff));
  709. fifo_hdr->fence_mode =
  710. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  711. RXF_SET_FENCE_MODE +
  712. offset_diff));
  713. /* Lock fence */
  714. iwl_trans_write_prph(mvm->trans,
  715. RXF_SET_FENCE_MODE + offset_diff, 0x1);
  716. /* Set fence pointer to the same place like WR pointer */
  717. iwl_trans_write_prph(mvm->trans,
  718. RXF_LD_WR2FENCE + offset_diff, 0x1);
  719. /* Set fence offset */
  720. iwl_trans_write_prph(mvm->trans,
  721. RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
  722. 0x0);
  723. /* Read FIFO */
  724. fifo_len /= sizeof(u32); /* Size in DWORDS */
  725. for (j = 0; j < fifo_len; j++)
  726. fifo_data[j] = iwl_trans_read_prph(mvm->trans,
  727. RXF_FIFO_RD_FENCE_INC +
  728. offset_diff);
  729. *dump_data = iwl_fw_error_next_data(*dump_data);
  730. }
  731. /* Pull TXF data from all TXFs */
  732. for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
  733. /* Mark the number of TXF we're pulling now */
  734. iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
  735. fifo_hdr = (void *)(*dump_data)->data;
  736. fifo_data = (void *)fifo_hdr->data;
  737. fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
  738. /* No need to try to read the data if the length is 0 */
  739. if (fifo_len == 0)
  740. continue;
  741. /* Add a TLV for the FIFO */
  742. (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
  743. (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
  744. fifo_hdr->fifo_num = cpu_to_le32(i);
  745. fifo_hdr->available_bytes =
  746. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  747. TXF_FIFO_ITEM_CNT));
  748. fifo_hdr->wr_ptr =
  749. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  750. TXF_WR_PTR));
  751. fifo_hdr->rd_ptr =
  752. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  753. TXF_RD_PTR));
  754. fifo_hdr->fence_ptr =
  755. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  756. TXF_FENCE_PTR));
  757. fifo_hdr->fence_mode =
  758. cpu_to_le32(iwl_trans_read_prph(mvm->trans,
  759. TXF_LOCK_FENCE));
  760. /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
  761. iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
  762. TXF_WR_PTR);
  763. /* Dummy-read to advance the read pointer to the head */
  764. iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
  765. /* Read FIFO */
  766. fifo_len /= sizeof(u32); /* Size in DWORDS */
  767. for (j = 0; j < fifo_len; j++)
  768. fifo_data[j] = iwl_trans_read_prph(mvm->trans,
  769. TXF_READ_MODIFY_DATA);
  770. *dump_data = iwl_fw_error_next_data(*dump_data);
  771. }
  772. iwl_trans_release_nic_access(mvm->trans, &flags);
  773. }
  774. void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
  775. {
  776. struct iwl_fw_error_dump_file *dump_file;
  777. struct iwl_fw_error_dump_data *dump_data;
  778. struct iwl_fw_error_dump_info *dump_info;
  779. struct iwl_fw_error_dump_mem *dump_mem;
  780. struct iwl_mvm_dump_ptrs *fw_error_dump;
  781. u32 sram_len, sram_ofs;
  782. u32 file_len, fifo_data_len = 0;
  783. u32 smem_len = mvm->cfg->smem_len;
  784. u32 sram2_len = mvm->cfg->dccm2_len;
  785. lockdep_assert_held(&mvm->mutex);
  786. /* W/A for 8000 HW family A-step */
  787. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  788. CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP) {
  789. if (smem_len)
  790. smem_len = 0x38000;
  791. if (sram2_len)
  792. sram2_len = 0x10000;
  793. }
  794. fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
  795. if (!fw_error_dump)
  796. return;
  797. /* SRAM - include stack CCM if driver knows the values for it */
  798. if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
  799. const struct fw_img *img;
  800. img = &mvm->fw->img[mvm->cur_ucode];
  801. sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
  802. sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
  803. } else {
  804. sram_ofs = mvm->cfg->dccm_offset;
  805. sram_len = mvm->cfg->dccm_len;
  806. }
  807. /* reading RXF/TXF sizes */
  808. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
  809. struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
  810. int i;
  811. fifo_data_len = 0;
  812. /* Count RXF size */
  813. for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
  814. if (!mem_cfg->rxfifo_size[i])
  815. continue;
  816. /* Add header info */
  817. fifo_data_len += mem_cfg->rxfifo_size[i] +
  818. sizeof(*dump_data) +
  819. sizeof(struct iwl_fw_error_dump_fifo);
  820. }
  821. for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
  822. if (!mem_cfg->txfifo_size[i])
  823. continue;
  824. /* Add header info */
  825. fifo_data_len += mem_cfg->txfifo_size[i] +
  826. sizeof(*dump_data) +
  827. sizeof(struct iwl_fw_error_dump_fifo);
  828. }
  829. }
  830. file_len = sizeof(*dump_file) +
  831. sizeof(*dump_data) * 2 +
  832. sram_len + sizeof(*dump_mem) +
  833. fifo_data_len +
  834. sizeof(*dump_info);
  835. /* Make room for the SMEM, if it exists */
  836. if (smem_len)
  837. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
  838. /* Make room for the secondary SRAM, if it exists */
  839. if (sram2_len)
  840. file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
  841. dump_file = vzalloc(file_len);
  842. if (!dump_file) {
  843. kfree(fw_error_dump);
  844. return;
  845. }
  846. fw_error_dump->op_mode_ptr = dump_file;
  847. dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
  848. dump_data = (void *)dump_file->data;
  849. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
  850. dump_data->len = cpu_to_le32(sizeof(*dump_info));
  851. dump_info = (void *) dump_data->data;
  852. dump_info->device_family =
  853. mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
  854. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
  855. cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
  856. dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
  857. memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
  858. sizeof(dump_info->fw_human_readable));
  859. strncpy(dump_info->dev_human_readable, mvm->cfg->name,
  860. sizeof(dump_info->dev_human_readable));
  861. strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
  862. sizeof(dump_info->bus_human_readable));
  863. dump_data = iwl_fw_error_next_data(dump_data);
  864. /* We only dump the FIFOs if the FW is in error state */
  865. if (test_bit(STATUS_FW_ERROR, &mvm->trans->status))
  866. iwl_mvm_dump_fifos(mvm, &dump_data);
  867. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  868. dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
  869. dump_mem = (void *)dump_data->data;
  870. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  871. dump_mem->offset = cpu_to_le32(sram_ofs);
  872. iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
  873. sram_len);
  874. if (smem_len) {
  875. dump_data = iwl_fw_error_next_data(dump_data);
  876. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  877. dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
  878. dump_mem = (void *)dump_data->data;
  879. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
  880. dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
  881. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
  882. dump_mem->data, smem_len);
  883. }
  884. if (sram2_len) {
  885. dump_data = iwl_fw_error_next_data(dump_data);
  886. dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
  887. dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
  888. dump_mem = (void *)dump_data->data;
  889. dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
  890. dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
  891. iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
  892. dump_mem->data, sram2_len);
  893. }
  894. fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
  895. fw_error_dump->op_mode_len = file_len;
  896. if (fw_error_dump->trans_ptr)
  897. file_len += fw_error_dump->trans_ptr->len;
  898. dump_file->file_len = cpu_to_le32(file_len);
  899. dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
  900. GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
  901. }
  902. static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
  903. {
  904. /* clear the D3 reconfig, we only need it to avoid dumping a
  905. * firmware coredump on reconfiguration, we shouldn't do that
  906. * on D3->D0 transition
  907. */
  908. if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status))
  909. iwl_mvm_fw_error_dump(mvm);
  910. /* cleanup all stale references (scan, roc), but keep the
  911. * ucode_down ref until reconfig is complete
  912. */
  913. iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
  914. iwl_trans_stop_device(mvm->trans);
  915. mvm->scan_status = IWL_MVM_SCAN_NONE;
  916. mvm->ps_disabled = false;
  917. mvm->calibrating = false;
  918. /* just in case one was running */
  919. ieee80211_remain_on_channel_expired(mvm->hw);
  920. ieee80211_iterate_active_interfaces_atomic(
  921. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  922. iwl_mvm_cleanup_iterator, mvm);
  923. mvm->p2p_device_vif = NULL;
  924. mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
  925. iwl_mvm_reset_phy_ctxts(mvm);
  926. memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
  927. memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
  928. memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
  929. memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
  930. memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
  931. memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
  932. memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
  933. memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
  934. memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
  935. ieee80211_wake_queues(mvm->hw);
  936. /* clear any stale d0i3 state */
  937. clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
  938. mvm->vif_count = 0;
  939. mvm->rx_ba_sessions = 0;
  940. }
  941. int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
  942. {
  943. int ret;
  944. lockdep_assert_held(&mvm->mutex);
  945. /* Clean up some internal and mac80211 state on restart */
  946. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  947. iwl_mvm_restart_cleanup(mvm);
  948. ret = iwl_mvm_up(mvm);
  949. if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  950. /* Something went wrong - we need to finish some cleanup
  951. * that normally iwl_mvm_mac_restart_complete() below
  952. * would do.
  953. */
  954. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  955. iwl_mvm_d0i3_enable_tx(mvm, NULL);
  956. }
  957. return ret;
  958. }
  959. static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
  960. {
  961. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  962. int ret;
  963. /* Some hw restart cleanups must not hold the mutex */
  964. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  965. /*
  966. * Make sure we are out of d0i3. This is needed
  967. * to make sure the reference accounting is correct
  968. * (and there is no stale d0i3_exit_work).
  969. */
  970. wait_event_timeout(mvm->d0i3_exit_waitq,
  971. !test_bit(IWL_MVM_STATUS_IN_D0I3,
  972. &mvm->status),
  973. HZ);
  974. }
  975. mutex_lock(&mvm->mutex);
  976. ret = __iwl_mvm_mac_start(mvm);
  977. mutex_unlock(&mvm->mutex);
  978. return ret;
  979. }
  980. static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
  981. {
  982. int ret;
  983. mutex_lock(&mvm->mutex);
  984. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  985. iwl_mvm_d0i3_enable_tx(mvm, NULL);
  986. ret = iwl_mvm_update_quotas(mvm, NULL);
  987. if (ret)
  988. IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
  989. ret);
  990. /* allow transport/FW low power modes */
  991. iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
  992. /*
  993. * If we have TDLS peers, remove them. We don't know the last seqno/PN
  994. * of packets the FW sent out, so we must reconnect.
  995. */
  996. iwl_mvm_teardown_tdls_peers(mvm);
  997. mutex_unlock(&mvm->mutex);
  998. }
  999. static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
  1000. {
  1001. bool exit_now;
  1002. if (!iwl_mvm_is_d0i3_supported(mvm))
  1003. return;
  1004. mutex_lock(&mvm->d0i3_suspend_mutex);
  1005. __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
  1006. exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
  1007. &mvm->d0i3_suspend_flags);
  1008. mutex_unlock(&mvm->d0i3_suspend_mutex);
  1009. if (exit_now) {
  1010. IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
  1011. _iwl_mvm_exit_d0i3(mvm);
  1012. }
  1013. if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND)
  1014. if (!wait_event_timeout(mvm->d0i3_exit_waitq,
  1015. !test_bit(IWL_MVM_STATUS_IN_D0I3,
  1016. &mvm->status),
  1017. HZ))
  1018. WARN_ONCE(1, "D0i3 exit on resume timed out\n");
  1019. }
  1020. static void
  1021. iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
  1022. enum ieee80211_reconfig_type reconfig_type)
  1023. {
  1024. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1025. switch (reconfig_type) {
  1026. case IEEE80211_RECONFIG_TYPE_RESTART:
  1027. iwl_mvm_restart_complete(mvm);
  1028. break;
  1029. case IEEE80211_RECONFIG_TYPE_SUSPEND:
  1030. iwl_mvm_resume_complete(mvm);
  1031. break;
  1032. }
  1033. }
  1034. void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
  1035. {
  1036. lockdep_assert_held(&mvm->mutex);
  1037. /*
  1038. * Disallow low power states when the FW is down by taking
  1039. * the UCODE_DOWN ref. in case of ongoing hw restart the
  1040. * ref is already taken, so don't take it again.
  1041. */
  1042. if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  1043. iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
  1044. /* async_handlers_wk is now blocked */
  1045. /*
  1046. * The work item could be running or queued if the
  1047. * ROC time event stops just as we get here.
  1048. */
  1049. cancel_work_sync(&mvm->roc_done_wk);
  1050. iwl_trans_stop_device(mvm->trans);
  1051. iwl_mvm_async_handlers_purge(mvm);
  1052. /* async_handlers_list is empty and will stay empty: HW is stopped */
  1053. /* the fw is stopped, the aux sta is dead: clean up driver state */
  1054. iwl_mvm_del_aux_sta(mvm);
  1055. /*
  1056. * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
  1057. * won't be called in this case).
  1058. */
  1059. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  1060. mvm->ucode_loaded = false;
  1061. }
  1062. static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
  1063. {
  1064. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1065. flush_work(&mvm->d0i3_exit_work);
  1066. flush_work(&mvm->async_handlers_wk);
  1067. flush_work(&mvm->fw_error_dump_wk);
  1068. mutex_lock(&mvm->mutex);
  1069. __iwl_mvm_mac_stop(mvm);
  1070. mutex_unlock(&mvm->mutex);
  1071. /*
  1072. * The worker might have been waiting for the mutex, let it run and
  1073. * discover that its list is now empty.
  1074. */
  1075. cancel_work_sync(&mvm->async_handlers_wk);
  1076. }
  1077. static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
  1078. {
  1079. u16 i;
  1080. lockdep_assert_held(&mvm->mutex);
  1081. for (i = 0; i < NUM_PHY_CTX; i++)
  1082. if (!mvm->phy_ctxts[i].ref)
  1083. return &mvm->phy_ctxts[i];
  1084. IWL_ERR(mvm, "No available PHY context\n");
  1085. return NULL;
  1086. }
  1087. static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1088. s8 tx_power)
  1089. {
  1090. /* FW is in charge of regulatory enforcement */
  1091. struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
  1092. .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
  1093. .pwr_restriction = cpu_to_le16(tx_power),
  1094. };
  1095. return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
  1096. sizeof(reduce_txpwr_cmd),
  1097. &reduce_txpwr_cmd);
  1098. }
  1099. static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
  1100. struct ieee80211_vif *vif)
  1101. {
  1102. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1103. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1104. int ret;
  1105. /*
  1106. * make sure D0i3 exit is completed, otherwise a target access
  1107. * during tx queue configuration could be done when still in
  1108. * D0i3 state.
  1109. */
  1110. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
  1111. if (ret)
  1112. return ret;
  1113. /*
  1114. * Not much to do here. The stack will not allow interface
  1115. * types or combinations that we didn't advertise, so we
  1116. * don't really have to check the types.
  1117. */
  1118. mutex_lock(&mvm->mutex);
  1119. /* Allocate resources for the MAC context, and add it to the fw */
  1120. ret = iwl_mvm_mac_ctxt_init(mvm, vif);
  1121. if (ret)
  1122. goto out_unlock;
  1123. /* Counting number of interfaces is needed for legacy PM */
  1124. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  1125. mvm->vif_count++;
  1126. /*
  1127. * The AP binding flow can be done only after the beacon
  1128. * template is configured (which happens only in the mac80211
  1129. * start_ap() flow), and adding the broadcast station can happen
  1130. * only after the binding.
  1131. * In addition, since modifying the MAC before adding a bcast
  1132. * station is not allowed by the FW, delay the adding of MAC context to
  1133. * the point where we can also add the bcast station.
  1134. * In short: there's not much we can do at this point, other than
  1135. * allocating resources :)
  1136. */
  1137. if (vif->type == NL80211_IFTYPE_AP ||
  1138. vif->type == NL80211_IFTYPE_ADHOC) {
  1139. ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
  1140. if (ret) {
  1141. IWL_ERR(mvm, "Failed to allocate bcast sta\n");
  1142. goto out_release;
  1143. }
  1144. iwl_mvm_vif_dbgfs_register(mvm, vif);
  1145. goto out_unlock;
  1146. }
  1147. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  1148. if (ret)
  1149. goto out_release;
  1150. ret = iwl_mvm_power_update_mac(mvm);
  1151. if (ret)
  1152. goto out_remove_mac;
  1153. /* beacon filtering */
  1154. ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
  1155. if (ret)
  1156. goto out_remove_mac;
  1157. if (!mvm->bf_allowed_vif &&
  1158. vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
  1159. mvm->bf_allowed_vif = mvmvif;
  1160. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
  1161. IEEE80211_VIF_SUPPORTS_CQM_RSSI;
  1162. }
  1163. /*
  1164. * P2P_DEVICE interface does not have a channel context assigned to it,
  1165. * so a dedicated PHY context is allocated to it and the corresponding
  1166. * MAC context is bound to it at this stage.
  1167. */
  1168. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1169. mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1170. if (!mvmvif->phy_ctxt) {
  1171. ret = -ENOSPC;
  1172. goto out_free_bf;
  1173. }
  1174. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1175. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1176. if (ret)
  1177. goto out_unref_phy;
  1178. ret = iwl_mvm_add_bcast_sta(mvm, vif);
  1179. if (ret)
  1180. goto out_unbind;
  1181. /* Save a pointer to p2p device vif, so it can later be used to
  1182. * update the p2p device MAC when a GO is started/stopped */
  1183. mvm->p2p_device_vif = vif;
  1184. }
  1185. iwl_mvm_vif_dbgfs_register(mvm, vif);
  1186. goto out_unlock;
  1187. out_unbind:
  1188. iwl_mvm_binding_remove_vif(mvm, vif);
  1189. out_unref_phy:
  1190. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1191. out_free_bf:
  1192. if (mvm->bf_allowed_vif == mvmvif) {
  1193. mvm->bf_allowed_vif = NULL;
  1194. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  1195. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  1196. }
  1197. out_remove_mac:
  1198. mvmvif->phy_ctxt = NULL;
  1199. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1200. out_release:
  1201. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  1202. mvm->vif_count--;
  1203. iwl_mvm_mac_ctxt_release(mvm, vif);
  1204. out_unlock:
  1205. mutex_unlock(&mvm->mutex);
  1206. iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
  1207. return ret;
  1208. }
  1209. static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
  1210. struct ieee80211_vif *vif)
  1211. {
  1212. u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
  1213. if (tfd_msk) {
  1214. mutex_lock(&mvm->mutex);
  1215. iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
  1216. mutex_unlock(&mvm->mutex);
  1217. }
  1218. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1219. /*
  1220. * Flush the ROC worker which will flush the OFFCHANNEL queue.
  1221. * We assume here that all the packets sent to the OFFCHANNEL
  1222. * queue are sent in ROC session.
  1223. */
  1224. flush_work(&mvm->roc_done_wk);
  1225. } else {
  1226. /*
  1227. * By now, all the AC queues are empty. The AGG queues are
  1228. * empty too. We already got all the Tx responses for all the
  1229. * packets in the queues. The drain work can have been
  1230. * triggered. Flush it.
  1231. */
  1232. flush_work(&mvm->sta_drained_wk);
  1233. }
  1234. }
  1235. static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
  1236. struct ieee80211_vif *vif)
  1237. {
  1238. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1239. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1240. iwl_mvm_prepare_mac_removal(mvm, vif);
  1241. mutex_lock(&mvm->mutex);
  1242. if (mvm->bf_allowed_vif == mvmvif) {
  1243. mvm->bf_allowed_vif = NULL;
  1244. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  1245. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  1246. }
  1247. iwl_mvm_vif_dbgfs_clean(mvm, vif);
  1248. /*
  1249. * For AP/GO interface, the tear down of the resources allocated to the
  1250. * interface is be handled as part of the stop_ap flow.
  1251. */
  1252. if (vif->type == NL80211_IFTYPE_AP ||
  1253. vif->type == NL80211_IFTYPE_ADHOC) {
  1254. #ifdef CONFIG_NL80211_TESTMODE
  1255. if (vif == mvm->noa_vif) {
  1256. mvm->noa_vif = NULL;
  1257. mvm->noa_duration = 0;
  1258. }
  1259. #endif
  1260. iwl_mvm_dealloc_bcast_sta(mvm, vif);
  1261. goto out_release;
  1262. }
  1263. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1264. mvm->p2p_device_vif = NULL;
  1265. iwl_mvm_rm_bcast_sta(mvm, vif);
  1266. iwl_mvm_binding_remove_vif(mvm, vif);
  1267. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1268. mvmvif->phy_ctxt = NULL;
  1269. }
  1270. if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
  1271. mvm->vif_count--;
  1272. iwl_mvm_power_update_mac(mvm);
  1273. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1274. out_release:
  1275. iwl_mvm_mac_ctxt_release(mvm, vif);
  1276. mutex_unlock(&mvm->mutex);
  1277. }
  1278. static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
  1279. {
  1280. return 0;
  1281. }
  1282. struct iwl_mvm_mc_iter_data {
  1283. struct iwl_mvm *mvm;
  1284. int port_id;
  1285. };
  1286. static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
  1287. struct ieee80211_vif *vif)
  1288. {
  1289. struct iwl_mvm_mc_iter_data *data = _data;
  1290. struct iwl_mvm *mvm = data->mvm;
  1291. struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
  1292. int ret, len;
  1293. /* if we don't have free ports, mcast frames will be dropped */
  1294. if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
  1295. return;
  1296. if (vif->type != NL80211_IFTYPE_STATION ||
  1297. !vif->bss_conf.assoc)
  1298. return;
  1299. cmd->port_id = data->port_id++;
  1300. memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
  1301. len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
  1302. ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
  1303. if (ret)
  1304. IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
  1305. }
  1306. static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
  1307. {
  1308. struct iwl_mvm_mc_iter_data iter_data = {
  1309. .mvm = mvm,
  1310. };
  1311. lockdep_assert_held(&mvm->mutex);
  1312. if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
  1313. return;
  1314. ieee80211_iterate_active_interfaces_atomic(
  1315. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  1316. iwl_mvm_mc_iface_iterator, &iter_data);
  1317. }
  1318. static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
  1319. struct netdev_hw_addr_list *mc_list)
  1320. {
  1321. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1322. struct iwl_mcast_filter_cmd *cmd;
  1323. struct netdev_hw_addr *addr;
  1324. int addr_count;
  1325. bool pass_all;
  1326. int len;
  1327. addr_count = netdev_hw_addr_list_count(mc_list);
  1328. pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
  1329. IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
  1330. if (pass_all)
  1331. addr_count = 0;
  1332. len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
  1333. cmd = kzalloc(len, GFP_ATOMIC);
  1334. if (!cmd)
  1335. return 0;
  1336. if (pass_all) {
  1337. cmd->pass_all = 1;
  1338. return (u64)(unsigned long)cmd;
  1339. }
  1340. netdev_hw_addr_list_for_each(addr, mc_list) {
  1341. IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
  1342. cmd->count, addr->addr);
  1343. memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
  1344. addr->addr, ETH_ALEN);
  1345. cmd->count++;
  1346. }
  1347. return (u64)(unsigned long)cmd;
  1348. }
  1349. static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
  1350. unsigned int changed_flags,
  1351. unsigned int *total_flags,
  1352. u64 multicast)
  1353. {
  1354. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1355. struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
  1356. mutex_lock(&mvm->mutex);
  1357. /* replace previous configuration */
  1358. kfree(mvm->mcast_filter_cmd);
  1359. mvm->mcast_filter_cmd = cmd;
  1360. if (!cmd)
  1361. goto out;
  1362. iwl_mvm_recalc_multicast(mvm);
  1363. out:
  1364. mutex_unlock(&mvm->mutex);
  1365. *total_flags = 0;
  1366. }
  1367. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1368. struct iwl_bcast_iter_data {
  1369. struct iwl_mvm *mvm;
  1370. struct iwl_bcast_filter_cmd *cmd;
  1371. u8 current_filter;
  1372. };
  1373. static void
  1374. iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
  1375. const struct iwl_fw_bcast_filter *in_filter,
  1376. struct iwl_fw_bcast_filter *out_filter)
  1377. {
  1378. struct iwl_fw_bcast_filter_attr *attr;
  1379. int i;
  1380. memcpy(out_filter, in_filter, sizeof(*out_filter));
  1381. for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
  1382. attr = &out_filter->attrs[i];
  1383. if (!attr->mask)
  1384. break;
  1385. switch (attr->reserved1) {
  1386. case cpu_to_le16(BC_FILTER_MAGIC_IP):
  1387. if (vif->bss_conf.arp_addr_cnt != 1) {
  1388. attr->mask = 0;
  1389. continue;
  1390. }
  1391. attr->val = vif->bss_conf.arp_addr_list[0];
  1392. break;
  1393. case cpu_to_le16(BC_FILTER_MAGIC_MAC):
  1394. attr->val = *(__be32 *)&vif->addr[2];
  1395. break;
  1396. default:
  1397. break;
  1398. }
  1399. attr->reserved1 = 0;
  1400. out_filter->num_attrs++;
  1401. }
  1402. }
  1403. static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
  1404. struct ieee80211_vif *vif)
  1405. {
  1406. struct iwl_bcast_iter_data *data = _data;
  1407. struct iwl_mvm *mvm = data->mvm;
  1408. struct iwl_bcast_filter_cmd *cmd = data->cmd;
  1409. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1410. struct iwl_fw_bcast_mac *bcast_mac;
  1411. int i;
  1412. if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
  1413. return;
  1414. bcast_mac = &cmd->macs[mvmvif->id];
  1415. /*
  1416. * enable filtering only for associated stations, but not for P2P
  1417. * Clients
  1418. */
  1419. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
  1420. !vif->bss_conf.assoc)
  1421. return;
  1422. bcast_mac->default_discard = 1;
  1423. /* copy all configured filters */
  1424. for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
  1425. /*
  1426. * Make sure we don't exceed our filters limit.
  1427. * if there is still a valid filter to be configured,
  1428. * be on the safe side and just allow bcast for this mac.
  1429. */
  1430. if (WARN_ON_ONCE(data->current_filter >=
  1431. ARRAY_SIZE(cmd->filters))) {
  1432. bcast_mac->default_discard = 0;
  1433. bcast_mac->attached_filters = 0;
  1434. break;
  1435. }
  1436. iwl_mvm_set_bcast_filter(vif,
  1437. &mvm->bcast_filters[i],
  1438. &cmd->filters[data->current_filter]);
  1439. /* skip current filter if it contains no attributes */
  1440. if (!cmd->filters[data->current_filter].num_attrs)
  1441. continue;
  1442. /* attach the filter to current mac */
  1443. bcast_mac->attached_filters |=
  1444. cpu_to_le16(BIT(data->current_filter));
  1445. data->current_filter++;
  1446. }
  1447. }
  1448. bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
  1449. struct iwl_bcast_filter_cmd *cmd)
  1450. {
  1451. struct iwl_bcast_iter_data iter_data = {
  1452. .mvm = mvm,
  1453. .cmd = cmd,
  1454. };
  1455. if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
  1456. return false;
  1457. memset(cmd, 0, sizeof(*cmd));
  1458. cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
  1459. cmd->max_macs = ARRAY_SIZE(cmd->macs);
  1460. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1461. /* use debugfs filters/macs if override is configured */
  1462. if (mvm->dbgfs_bcast_filtering.override) {
  1463. memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
  1464. sizeof(cmd->filters));
  1465. memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
  1466. sizeof(cmd->macs));
  1467. return true;
  1468. }
  1469. #endif
  1470. /* if no filters are configured, do nothing */
  1471. if (!mvm->bcast_filters)
  1472. return false;
  1473. /* configure and attach these filters for each associated sta vif */
  1474. ieee80211_iterate_active_interfaces(
  1475. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  1476. iwl_mvm_bcast_filter_iterator, &iter_data);
  1477. return true;
  1478. }
  1479. static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
  1480. struct ieee80211_vif *vif)
  1481. {
  1482. struct iwl_bcast_filter_cmd cmd;
  1483. if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
  1484. return 0;
  1485. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  1486. return 0;
  1487. return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  1488. sizeof(cmd), &cmd);
  1489. }
  1490. #else
  1491. static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
  1492. struct ieee80211_vif *vif)
  1493. {
  1494. return 0;
  1495. }
  1496. #endif
  1497. static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
  1498. struct ieee80211_vif *vif,
  1499. struct ieee80211_bss_conf *bss_conf,
  1500. u32 changes)
  1501. {
  1502. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1503. int ret;
  1504. /*
  1505. * Re-calculate the tsf id, as the master-slave relations depend on the
  1506. * beacon interval, which was not known when the station interface was
  1507. * added.
  1508. */
  1509. if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
  1510. iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
  1511. /*
  1512. * If we're not associated yet, take the (new) BSSID before associating
  1513. * so the firmware knows. If we're already associated, then use the old
  1514. * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
  1515. * branch for disassociation below.
  1516. */
  1517. if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
  1518. memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
  1519. ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
  1520. if (ret)
  1521. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  1522. /* after sending it once, adopt mac80211 data */
  1523. memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
  1524. mvmvif->associated = bss_conf->assoc;
  1525. if (changes & BSS_CHANGED_ASSOC) {
  1526. if (bss_conf->assoc) {
  1527. /* add quota for this interface */
  1528. ret = iwl_mvm_update_quotas(mvm, NULL);
  1529. if (ret) {
  1530. IWL_ERR(mvm, "failed to update quotas\n");
  1531. return;
  1532. }
  1533. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
  1534. &mvm->status)) {
  1535. /*
  1536. * If we're restarting then the firmware will
  1537. * obviously have lost synchronisation with
  1538. * the AP. It will attempt to synchronise by
  1539. * itself, but we can make it more reliable by
  1540. * scheduling a session protection time event.
  1541. *
  1542. * The firmware needs to receive a beacon to
  1543. * catch up with synchronisation, use 110% of
  1544. * the beacon interval.
  1545. *
  1546. * Set a large maximum delay to allow for more
  1547. * than a single interface.
  1548. */
  1549. u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
  1550. iwl_mvm_protect_session(mvm, vif, dur, dur,
  1551. 5 * dur, false);
  1552. }
  1553. iwl_mvm_sf_update(mvm, vif, false);
  1554. iwl_mvm_power_vif_assoc(mvm, vif);
  1555. if (vif->p2p) {
  1556. iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
  1557. iwl_mvm_update_smps(mvm, vif,
  1558. IWL_MVM_SMPS_REQ_PROT,
  1559. IEEE80211_SMPS_DYNAMIC);
  1560. }
  1561. } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
  1562. /*
  1563. * If update fails - SF might be running in associated
  1564. * mode while disassociated - which is forbidden.
  1565. */
  1566. WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
  1567. "Failed to update SF upon disassociation\n");
  1568. /* remove AP station now that the MAC is unassoc */
  1569. ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
  1570. if (ret)
  1571. IWL_ERR(mvm, "failed to remove AP station\n");
  1572. if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
  1573. mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
  1574. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  1575. /* remove quota for this interface */
  1576. ret = iwl_mvm_update_quotas(mvm, NULL);
  1577. if (ret)
  1578. IWL_ERR(mvm, "failed to update quotas\n");
  1579. if (vif->p2p)
  1580. iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
  1581. /* this will take the cleared BSSID from bss_conf */
  1582. ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  1583. if (ret)
  1584. IWL_ERR(mvm,
  1585. "failed to update MAC %pM (clear after unassoc)\n",
  1586. vif->addr);
  1587. }
  1588. iwl_mvm_recalc_multicast(mvm);
  1589. iwl_mvm_configure_bcast_filter(mvm, vif);
  1590. /* reset rssi values */
  1591. mvmvif->bf_data.ave_beacon_signal = 0;
  1592. iwl_mvm_bt_coex_vif_change(mvm);
  1593. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
  1594. IEEE80211_SMPS_AUTOMATIC);
  1595. } else if (changes & BSS_CHANGED_BEACON_INFO) {
  1596. /*
  1597. * We received a beacon _after_ association so
  1598. * remove the session protection.
  1599. */
  1600. iwl_mvm_remove_time_event(mvm, mvmvif,
  1601. &mvmvif->time_event_data);
  1602. }
  1603. if (changes & BSS_CHANGED_BEACON_INFO) {
  1604. iwl_mvm_sf_update(mvm, vif, false);
  1605. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
  1606. }
  1607. if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
  1608. ret = iwl_mvm_power_update_mac(mvm);
  1609. if (ret)
  1610. IWL_ERR(mvm, "failed to update power mode\n");
  1611. }
  1612. if (changes & BSS_CHANGED_TXPOWER) {
  1613. IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
  1614. bss_conf->txpower);
  1615. iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
  1616. }
  1617. if (changes & BSS_CHANGED_CQM) {
  1618. IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
  1619. /* reset cqm events tracking */
  1620. mvmvif->bf_data.last_cqm_event = 0;
  1621. if (mvmvif->bf_data.bf_enabled) {
  1622. ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
  1623. if (ret)
  1624. IWL_ERR(mvm,
  1625. "failed to update CQM thresholds\n");
  1626. }
  1627. }
  1628. if (changes & BSS_CHANGED_ARP_FILTER) {
  1629. IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
  1630. iwl_mvm_configure_bcast_filter(mvm, vif);
  1631. }
  1632. }
  1633. static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
  1634. struct ieee80211_vif *vif)
  1635. {
  1636. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1637. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1638. int ret;
  1639. /*
  1640. * iwl_mvm_mac_ctxt_add() might read directly from the device
  1641. * (the system time), so make sure it is available.
  1642. */
  1643. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
  1644. if (ret)
  1645. return ret;
  1646. mutex_lock(&mvm->mutex);
  1647. /* Send the beacon template */
  1648. ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
  1649. if (ret)
  1650. goto out_unlock;
  1651. /*
  1652. * Re-calculate the tsf id, as the master-slave relations depend on the
  1653. * beacon interval, which was not known when the AP interface was added.
  1654. */
  1655. if (vif->type == NL80211_IFTYPE_AP)
  1656. iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
  1657. /* Add the mac context */
  1658. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  1659. if (ret)
  1660. goto out_unlock;
  1661. /* Perform the binding */
  1662. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1663. if (ret)
  1664. goto out_remove;
  1665. /* Send the bcast station. At this stage the TBTT and DTIM time events
  1666. * are added and applied to the scheduler */
  1667. ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
  1668. if (ret)
  1669. goto out_unbind;
  1670. /* must be set before quota calculations */
  1671. mvmvif->ap_ibss_active = true;
  1672. /* power updated needs to be done before quotas */
  1673. iwl_mvm_power_update_mac(mvm);
  1674. ret = iwl_mvm_update_quotas(mvm, NULL);
  1675. if (ret)
  1676. goto out_quota_failed;
  1677. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  1678. if (vif->p2p && mvm->p2p_device_vif)
  1679. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
  1680. iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
  1681. iwl_mvm_bt_coex_vif_change(mvm);
  1682. /* we don't support TDLS during DCM */
  1683. if (iwl_mvm_phy_ctx_count(mvm) > 1)
  1684. iwl_mvm_teardown_tdls_peers(mvm);
  1685. mutex_unlock(&mvm->mutex);
  1686. return 0;
  1687. out_quota_failed:
  1688. iwl_mvm_power_update_mac(mvm);
  1689. mvmvif->ap_ibss_active = false;
  1690. iwl_mvm_send_rm_bcast_sta(mvm, vif);
  1691. out_unbind:
  1692. iwl_mvm_binding_remove_vif(mvm, vif);
  1693. out_remove:
  1694. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1695. out_unlock:
  1696. mutex_unlock(&mvm->mutex);
  1697. iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
  1698. return ret;
  1699. }
  1700. static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
  1701. struct ieee80211_vif *vif)
  1702. {
  1703. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1704. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1705. iwl_mvm_prepare_mac_removal(mvm, vif);
  1706. mutex_lock(&mvm->mutex);
  1707. /* Handle AP stop while in CSA */
  1708. if (rcu_access_pointer(mvm->csa_vif) == vif) {
  1709. iwl_mvm_remove_time_event(mvm, mvmvif,
  1710. &mvmvif->time_event_data);
  1711. RCU_INIT_POINTER(mvm->csa_vif, NULL);
  1712. }
  1713. if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
  1714. RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
  1715. mvm->csa_tx_block_bcn_timeout = 0;
  1716. }
  1717. mvmvif->ap_ibss_active = false;
  1718. mvm->ap_last_beacon_gp2 = 0;
  1719. iwl_mvm_bt_coex_vif_change(mvm);
  1720. iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
  1721. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  1722. if (vif->p2p && mvm->p2p_device_vif)
  1723. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
  1724. iwl_mvm_update_quotas(mvm, NULL);
  1725. iwl_mvm_send_rm_bcast_sta(mvm, vif);
  1726. iwl_mvm_binding_remove_vif(mvm, vif);
  1727. iwl_mvm_power_update_mac(mvm);
  1728. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1729. mutex_unlock(&mvm->mutex);
  1730. }
  1731. static void
  1732. iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
  1733. struct ieee80211_vif *vif,
  1734. struct ieee80211_bss_conf *bss_conf,
  1735. u32 changes)
  1736. {
  1737. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1738. /* Changes will be applied when the AP/IBSS is started */
  1739. if (!mvmvif->ap_ibss_active)
  1740. return;
  1741. if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
  1742. BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
  1743. iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
  1744. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  1745. /* Need to send a new beacon template to the FW */
  1746. if (changes & BSS_CHANGED_BEACON &&
  1747. iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
  1748. IWL_WARN(mvm, "Failed updating beacon data\n");
  1749. if (changes & BSS_CHANGED_TXPOWER) {
  1750. IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
  1751. bss_conf->txpower);
  1752. iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
  1753. }
  1754. }
  1755. static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
  1756. struct ieee80211_vif *vif,
  1757. struct ieee80211_bss_conf *bss_conf,
  1758. u32 changes)
  1759. {
  1760. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1761. /*
  1762. * iwl_mvm_bss_info_changed_station() might call
  1763. * iwl_mvm_protect_session(), which reads directly from
  1764. * the device (the system time), so make sure it is available.
  1765. */
  1766. if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
  1767. return;
  1768. mutex_lock(&mvm->mutex);
  1769. if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
  1770. iwl_mvm_scan_offload_stop(mvm, true);
  1771. switch (vif->type) {
  1772. case NL80211_IFTYPE_STATION:
  1773. iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
  1774. break;
  1775. case NL80211_IFTYPE_AP:
  1776. case NL80211_IFTYPE_ADHOC:
  1777. iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
  1778. break;
  1779. default:
  1780. /* shouldn't happen */
  1781. WARN_ON_ONCE(1);
  1782. }
  1783. mutex_unlock(&mvm->mutex);
  1784. iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
  1785. }
  1786. static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
  1787. enum iwl_scan_status scan_type)
  1788. {
  1789. int ret;
  1790. bool wait_for_handlers = false;
  1791. mutex_lock(&mvm->mutex);
  1792. if (mvm->scan_status != scan_type) {
  1793. ret = 0;
  1794. /* make sure there are no pending notifications */
  1795. wait_for_handlers = true;
  1796. goto out;
  1797. }
  1798. switch (scan_type) {
  1799. case IWL_MVM_SCAN_SCHED:
  1800. ret = iwl_mvm_scan_offload_stop(mvm, true);
  1801. break;
  1802. case IWL_MVM_SCAN_OS:
  1803. ret = iwl_mvm_cancel_scan(mvm);
  1804. break;
  1805. case IWL_MVM_SCAN_NONE:
  1806. default:
  1807. WARN_ON_ONCE(1);
  1808. ret = -EINVAL;
  1809. break;
  1810. }
  1811. if (ret)
  1812. goto out;
  1813. wait_for_handlers = true;
  1814. out:
  1815. mutex_unlock(&mvm->mutex);
  1816. /* make sure we consume the completion notification */
  1817. if (wait_for_handlers)
  1818. iwl_mvm_wait_for_async_handlers(mvm);
  1819. return ret;
  1820. }
  1821. static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
  1822. struct ieee80211_vif *vif,
  1823. struct ieee80211_scan_request *hw_req)
  1824. {
  1825. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1826. struct cfg80211_scan_request *req = &hw_req->req;
  1827. int ret;
  1828. if (req->n_channels == 0 ||
  1829. req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
  1830. return -EINVAL;
  1831. if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1832. ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
  1833. if (ret)
  1834. return ret;
  1835. }
  1836. mutex_lock(&mvm->mutex);
  1837. if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
  1838. ret = -EBUSY;
  1839. goto out;
  1840. }
  1841. iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
  1842. if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
  1843. ret = iwl_mvm_scan_umac(mvm, vif, hw_req);
  1844. else if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
  1845. ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
  1846. else
  1847. ret = iwl_mvm_scan_request(mvm, vif, req);
  1848. if (ret)
  1849. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  1850. out:
  1851. mutex_unlock(&mvm->mutex);
  1852. return ret;
  1853. }
  1854. static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
  1855. struct ieee80211_vif *vif)
  1856. {
  1857. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1858. mutex_lock(&mvm->mutex);
  1859. iwl_mvm_cancel_scan(mvm);
  1860. mutex_unlock(&mvm->mutex);
  1861. }
  1862. static void
  1863. iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
  1864. struct ieee80211_sta *sta, u16 tids,
  1865. int num_frames,
  1866. enum ieee80211_frame_release_type reason,
  1867. bool more_data)
  1868. {
  1869. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1870. /* Called when we need to transmit (a) frame(s) from mac80211 */
  1871. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
  1872. tids, more_data, false);
  1873. }
  1874. static void
  1875. iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
  1876. struct ieee80211_sta *sta, u16 tids,
  1877. int num_frames,
  1878. enum ieee80211_frame_release_type reason,
  1879. bool more_data)
  1880. {
  1881. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1882. /* Called when we need to transmit (a) frame(s) from agg queue */
  1883. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
  1884. tids, more_data, true);
  1885. }
  1886. static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  1887. struct ieee80211_vif *vif,
  1888. enum sta_notify_cmd cmd,
  1889. struct ieee80211_sta *sta)
  1890. {
  1891. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1892. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1893. int tid;
  1894. switch (cmd) {
  1895. case STA_NOTIFY_SLEEP:
  1896. if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
  1897. ieee80211_sta_block_awake(hw, sta, true);
  1898. spin_lock_bh(&mvmsta->lock);
  1899. for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
  1900. struct iwl_mvm_tid_data *tid_data;
  1901. tid_data = &mvmsta->tid_data[tid];
  1902. if (tid_data->state != IWL_AGG_ON &&
  1903. tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
  1904. continue;
  1905. if (iwl_mvm_tid_queued(tid_data) == 0)
  1906. continue;
  1907. ieee80211_sta_set_buffered(sta, tid, true);
  1908. }
  1909. spin_unlock_bh(&mvmsta->lock);
  1910. /*
  1911. * The fw updates the STA to be asleep. Tx packets on the Tx
  1912. * queues to this station will not be transmitted. The fw will
  1913. * send a Tx response with TX_STATUS_FAIL_DEST_PS.
  1914. */
  1915. break;
  1916. case STA_NOTIFY_AWAKE:
  1917. if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
  1918. break;
  1919. iwl_mvm_sta_modify_ps_wake(mvm, sta);
  1920. break;
  1921. default:
  1922. break;
  1923. }
  1924. }
  1925. static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
  1926. struct ieee80211_vif *vif,
  1927. struct ieee80211_sta *sta)
  1928. {
  1929. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1930. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  1931. /*
  1932. * This is called before mac80211 does RCU synchronisation,
  1933. * so here we already invalidate our internal RCU-protected
  1934. * station pointer. The rest of the code will thus no longer
  1935. * be able to find the station this way, and we don't rely
  1936. * on further RCU synchronisation after the sta_state()
  1937. * callback deleted the station.
  1938. */
  1939. mutex_lock(&mvm->mutex);
  1940. if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
  1941. rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
  1942. ERR_PTR(-ENOENT));
  1943. mutex_unlock(&mvm->mutex);
  1944. }
  1945. static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1946. const u8 *bssid)
  1947. {
  1948. if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
  1949. return;
  1950. if (iwlwifi_mod_params.uapsd_disable) {
  1951. vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
  1952. return;
  1953. }
  1954. vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
  1955. }
  1956. static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
  1957. struct ieee80211_vif *vif,
  1958. struct ieee80211_sta *sta,
  1959. enum ieee80211_sta_state old_state,
  1960. enum ieee80211_sta_state new_state)
  1961. {
  1962. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1963. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1964. int ret;
  1965. IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
  1966. sta->addr, old_state, new_state);
  1967. /* this would be a mac80211 bug ... but don't crash */
  1968. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  1969. return -EINVAL;
  1970. /* if a STA is being removed, reuse its ID */
  1971. flush_work(&mvm->sta_drained_wk);
  1972. mutex_lock(&mvm->mutex);
  1973. if (old_state == IEEE80211_STA_NOTEXIST &&
  1974. new_state == IEEE80211_STA_NONE) {
  1975. /*
  1976. * Firmware bug - it'll crash if the beacon interval is less
  1977. * than 16. We can't avoid connecting at all, so refuse the
  1978. * station state change, this will cause mac80211 to abandon
  1979. * attempts to connect to this AP, and eventually wpa_s will
  1980. * blacklist the AP...
  1981. */
  1982. if (vif->type == NL80211_IFTYPE_STATION &&
  1983. vif->bss_conf.beacon_int < 16) {
  1984. IWL_ERR(mvm,
  1985. "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
  1986. sta->addr, vif->bss_conf.beacon_int);
  1987. ret = -EINVAL;
  1988. goto out_unlock;
  1989. }
  1990. if (sta->tdls &&
  1991. (vif->p2p ||
  1992. iwl_mvm_tdls_sta_count(mvm, NULL) ==
  1993. IWL_MVM_TDLS_STA_COUNT ||
  1994. iwl_mvm_phy_ctx_count(mvm) > 1)) {
  1995. IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
  1996. ret = -EBUSY;
  1997. goto out_unlock;
  1998. }
  1999. ret = iwl_mvm_add_sta(mvm, vif, sta);
  2000. if (sta->tdls && ret == 0)
  2001. iwl_mvm_recalc_tdls_state(mvm, vif, true);
  2002. } else if (old_state == IEEE80211_STA_NONE &&
  2003. new_state == IEEE80211_STA_AUTH) {
  2004. /*
  2005. * EBS may be disabled due to previous failures reported by FW.
  2006. * Reset EBS status here assuming environment has been changed.
  2007. */
  2008. mvm->last_ebs_successful = true;
  2009. iwl_mvm_check_uapsd(mvm, vif, sta->addr);
  2010. ret = 0;
  2011. } else if (old_state == IEEE80211_STA_AUTH &&
  2012. new_state == IEEE80211_STA_ASSOC) {
  2013. ret = iwl_mvm_update_sta(mvm, vif, sta);
  2014. if (ret == 0)
  2015. iwl_mvm_rs_rate_init(mvm, sta,
  2016. mvmvif->phy_ctxt->channel->band,
  2017. true);
  2018. } else if (old_state == IEEE80211_STA_ASSOC &&
  2019. new_state == IEEE80211_STA_AUTHORIZED) {
  2020. /* we don't support TDLS during DCM */
  2021. if (iwl_mvm_phy_ctx_count(mvm) > 1)
  2022. iwl_mvm_teardown_tdls_peers(mvm);
  2023. /* enable beacon filtering */
  2024. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
  2025. ret = 0;
  2026. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  2027. new_state == IEEE80211_STA_ASSOC) {
  2028. /* disable beacon filtering */
  2029. WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
  2030. ret = 0;
  2031. } else if (old_state == IEEE80211_STA_ASSOC &&
  2032. new_state == IEEE80211_STA_AUTH) {
  2033. ret = 0;
  2034. } else if (old_state == IEEE80211_STA_AUTH &&
  2035. new_state == IEEE80211_STA_NONE) {
  2036. ret = 0;
  2037. } else if (old_state == IEEE80211_STA_NONE &&
  2038. new_state == IEEE80211_STA_NOTEXIST) {
  2039. ret = iwl_mvm_rm_sta(mvm, vif, sta);
  2040. if (sta->tdls)
  2041. iwl_mvm_recalc_tdls_state(mvm, vif, false);
  2042. } else {
  2043. ret = -EIO;
  2044. }
  2045. out_unlock:
  2046. mutex_unlock(&mvm->mutex);
  2047. if (sta->tdls && ret == 0) {
  2048. if (old_state == IEEE80211_STA_NOTEXIST &&
  2049. new_state == IEEE80211_STA_NONE)
  2050. ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
  2051. else if (old_state == IEEE80211_STA_NONE &&
  2052. new_state == IEEE80211_STA_NOTEXIST)
  2053. ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
  2054. }
  2055. return ret;
  2056. }
  2057. static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  2058. {
  2059. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2060. mvm->rts_threshold = value;
  2061. return 0;
  2062. }
  2063. static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
  2064. struct ieee80211_vif *vif,
  2065. struct ieee80211_sta *sta, u32 changed)
  2066. {
  2067. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2068. if (vif->type == NL80211_IFTYPE_STATION &&
  2069. changed & IEEE80211_RC_NSS_CHANGED)
  2070. iwl_mvm_sf_update(mvm, vif, false);
  2071. }
  2072. static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
  2073. struct ieee80211_vif *vif, u16 ac,
  2074. const struct ieee80211_tx_queue_params *params)
  2075. {
  2076. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2077. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2078. mvmvif->queue_params[ac] = *params;
  2079. /*
  2080. * No need to update right away, we'll get BSS_CHANGED_QOS
  2081. * The exception is P2P_DEVICE interface which needs immediate update.
  2082. */
  2083. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  2084. int ret;
  2085. mutex_lock(&mvm->mutex);
  2086. ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  2087. mutex_unlock(&mvm->mutex);
  2088. return ret;
  2089. }
  2090. return 0;
  2091. }
  2092. static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
  2093. struct ieee80211_vif *vif)
  2094. {
  2095. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2096. u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
  2097. 200 + vif->bss_conf.beacon_int);
  2098. u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
  2099. 100 + vif->bss_conf.beacon_int);
  2100. if (WARN_ON_ONCE(vif->bss_conf.assoc))
  2101. return;
  2102. /*
  2103. * iwl_mvm_protect_session() reads directly from the device
  2104. * (the system time), so make sure it is available.
  2105. */
  2106. if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
  2107. return;
  2108. mutex_lock(&mvm->mutex);
  2109. /* Try really hard to protect the session and hear a beacon */
  2110. iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
  2111. mutex_unlock(&mvm->mutex);
  2112. iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
  2113. }
  2114. static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
  2115. struct ieee80211_vif *vif,
  2116. struct cfg80211_sched_scan_request *req,
  2117. struct ieee80211_scan_ies *ies)
  2118. {
  2119. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2120. int ret;
  2121. if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  2122. ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
  2123. if (ret)
  2124. return ret;
  2125. }
  2126. mutex_lock(&mvm->mutex);
  2127. /* Newest FW fixes sched scan while connected on another interface */
  2128. if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) {
  2129. if (!vif->bss_conf.idle) {
  2130. ret = -EBUSY;
  2131. goto out;
  2132. }
  2133. } else if (!iwl_mvm_is_idle(mvm)) {
  2134. ret = -EBUSY;
  2135. goto out;
  2136. }
  2137. if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
  2138. ret = -EBUSY;
  2139. goto out;
  2140. }
  2141. ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
  2142. if (ret)
  2143. mvm->scan_status = IWL_MVM_SCAN_NONE;
  2144. out:
  2145. mutex_unlock(&mvm->mutex);
  2146. return ret;
  2147. }
  2148. static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
  2149. struct ieee80211_vif *vif)
  2150. {
  2151. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2152. int ret;
  2153. mutex_lock(&mvm->mutex);
  2154. ret = iwl_mvm_scan_offload_stop(mvm, false);
  2155. mutex_unlock(&mvm->mutex);
  2156. iwl_mvm_wait_for_async_handlers(mvm);
  2157. return ret;
  2158. }
  2159. static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
  2160. enum set_key_cmd cmd,
  2161. struct ieee80211_vif *vif,
  2162. struct ieee80211_sta *sta,
  2163. struct ieee80211_key_conf *key)
  2164. {
  2165. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2166. int ret;
  2167. if (iwlwifi_mod_params.sw_crypto) {
  2168. IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
  2169. return -EOPNOTSUPP;
  2170. }
  2171. switch (key->cipher) {
  2172. case WLAN_CIPHER_SUITE_TKIP:
  2173. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  2174. /* fall-through */
  2175. case WLAN_CIPHER_SUITE_CCMP:
  2176. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2177. break;
  2178. case WLAN_CIPHER_SUITE_AES_CMAC:
  2179. WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
  2180. break;
  2181. case WLAN_CIPHER_SUITE_WEP40:
  2182. case WLAN_CIPHER_SUITE_WEP104:
  2183. /* For non-client mode, only use WEP keys for TX as we probably
  2184. * don't have a station yet anyway and would then have to keep
  2185. * track of the keys, linking them to each of the clients/peers
  2186. * as they appear. For now, don't do that, for performance WEP
  2187. * offload doesn't really matter much, but we need it for some
  2188. * other offload features in client mode.
  2189. */
  2190. if (vif->type != NL80211_IFTYPE_STATION)
  2191. return 0;
  2192. break;
  2193. default:
  2194. /* currently FW supports only one optional cipher scheme */
  2195. if (hw->n_cipher_schemes &&
  2196. hw->cipher_schemes->cipher == key->cipher)
  2197. key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
  2198. else
  2199. return -EOPNOTSUPP;
  2200. }
  2201. mutex_lock(&mvm->mutex);
  2202. switch (cmd) {
  2203. case SET_KEY:
  2204. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  2205. vif->type == NL80211_IFTYPE_AP) && !sta) {
  2206. /*
  2207. * GTK on AP interface is a TX-only key, return 0;
  2208. * on IBSS they're per-station and because we're lazy
  2209. * we don't support them for RX, so do the same.
  2210. */
  2211. ret = 0;
  2212. key->hw_key_idx = STA_KEY_IDX_INVALID;
  2213. break;
  2214. }
  2215. IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
  2216. ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
  2217. if (ret) {
  2218. IWL_WARN(mvm, "set key failed\n");
  2219. /*
  2220. * can't add key for RX, but we don't need it
  2221. * in the device for TX so still return 0
  2222. */
  2223. key->hw_key_idx = STA_KEY_IDX_INVALID;
  2224. ret = 0;
  2225. }
  2226. break;
  2227. case DISABLE_KEY:
  2228. if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
  2229. ret = 0;
  2230. break;
  2231. }
  2232. IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
  2233. ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
  2234. break;
  2235. default:
  2236. ret = -EINVAL;
  2237. }
  2238. mutex_unlock(&mvm->mutex);
  2239. return ret;
  2240. }
  2241. static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
  2242. struct ieee80211_vif *vif,
  2243. struct ieee80211_key_conf *keyconf,
  2244. struct ieee80211_sta *sta,
  2245. u32 iv32, u16 *phase1key)
  2246. {
  2247. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2248. if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
  2249. return;
  2250. iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
  2251. }
  2252. static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
  2253. struct iwl_rx_packet *pkt, void *data)
  2254. {
  2255. struct iwl_mvm *mvm =
  2256. container_of(notif_wait, struct iwl_mvm, notif_wait);
  2257. struct iwl_hs20_roc_res *resp;
  2258. int resp_len = iwl_rx_packet_payload_len(pkt);
  2259. struct iwl_mvm_time_event_data *te_data = data;
  2260. if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
  2261. return true;
  2262. if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
  2263. IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
  2264. return true;
  2265. }
  2266. resp = (void *)pkt->data;
  2267. IWL_DEBUG_TE(mvm,
  2268. "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
  2269. resp->status, resp->event_unique_id);
  2270. te_data->uid = le32_to_cpu(resp->event_unique_id);
  2271. IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
  2272. te_data->uid);
  2273. spin_lock_bh(&mvm->time_event_lock);
  2274. list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
  2275. spin_unlock_bh(&mvm->time_event_lock);
  2276. return true;
  2277. }
  2278. #define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
  2279. static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
  2280. struct ieee80211_channel *channel,
  2281. struct ieee80211_vif *vif,
  2282. int duration)
  2283. {
  2284. int res, time_reg = DEVICE_SYSTEM_TIME_REG;
  2285. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2286. struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
  2287. static const u8 time_event_response[] = { HOT_SPOT_CMD };
  2288. struct iwl_notification_wait wait_time_event;
  2289. struct iwl_hs20_roc_req aux_roc_req = {
  2290. .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
  2291. .id_and_color =
  2292. cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
  2293. .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
  2294. /* Set the channel info data */
  2295. .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
  2296. PHY_BAND_24 : PHY_BAND_5,
  2297. .channel_info.channel = channel->hw_value,
  2298. .channel_info.width = PHY_VHT_CHANNEL_MODE20,
  2299. /* Set the time and duration */
  2300. .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
  2301. .apply_time_max_delay =
  2302. cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
  2303. .duration = cpu_to_le32(MSEC_TO_TU(duration)),
  2304. };
  2305. /* Set the node address */
  2306. memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
  2307. lockdep_assert_held(&mvm->mutex);
  2308. spin_lock_bh(&mvm->time_event_lock);
  2309. if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
  2310. spin_unlock_bh(&mvm->time_event_lock);
  2311. return -EIO;
  2312. }
  2313. te_data->vif = vif;
  2314. te_data->duration = duration;
  2315. te_data->id = HOT_SPOT_CMD;
  2316. spin_unlock_bh(&mvm->time_event_lock);
  2317. /*
  2318. * Use a notification wait, which really just processes the
  2319. * command response and doesn't wait for anything, in order
  2320. * to be able to process the response and get the UID inside
  2321. * the RX path. Using CMD_WANT_SKB doesn't work because it
  2322. * stores the buffer and then wakes up this thread, by which
  2323. * time another notification (that the time event started)
  2324. * might already be processed unsuccessfully.
  2325. */
  2326. iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
  2327. time_event_response,
  2328. ARRAY_SIZE(time_event_response),
  2329. iwl_mvm_rx_aux_roc, te_data);
  2330. res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
  2331. &aux_roc_req);
  2332. if (res) {
  2333. IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
  2334. iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
  2335. goto out_clear_te;
  2336. }
  2337. /* No need to wait for anything, so just pass 1 (0 isn't valid) */
  2338. res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
  2339. /* should never fail */
  2340. WARN_ON_ONCE(res);
  2341. if (res) {
  2342. out_clear_te:
  2343. spin_lock_bh(&mvm->time_event_lock);
  2344. iwl_mvm_te_clear_data(mvm, te_data);
  2345. spin_unlock_bh(&mvm->time_event_lock);
  2346. }
  2347. return res;
  2348. }
  2349. static int iwl_mvm_roc(struct ieee80211_hw *hw,
  2350. struct ieee80211_vif *vif,
  2351. struct ieee80211_channel *channel,
  2352. int duration,
  2353. enum ieee80211_roc_type type)
  2354. {
  2355. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2356. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2357. struct cfg80211_chan_def chandef;
  2358. struct iwl_mvm_phy_ctxt *phy_ctxt;
  2359. int ret, i;
  2360. IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
  2361. duration, type);
  2362. mutex_lock(&mvm->mutex);
  2363. switch (vif->type) {
  2364. case NL80211_IFTYPE_STATION:
  2365. if (mvm->fw->ucode_capa.capa[0] &
  2366. IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
  2367. /* Use aux roc framework (HS20) */
  2368. ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
  2369. vif, duration);
  2370. goto out_unlock;
  2371. }
  2372. IWL_ERR(mvm, "hotspot not supported\n");
  2373. ret = -EINVAL;
  2374. goto out_unlock;
  2375. case NL80211_IFTYPE_P2P_DEVICE:
  2376. /* handle below */
  2377. break;
  2378. default:
  2379. IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
  2380. ret = -EINVAL;
  2381. goto out_unlock;
  2382. }
  2383. for (i = 0; i < NUM_PHY_CTX; i++) {
  2384. phy_ctxt = &mvm->phy_ctxts[i];
  2385. if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
  2386. continue;
  2387. if (phy_ctxt->ref && channel == phy_ctxt->channel) {
  2388. /*
  2389. * Unbind the P2P_DEVICE from the current PHY context,
  2390. * and if the PHY context is not used remove it.
  2391. */
  2392. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  2393. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  2394. goto out_unlock;
  2395. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  2396. /* Bind the P2P_DEVICE to the current PHY Context */
  2397. mvmvif->phy_ctxt = phy_ctxt;
  2398. ret = iwl_mvm_binding_add_vif(mvm, vif);
  2399. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  2400. goto out_unlock;
  2401. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  2402. goto schedule_time_event;
  2403. }
  2404. }
  2405. /* Need to update the PHY context only if the ROC channel changed */
  2406. if (channel == mvmvif->phy_ctxt->channel)
  2407. goto schedule_time_event;
  2408. cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
  2409. /*
  2410. * Change the PHY context configuration as it is currently referenced
  2411. * only by the P2P Device MAC
  2412. */
  2413. if (mvmvif->phy_ctxt->ref == 1) {
  2414. ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
  2415. &chandef, 1, 1);
  2416. if (ret)
  2417. goto out_unlock;
  2418. } else {
  2419. /*
  2420. * The PHY context is shared with other MACs. Need to remove the
  2421. * P2P Device from the binding, allocate an new PHY context and
  2422. * create a new binding
  2423. */
  2424. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  2425. if (!phy_ctxt) {
  2426. ret = -ENOSPC;
  2427. goto out_unlock;
  2428. }
  2429. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
  2430. 1, 1);
  2431. if (ret) {
  2432. IWL_ERR(mvm, "Failed to change PHY context\n");
  2433. goto out_unlock;
  2434. }
  2435. /* Unbind the P2P_DEVICE from the current PHY context */
  2436. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  2437. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  2438. goto out_unlock;
  2439. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  2440. /* Bind the P2P_DEVICE to the new allocated PHY context */
  2441. mvmvif->phy_ctxt = phy_ctxt;
  2442. ret = iwl_mvm_binding_add_vif(mvm, vif);
  2443. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  2444. goto out_unlock;
  2445. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  2446. }
  2447. schedule_time_event:
  2448. /* Schedule the time events */
  2449. ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
  2450. out_unlock:
  2451. mutex_unlock(&mvm->mutex);
  2452. IWL_DEBUG_MAC80211(mvm, "leave\n");
  2453. return ret;
  2454. }
  2455. static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
  2456. {
  2457. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2458. IWL_DEBUG_MAC80211(mvm, "enter\n");
  2459. mutex_lock(&mvm->mutex);
  2460. iwl_mvm_stop_roc(mvm);
  2461. mutex_unlock(&mvm->mutex);
  2462. IWL_DEBUG_MAC80211(mvm, "leave\n");
  2463. return 0;
  2464. }
  2465. static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
  2466. struct ieee80211_chanctx_conf *ctx)
  2467. {
  2468. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  2469. struct iwl_mvm_phy_ctxt *phy_ctxt;
  2470. int ret;
  2471. lockdep_assert_held(&mvm->mutex);
  2472. IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
  2473. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  2474. if (!phy_ctxt) {
  2475. ret = -ENOSPC;
  2476. goto out;
  2477. }
  2478. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
  2479. ctx->rx_chains_static,
  2480. ctx->rx_chains_dynamic);
  2481. if (ret) {
  2482. IWL_ERR(mvm, "Failed to add PHY context\n");
  2483. goto out;
  2484. }
  2485. iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
  2486. *phy_ctxt_id = phy_ctxt->id;
  2487. out:
  2488. return ret;
  2489. }
  2490. static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
  2491. struct ieee80211_chanctx_conf *ctx)
  2492. {
  2493. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2494. int ret;
  2495. mutex_lock(&mvm->mutex);
  2496. ret = __iwl_mvm_add_chanctx(mvm, ctx);
  2497. mutex_unlock(&mvm->mutex);
  2498. return ret;
  2499. }
  2500. static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
  2501. struct ieee80211_chanctx_conf *ctx)
  2502. {
  2503. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  2504. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  2505. lockdep_assert_held(&mvm->mutex);
  2506. iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
  2507. }
  2508. static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
  2509. struct ieee80211_chanctx_conf *ctx)
  2510. {
  2511. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2512. mutex_lock(&mvm->mutex);
  2513. __iwl_mvm_remove_chanctx(mvm, ctx);
  2514. mutex_unlock(&mvm->mutex);
  2515. }
  2516. static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
  2517. struct ieee80211_chanctx_conf *ctx,
  2518. u32 changed)
  2519. {
  2520. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2521. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  2522. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  2523. if (WARN_ONCE((phy_ctxt->ref > 1) &&
  2524. (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
  2525. IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
  2526. IEEE80211_CHANCTX_CHANGE_RADAR |
  2527. IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
  2528. "Cannot change PHY. Ref=%d, changed=0x%X\n",
  2529. phy_ctxt->ref, changed))
  2530. return;
  2531. mutex_lock(&mvm->mutex);
  2532. iwl_mvm_bt_coex_vif_change(mvm);
  2533. iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
  2534. ctx->rx_chains_static,
  2535. ctx->rx_chains_dynamic);
  2536. mutex_unlock(&mvm->mutex);
  2537. }
  2538. static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
  2539. struct ieee80211_vif *vif,
  2540. struct ieee80211_chanctx_conf *ctx,
  2541. bool switching_chanctx)
  2542. {
  2543. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  2544. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  2545. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2546. int ret;
  2547. lockdep_assert_held(&mvm->mutex);
  2548. mvmvif->phy_ctxt = phy_ctxt;
  2549. switch (vif->type) {
  2550. case NL80211_IFTYPE_AP:
  2551. /* only needed if we're switching chanctx (i.e. during CSA) */
  2552. if (switching_chanctx) {
  2553. mvmvif->ap_ibss_active = true;
  2554. break;
  2555. }
  2556. case NL80211_IFTYPE_ADHOC:
  2557. /*
  2558. * The AP binding flow is handled as part of the start_ap flow
  2559. * (in bss_info_changed), similarly for IBSS.
  2560. */
  2561. ret = 0;
  2562. goto out;
  2563. case NL80211_IFTYPE_STATION:
  2564. break;
  2565. case NL80211_IFTYPE_MONITOR:
  2566. /* always disable PS when a monitor interface is active */
  2567. mvmvif->ps_disabled = true;
  2568. break;
  2569. default:
  2570. ret = -EINVAL;
  2571. goto out;
  2572. }
  2573. ret = iwl_mvm_binding_add_vif(mvm, vif);
  2574. if (ret)
  2575. goto out;
  2576. /*
  2577. * Power state must be updated before quotas,
  2578. * otherwise fw will complain.
  2579. */
  2580. iwl_mvm_power_update_mac(mvm);
  2581. /* Setting the quota at this stage is only required for monitor
  2582. * interfaces. For the other types, the bss_info changed flow
  2583. * will handle quota settings.
  2584. */
  2585. if (vif->type == NL80211_IFTYPE_MONITOR) {
  2586. mvmvif->monitor_active = true;
  2587. ret = iwl_mvm_update_quotas(mvm, NULL);
  2588. if (ret)
  2589. goto out_remove_binding;
  2590. }
  2591. /* Handle binding during CSA */
  2592. if (vif->type == NL80211_IFTYPE_AP) {
  2593. iwl_mvm_update_quotas(mvm, NULL);
  2594. iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  2595. }
  2596. if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
  2597. u32 duration = 2 * vif->bss_conf.beacon_int;
  2598. /* iwl_mvm_protect_session() reads directly from the
  2599. * device (the system time), so make sure it is
  2600. * available.
  2601. */
  2602. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
  2603. if (ret)
  2604. goto out_remove_binding;
  2605. /* Protect the session to make sure we hear the first
  2606. * beacon on the new channel.
  2607. */
  2608. iwl_mvm_protect_session(mvm, vif, duration, duration,
  2609. vif->bss_conf.beacon_int / 2,
  2610. true);
  2611. iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
  2612. iwl_mvm_update_quotas(mvm, NULL);
  2613. }
  2614. goto out;
  2615. out_remove_binding:
  2616. iwl_mvm_binding_remove_vif(mvm, vif);
  2617. iwl_mvm_power_update_mac(mvm);
  2618. out:
  2619. if (ret)
  2620. mvmvif->phy_ctxt = NULL;
  2621. return ret;
  2622. }
  2623. static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
  2624. struct ieee80211_vif *vif,
  2625. struct ieee80211_chanctx_conf *ctx)
  2626. {
  2627. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2628. int ret;
  2629. mutex_lock(&mvm->mutex);
  2630. ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
  2631. mutex_unlock(&mvm->mutex);
  2632. return ret;
  2633. }
  2634. static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
  2635. struct ieee80211_vif *vif,
  2636. struct ieee80211_chanctx_conf *ctx,
  2637. bool switching_chanctx)
  2638. {
  2639. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2640. struct ieee80211_vif *disabled_vif = NULL;
  2641. lockdep_assert_held(&mvm->mutex);
  2642. iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
  2643. switch (vif->type) {
  2644. case NL80211_IFTYPE_ADHOC:
  2645. goto out;
  2646. case NL80211_IFTYPE_MONITOR:
  2647. mvmvif->monitor_active = false;
  2648. mvmvif->ps_disabled = false;
  2649. break;
  2650. case NL80211_IFTYPE_AP:
  2651. /* This part is triggered only during CSA */
  2652. if (!switching_chanctx || !mvmvif->ap_ibss_active)
  2653. goto out;
  2654. mvmvif->csa_countdown = false;
  2655. /* Set CS bit on all the stations */
  2656. iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
  2657. /* Save blocked iface, the timeout is set on the next beacon */
  2658. rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
  2659. mvmvif->ap_ibss_active = false;
  2660. break;
  2661. case NL80211_IFTYPE_STATION:
  2662. if (!switching_chanctx)
  2663. break;
  2664. disabled_vif = vif;
  2665. iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
  2666. break;
  2667. default:
  2668. break;
  2669. }
  2670. iwl_mvm_update_quotas(mvm, disabled_vif);
  2671. iwl_mvm_binding_remove_vif(mvm, vif);
  2672. out:
  2673. mvmvif->phy_ctxt = NULL;
  2674. iwl_mvm_power_update_mac(mvm);
  2675. }
  2676. static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
  2677. struct ieee80211_vif *vif,
  2678. struct ieee80211_chanctx_conf *ctx)
  2679. {
  2680. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2681. mutex_lock(&mvm->mutex);
  2682. __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
  2683. mutex_unlock(&mvm->mutex);
  2684. }
  2685. static int
  2686. iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
  2687. struct ieee80211_vif_chanctx_switch *vifs)
  2688. {
  2689. int ret;
  2690. mutex_lock(&mvm->mutex);
  2691. __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
  2692. __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
  2693. ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
  2694. if (ret) {
  2695. IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
  2696. goto out_reassign;
  2697. }
  2698. ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
  2699. true);
  2700. if (ret) {
  2701. IWL_ERR(mvm,
  2702. "failed to assign new_ctx during channel switch\n");
  2703. goto out_remove;
  2704. }
  2705. /* we don't support TDLS during DCM - can be caused by channel switch */
  2706. if (iwl_mvm_phy_ctx_count(mvm) > 1)
  2707. iwl_mvm_teardown_tdls_peers(mvm);
  2708. goto out;
  2709. out_remove:
  2710. __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
  2711. out_reassign:
  2712. if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
  2713. IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
  2714. goto out_restart;
  2715. }
  2716. if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
  2717. true)) {
  2718. IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
  2719. goto out_restart;
  2720. }
  2721. goto out;
  2722. out_restart:
  2723. /* things keep failing, better restart the hw */
  2724. iwl_mvm_nic_restart(mvm, false);
  2725. out:
  2726. mutex_unlock(&mvm->mutex);
  2727. return ret;
  2728. }
  2729. static int
  2730. iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
  2731. struct ieee80211_vif_chanctx_switch *vifs)
  2732. {
  2733. int ret;
  2734. mutex_lock(&mvm->mutex);
  2735. __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
  2736. ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
  2737. true);
  2738. if (ret) {
  2739. IWL_ERR(mvm,
  2740. "failed to assign new_ctx during channel switch\n");
  2741. goto out_reassign;
  2742. }
  2743. goto out;
  2744. out_reassign:
  2745. if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
  2746. true)) {
  2747. IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
  2748. goto out_restart;
  2749. }
  2750. goto out;
  2751. out_restart:
  2752. /* things keep failing, better restart the hw */
  2753. iwl_mvm_nic_restart(mvm, false);
  2754. out:
  2755. mutex_unlock(&mvm->mutex);
  2756. return ret;
  2757. }
  2758. static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
  2759. struct ieee80211_vif_chanctx_switch *vifs,
  2760. int n_vifs,
  2761. enum ieee80211_chanctx_switch_mode mode)
  2762. {
  2763. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2764. int ret;
  2765. /* we only support a single-vif right now */
  2766. if (n_vifs > 1)
  2767. return -EOPNOTSUPP;
  2768. switch (mode) {
  2769. case CHANCTX_SWMODE_SWAP_CONTEXTS:
  2770. ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
  2771. break;
  2772. case CHANCTX_SWMODE_REASSIGN_VIF:
  2773. ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
  2774. break;
  2775. default:
  2776. ret = -EOPNOTSUPP;
  2777. break;
  2778. }
  2779. return ret;
  2780. }
  2781. static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
  2782. struct ieee80211_sta *sta,
  2783. bool set)
  2784. {
  2785. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2786. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  2787. if (!mvm_sta || !mvm_sta->vif) {
  2788. IWL_ERR(mvm, "Station is not associated to a vif\n");
  2789. return -EINVAL;
  2790. }
  2791. return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
  2792. }
  2793. #ifdef CONFIG_NL80211_TESTMODE
  2794. static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
  2795. [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
  2796. [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
  2797. [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
  2798. };
  2799. static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
  2800. struct ieee80211_vif *vif,
  2801. void *data, int len)
  2802. {
  2803. struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
  2804. int err;
  2805. u32 noa_duration;
  2806. err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
  2807. if (err)
  2808. return err;
  2809. if (!tb[IWL_MVM_TM_ATTR_CMD])
  2810. return -EINVAL;
  2811. switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
  2812. case IWL_MVM_TM_CMD_SET_NOA:
  2813. if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
  2814. !vif->bss_conf.enable_beacon ||
  2815. !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
  2816. return -EINVAL;
  2817. noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
  2818. if (noa_duration >= vif->bss_conf.beacon_int)
  2819. return -EINVAL;
  2820. mvm->noa_duration = noa_duration;
  2821. mvm->noa_vif = vif;
  2822. return iwl_mvm_update_quotas(mvm, NULL);
  2823. case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
  2824. /* must be associated client vif - ignore authorized */
  2825. if (!vif || vif->type != NL80211_IFTYPE_STATION ||
  2826. !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
  2827. !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
  2828. return -EINVAL;
  2829. if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
  2830. return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
  2831. return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
  2832. }
  2833. return -EOPNOTSUPP;
  2834. }
  2835. static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
  2836. struct ieee80211_vif *vif,
  2837. void *data, int len)
  2838. {
  2839. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2840. int err;
  2841. mutex_lock(&mvm->mutex);
  2842. err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
  2843. mutex_unlock(&mvm->mutex);
  2844. return err;
  2845. }
  2846. #endif
  2847. static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
  2848. struct ieee80211_vif *vif,
  2849. struct ieee80211_channel_switch *chsw)
  2850. {
  2851. /* By implementing this operation, we prevent mac80211 from
  2852. * starting its own channel switch timer, so that we can call
  2853. * ieee80211_chswitch_done() ourselves at the right time
  2854. * (which is when the absence time event starts).
  2855. */
  2856. IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
  2857. "dummy channel switch op\n");
  2858. }
  2859. static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
  2860. struct ieee80211_vif *vif,
  2861. struct ieee80211_channel_switch *chsw)
  2862. {
  2863. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2864. struct ieee80211_vif *csa_vif;
  2865. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2866. u32 apply_time;
  2867. int ret;
  2868. mutex_lock(&mvm->mutex);
  2869. IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
  2870. chsw->chandef.center_freq1);
  2871. switch (vif->type) {
  2872. case NL80211_IFTYPE_AP:
  2873. csa_vif =
  2874. rcu_dereference_protected(mvm->csa_vif,
  2875. lockdep_is_held(&mvm->mutex));
  2876. if (WARN_ONCE(csa_vif && csa_vif->csa_active,
  2877. "Another CSA is already in progress")) {
  2878. ret = -EBUSY;
  2879. goto out_unlock;
  2880. }
  2881. rcu_assign_pointer(mvm->csa_vif, vif);
  2882. if (WARN_ONCE(mvmvif->csa_countdown,
  2883. "Previous CSA countdown didn't complete")) {
  2884. ret = -EBUSY;
  2885. goto out_unlock;
  2886. }
  2887. break;
  2888. case NL80211_IFTYPE_STATION:
  2889. /* Schedule the time event to a bit before beacon 1,
  2890. * to make sure we're in the new channel when the
  2891. * GO/AP arrives.
  2892. */
  2893. apply_time = chsw->device_timestamp +
  2894. ((vif->bss_conf.beacon_int * (chsw->count - 1) -
  2895. IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
  2896. if (chsw->block_tx)
  2897. iwl_mvm_csa_client_absent(mvm, vif);
  2898. iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
  2899. apply_time);
  2900. if (mvmvif->bf_data.bf_enabled) {
  2901. ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
  2902. if (ret)
  2903. goto out_unlock;
  2904. }
  2905. break;
  2906. default:
  2907. break;
  2908. }
  2909. mvmvif->ps_disabled = true;
  2910. ret = iwl_mvm_power_update_ps(mvm);
  2911. if (ret)
  2912. goto out_unlock;
  2913. /* we won't be on this channel any longer */
  2914. iwl_mvm_teardown_tdls_peers(mvm);
  2915. out_unlock:
  2916. mutex_unlock(&mvm->mutex);
  2917. return ret;
  2918. }
  2919. static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
  2920. struct ieee80211_vif *vif)
  2921. {
  2922. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2923. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2924. int ret;
  2925. mutex_lock(&mvm->mutex);
  2926. if (vif->type == NL80211_IFTYPE_STATION) {
  2927. struct iwl_mvm_sta *mvmsta;
  2928. mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
  2929. mvmvif->ap_sta_id);
  2930. if (WARN_ON(!mvmsta)) {
  2931. ret = -EIO;
  2932. goto out_unlock;
  2933. }
  2934. iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
  2935. iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  2936. ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
  2937. if (ret)
  2938. goto out_unlock;
  2939. iwl_mvm_stop_session_protection(mvm, vif);
  2940. }
  2941. mvmvif->ps_disabled = false;
  2942. ret = iwl_mvm_power_update_ps(mvm);
  2943. out_unlock:
  2944. mutex_unlock(&mvm->mutex);
  2945. return ret;
  2946. }
  2947. static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
  2948. struct ieee80211_vif *vif, u32 queues, bool drop)
  2949. {
  2950. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2951. struct iwl_mvm_vif *mvmvif;
  2952. struct iwl_mvm_sta *mvmsta;
  2953. struct ieee80211_sta *sta;
  2954. int i;
  2955. u32 msk = 0;
  2956. if (!vif || vif->type != NL80211_IFTYPE_STATION)
  2957. return;
  2958. mutex_lock(&mvm->mutex);
  2959. mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2960. /* flush the AP-station and all TDLS peers */
  2961. for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
  2962. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
  2963. lockdep_is_held(&mvm->mutex));
  2964. if (IS_ERR_OR_NULL(sta))
  2965. continue;
  2966. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2967. if (mvmsta->vif != vif)
  2968. continue;
  2969. /* make sure only TDLS peers or the AP are flushed */
  2970. WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
  2971. msk |= mvmsta->tfd_queue_msk;
  2972. }
  2973. if (drop) {
  2974. if (iwl_mvm_flush_tx_path(mvm, msk, true))
  2975. IWL_ERR(mvm, "flush request fail\n");
  2976. mutex_unlock(&mvm->mutex);
  2977. } else {
  2978. mutex_unlock(&mvm->mutex);
  2979. /* this can take a while, and we may need/want other operations
  2980. * to succeed while doing this, so do it without the mutex held
  2981. */
  2982. iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
  2983. }
  2984. }
  2985. const struct ieee80211_ops iwl_mvm_hw_ops = {
  2986. .tx = iwl_mvm_mac_tx,
  2987. .ampdu_action = iwl_mvm_mac_ampdu_action,
  2988. .start = iwl_mvm_mac_start,
  2989. .reconfig_complete = iwl_mvm_mac_reconfig_complete,
  2990. .stop = iwl_mvm_mac_stop,
  2991. .add_interface = iwl_mvm_mac_add_interface,
  2992. .remove_interface = iwl_mvm_mac_remove_interface,
  2993. .config = iwl_mvm_mac_config,
  2994. .prepare_multicast = iwl_mvm_prepare_multicast,
  2995. .configure_filter = iwl_mvm_configure_filter,
  2996. .bss_info_changed = iwl_mvm_bss_info_changed,
  2997. .hw_scan = iwl_mvm_mac_hw_scan,
  2998. .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
  2999. .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
  3000. .sta_state = iwl_mvm_mac_sta_state,
  3001. .sta_notify = iwl_mvm_mac_sta_notify,
  3002. .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
  3003. .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
  3004. .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
  3005. .sta_rc_update = iwl_mvm_sta_rc_update,
  3006. .conf_tx = iwl_mvm_mac_conf_tx,
  3007. .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
  3008. .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
  3009. .flush = iwl_mvm_mac_flush,
  3010. .sched_scan_start = iwl_mvm_mac_sched_scan_start,
  3011. .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
  3012. .set_key = iwl_mvm_mac_set_key,
  3013. .update_tkip_key = iwl_mvm_mac_update_tkip_key,
  3014. .remain_on_channel = iwl_mvm_roc,
  3015. .cancel_remain_on_channel = iwl_mvm_cancel_roc,
  3016. .add_chanctx = iwl_mvm_add_chanctx,
  3017. .remove_chanctx = iwl_mvm_remove_chanctx,
  3018. .change_chanctx = iwl_mvm_change_chanctx,
  3019. .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
  3020. .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
  3021. .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
  3022. .start_ap = iwl_mvm_start_ap_ibss,
  3023. .stop_ap = iwl_mvm_stop_ap_ibss,
  3024. .join_ibss = iwl_mvm_start_ap_ibss,
  3025. .leave_ibss = iwl_mvm_stop_ap_ibss,
  3026. .set_tim = iwl_mvm_set_tim,
  3027. .channel_switch = iwl_mvm_channel_switch,
  3028. .pre_channel_switch = iwl_mvm_pre_channel_switch,
  3029. .post_channel_switch = iwl_mvm_post_channel_switch,
  3030. .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
  3031. .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
  3032. .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
  3033. CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
  3034. #ifdef CONFIG_PM_SLEEP
  3035. /* look at d3.c */
  3036. .suspend = iwl_mvm_suspend,
  3037. .resume = iwl_mvm_resume,
  3038. .set_wakeup = iwl_mvm_set_wakeup,
  3039. .set_rekey_data = iwl_mvm_set_rekey_data,
  3040. #if IS_ENABLED(CONFIG_IPV6)
  3041. .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
  3042. #endif
  3043. .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
  3044. #endif
  3045. };