dp_peer.c 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524
  1. /*
  2. * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include <qdf_types.h>
  19. #include <qdf_lock.h>
  20. #include <hal_hw_headers.h>
  21. #include "dp_htt.h"
  22. #include "dp_types.h"
  23. #include "dp_internal.h"
  24. #include "dp_peer.h"
  25. #include "dp_rx_defrag.h"
  26. #include "dp_rx.h"
  27. #include <hal_api.h>
  28. #include <hal_reo.h>
  29. #include <cdp_txrx_handle.h>
  30. #include <wlan_cfg.h>
  31. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  32. #include "dp_tx_capture.h"
  33. #endif
  34. static inline void
  35. dp_set_ssn_valid_flag(struct hal_reo_cmd_params *params,
  36. uint8_t valid)
  37. {
  38. params->u.upd_queue_params.update_svld = 1;
  39. params->u.upd_queue_params.svld = valid;
  40. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  41. "%s: Setting SSN valid bit to %d",
  42. __func__, valid);
  43. }
  44. static inline int dp_peer_find_mac_addr_cmp(
  45. union dp_align_mac_addr *mac_addr1,
  46. union dp_align_mac_addr *mac_addr2)
  47. {
  48. /*
  49. * Intentionally use & rather than &&.
  50. * because the operands are binary rather than generic boolean,
  51. * the functionality is equivalent.
  52. * Using && has the advantage of short-circuited evaluation,
  53. * but using & has the advantage of no conditional branching,
  54. * which is a more significant benefit.
  55. */
  56. return !((mac_addr1->align4.bytes_abcd == mac_addr2->align4.bytes_abcd)
  57. & (mac_addr1->align4.bytes_ef == mac_addr2->align4.bytes_ef));
  58. }
  59. static int dp_peer_ast_table_attach(struct dp_soc *soc)
  60. {
  61. uint32_t max_ast_index;
  62. max_ast_index = wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx);
  63. /* allocate ast_table for ast entry to ast_index map */
  64. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  65. "\n<=== cfg max ast idx %d ====>", max_ast_index);
  66. soc->ast_table = qdf_mem_malloc(max_ast_index *
  67. sizeof(struct dp_ast_entry *));
  68. if (!soc->ast_table) {
  69. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  70. "%s: ast_table memory allocation failed", __func__);
  71. return QDF_STATUS_E_NOMEM;
  72. }
  73. return 0; /* success */
  74. }
  75. static int dp_peer_find_map_attach(struct dp_soc *soc)
  76. {
  77. uint32_t max_peers, peer_map_size;
  78. max_peers = soc->max_peers;
  79. /* allocate the peer ID -> peer object map */
  80. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  81. "\n<=== cfg max peer id %d ====>", max_peers);
  82. peer_map_size = max_peers * sizeof(soc->peer_id_to_obj_map[0]);
  83. soc->peer_id_to_obj_map = qdf_mem_malloc(peer_map_size);
  84. if (!soc->peer_id_to_obj_map) {
  85. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  86. "%s: peer map memory allocation failed", __func__);
  87. return QDF_STATUS_E_NOMEM;
  88. }
  89. /*
  90. * The peer_id_to_obj_map doesn't really need to be initialized,
  91. * since elements are only used after they have been individually
  92. * initialized.
  93. * However, it is convenient for debugging to have all elements
  94. * that are not in use set to 0.
  95. */
  96. qdf_mem_zero(soc->peer_id_to_obj_map, peer_map_size);
  97. return 0; /* success */
  98. }
  99. static int dp_log2_ceil(unsigned int value)
  100. {
  101. unsigned int tmp = value;
  102. int log2 = -1;
  103. while (tmp) {
  104. log2++;
  105. tmp >>= 1;
  106. }
  107. if (1 << log2 != value)
  108. log2++;
  109. return log2;
  110. }
  111. static int dp_peer_find_add_id_to_obj(
  112. struct dp_peer *peer,
  113. uint16_t peer_id)
  114. {
  115. int i;
  116. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++) {
  117. if (peer->peer_ids[i] == HTT_INVALID_PEER) {
  118. peer->peer_ids[i] = peer_id;
  119. return 0; /* success */
  120. }
  121. }
  122. return QDF_STATUS_E_FAILURE; /* failure */
  123. }
  124. #define DP_PEER_HASH_LOAD_MULT 2
  125. #define DP_PEER_HASH_LOAD_SHIFT 0
  126. #define DP_AST_HASH_LOAD_MULT 2
  127. #define DP_AST_HASH_LOAD_SHIFT 0
  128. static int dp_peer_find_hash_attach(struct dp_soc *soc)
  129. {
  130. int i, hash_elems, log2;
  131. /* allocate the peer MAC address -> peer object hash table */
  132. hash_elems = soc->max_peers;
  133. hash_elems *= DP_PEER_HASH_LOAD_MULT;
  134. hash_elems >>= DP_PEER_HASH_LOAD_SHIFT;
  135. log2 = dp_log2_ceil(hash_elems);
  136. hash_elems = 1 << log2;
  137. soc->peer_hash.mask = hash_elems - 1;
  138. soc->peer_hash.idx_bits = log2;
  139. /* allocate an array of TAILQ peer object lists */
  140. soc->peer_hash.bins = qdf_mem_malloc(
  141. hash_elems * sizeof(TAILQ_HEAD(anonymous_tail_q, dp_peer)));
  142. if (!soc->peer_hash.bins)
  143. return QDF_STATUS_E_NOMEM;
  144. for (i = 0; i < hash_elems; i++)
  145. TAILQ_INIT(&soc->peer_hash.bins[i]);
  146. return 0;
  147. }
  148. static void dp_peer_find_hash_detach(struct dp_soc *soc)
  149. {
  150. if (soc->peer_hash.bins) {
  151. qdf_mem_free(soc->peer_hash.bins);
  152. soc->peer_hash.bins = NULL;
  153. }
  154. }
  155. static inline unsigned dp_peer_find_hash_index(struct dp_soc *soc,
  156. union dp_align_mac_addr *mac_addr)
  157. {
  158. unsigned index;
  159. index =
  160. mac_addr->align2.bytes_ab ^
  161. mac_addr->align2.bytes_cd ^
  162. mac_addr->align2.bytes_ef;
  163. index ^= index >> soc->peer_hash.idx_bits;
  164. index &= soc->peer_hash.mask;
  165. return index;
  166. }
  167. void dp_peer_find_hash_add(struct dp_soc *soc, struct dp_peer *peer)
  168. {
  169. unsigned index;
  170. index = dp_peer_find_hash_index(soc, &peer->mac_addr);
  171. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  172. /*
  173. * It is important to add the new peer at the tail of the peer list
  174. * with the bin index. Together with having the hash_find function
  175. * search from head to tail, this ensures that if two entries with
  176. * the same MAC address are stored, the one added first will be
  177. * found first.
  178. */
  179. TAILQ_INSERT_TAIL(&soc->peer_hash.bins[index], peer, hash_list_elem);
  180. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  181. }
  182. #ifdef FEATURE_AST
  183. /*
  184. * dp_peer_ast_hash_attach() - Allocate and initialize AST Hash Table
  185. * @soc: SoC handle
  186. *
  187. * Return: None
  188. */
  189. static int dp_peer_ast_hash_attach(struct dp_soc *soc)
  190. {
  191. int i, hash_elems, log2;
  192. unsigned int max_ast_idx = wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx);
  193. hash_elems = ((max_ast_idx * DP_AST_HASH_LOAD_MULT) >>
  194. DP_AST_HASH_LOAD_SHIFT);
  195. log2 = dp_log2_ceil(hash_elems);
  196. hash_elems = 1 << log2;
  197. soc->ast_hash.mask = hash_elems - 1;
  198. soc->ast_hash.idx_bits = log2;
  199. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  200. "ast hash_elems: %d, max_ast_idx: %d",
  201. hash_elems, max_ast_idx);
  202. /* allocate an array of TAILQ peer object lists */
  203. soc->ast_hash.bins = qdf_mem_malloc(
  204. hash_elems * sizeof(TAILQ_HEAD(anonymous_tail_q,
  205. dp_ast_entry)));
  206. if (!soc->ast_hash.bins)
  207. return QDF_STATUS_E_NOMEM;
  208. for (i = 0; i < hash_elems; i++)
  209. TAILQ_INIT(&soc->ast_hash.bins[i]);
  210. return 0;
  211. }
  212. /*
  213. * dp_peer_ast_cleanup() - cleanup the references
  214. * @soc: SoC handle
  215. * @ast: ast entry
  216. *
  217. * Return: None
  218. */
  219. static inline void dp_peer_ast_cleanup(struct dp_soc *soc,
  220. struct dp_ast_entry *ast)
  221. {
  222. txrx_ast_free_cb cb = ast->callback;
  223. void *cookie = ast->cookie;
  224. /* Call the callbacks to free up the cookie */
  225. if (cb) {
  226. ast->callback = NULL;
  227. ast->cookie = NULL;
  228. cb(soc->ctrl_psoc,
  229. dp_soc_to_cdp_soc(soc),
  230. cookie,
  231. CDP_TXRX_AST_DELETE_IN_PROGRESS);
  232. }
  233. }
  234. /*
  235. * dp_peer_ast_hash_detach() - Free AST Hash table
  236. * @soc: SoC handle
  237. *
  238. * Return: None
  239. */
  240. static void dp_peer_ast_hash_detach(struct dp_soc *soc)
  241. {
  242. unsigned int index;
  243. struct dp_ast_entry *ast, *ast_next;
  244. if (!soc->ast_hash.mask)
  245. return;
  246. if (!soc->ast_hash.bins)
  247. return;
  248. qdf_spin_lock_bh(&soc->ast_lock);
  249. for (index = 0; index <= soc->ast_hash.mask; index++) {
  250. if (!TAILQ_EMPTY(&soc->ast_hash.bins[index])) {
  251. TAILQ_FOREACH_SAFE(ast, &soc->ast_hash.bins[index],
  252. hash_list_elem, ast_next) {
  253. TAILQ_REMOVE(&soc->ast_hash.bins[index], ast,
  254. hash_list_elem);
  255. dp_peer_ast_cleanup(soc, ast);
  256. qdf_mem_free(ast);
  257. }
  258. }
  259. }
  260. qdf_spin_unlock_bh(&soc->ast_lock);
  261. qdf_mem_free(soc->ast_hash.bins);
  262. soc->ast_hash.bins = NULL;
  263. }
  264. /*
  265. * dp_peer_ast_hash_index() - Compute the AST hash from MAC address
  266. * @soc: SoC handle
  267. *
  268. * Return: AST hash
  269. */
  270. static inline uint32_t dp_peer_ast_hash_index(struct dp_soc *soc,
  271. union dp_align_mac_addr *mac_addr)
  272. {
  273. uint32_t index;
  274. index =
  275. mac_addr->align2.bytes_ab ^
  276. mac_addr->align2.bytes_cd ^
  277. mac_addr->align2.bytes_ef;
  278. index ^= index >> soc->ast_hash.idx_bits;
  279. index &= soc->ast_hash.mask;
  280. return index;
  281. }
  282. /*
  283. * dp_peer_ast_hash_add() - Add AST entry into hash table
  284. * @soc: SoC handle
  285. *
  286. * This function adds the AST entry into SoC AST hash table
  287. * It assumes caller has taken the ast lock to protect the access to this table
  288. *
  289. * Return: None
  290. */
  291. static inline void dp_peer_ast_hash_add(struct dp_soc *soc,
  292. struct dp_ast_entry *ase)
  293. {
  294. uint32_t index;
  295. index = dp_peer_ast_hash_index(soc, &ase->mac_addr);
  296. TAILQ_INSERT_TAIL(&soc->ast_hash.bins[index], ase, hash_list_elem);
  297. }
  298. /*
  299. * dp_peer_ast_hash_remove() - Look up and remove AST entry from hash table
  300. * @soc: SoC handle
  301. *
  302. * This function removes the AST entry from soc AST hash table
  303. * It assumes caller has taken the ast lock to protect the access to this table
  304. *
  305. * Return: None
  306. */
  307. void dp_peer_ast_hash_remove(struct dp_soc *soc,
  308. struct dp_ast_entry *ase)
  309. {
  310. unsigned index;
  311. struct dp_ast_entry *tmpase;
  312. int found = 0;
  313. index = dp_peer_ast_hash_index(soc, &ase->mac_addr);
  314. /* Check if tail is not empty before delete*/
  315. QDF_ASSERT(!TAILQ_EMPTY(&soc->ast_hash.bins[index]));
  316. TAILQ_FOREACH(tmpase, &soc->ast_hash.bins[index], hash_list_elem) {
  317. if (tmpase == ase) {
  318. found = 1;
  319. break;
  320. }
  321. }
  322. QDF_ASSERT(found);
  323. TAILQ_REMOVE(&soc->ast_hash.bins[index], ase, hash_list_elem);
  324. }
  325. /*
  326. * dp_peer_ast_list_find() - Find AST entry by MAC address from peer ast list
  327. * @soc: SoC handle
  328. * @peer: peer handle
  329. * @ast_mac_addr: mac address
  330. *
  331. * It assumes caller has taken the ast lock to protect the access to ast list
  332. *
  333. * Return: AST entry
  334. */
  335. struct dp_ast_entry *dp_peer_ast_list_find(struct dp_soc *soc,
  336. struct dp_peer *peer,
  337. uint8_t *ast_mac_addr)
  338. {
  339. struct dp_ast_entry *ast_entry = NULL;
  340. union dp_align_mac_addr *mac_addr =
  341. (union dp_align_mac_addr *)ast_mac_addr;
  342. TAILQ_FOREACH(ast_entry, &peer->ast_entry_list, ase_list_elem) {
  343. if (!dp_peer_find_mac_addr_cmp(mac_addr,
  344. &ast_entry->mac_addr)) {
  345. return ast_entry;
  346. }
  347. }
  348. return NULL;
  349. }
  350. /*
  351. * dp_peer_ast_hash_find_by_pdevid() - Find AST entry by MAC address
  352. * @soc: SoC handle
  353. *
  354. * It assumes caller has taken the ast lock to protect the access to
  355. * AST hash table
  356. *
  357. * Return: AST entry
  358. */
  359. struct dp_ast_entry *dp_peer_ast_hash_find_by_pdevid(struct dp_soc *soc,
  360. uint8_t *ast_mac_addr,
  361. uint8_t pdev_id)
  362. {
  363. union dp_align_mac_addr local_mac_addr_aligned, *mac_addr;
  364. uint32_t index;
  365. struct dp_ast_entry *ase;
  366. qdf_mem_copy(&local_mac_addr_aligned.raw[0],
  367. ast_mac_addr, QDF_MAC_ADDR_SIZE);
  368. mac_addr = &local_mac_addr_aligned;
  369. index = dp_peer_ast_hash_index(soc, mac_addr);
  370. TAILQ_FOREACH(ase, &soc->ast_hash.bins[index], hash_list_elem) {
  371. if ((pdev_id == ase->pdev_id) &&
  372. !dp_peer_find_mac_addr_cmp(mac_addr, &ase->mac_addr)) {
  373. return ase;
  374. }
  375. }
  376. return NULL;
  377. }
  378. /*
  379. * dp_peer_ast_hash_find_soc() - Find AST entry by MAC address
  380. * @soc: SoC handle
  381. *
  382. * It assumes caller has taken the ast lock to protect the access to
  383. * AST hash table
  384. *
  385. * Return: AST entry
  386. */
  387. struct dp_ast_entry *dp_peer_ast_hash_find_soc(struct dp_soc *soc,
  388. uint8_t *ast_mac_addr)
  389. {
  390. union dp_align_mac_addr local_mac_addr_aligned, *mac_addr;
  391. unsigned index;
  392. struct dp_ast_entry *ase;
  393. qdf_mem_copy(&local_mac_addr_aligned.raw[0],
  394. ast_mac_addr, QDF_MAC_ADDR_SIZE);
  395. mac_addr = &local_mac_addr_aligned;
  396. index = dp_peer_ast_hash_index(soc, mac_addr);
  397. TAILQ_FOREACH(ase, &soc->ast_hash.bins[index], hash_list_elem) {
  398. if (dp_peer_find_mac_addr_cmp(mac_addr, &ase->mac_addr) == 0) {
  399. return ase;
  400. }
  401. }
  402. return NULL;
  403. }
  404. /*
  405. * dp_peer_map_ast() - Map the ast entry with HW AST Index
  406. * @soc: SoC handle
  407. * @peer: peer to which ast node belongs
  408. * @mac_addr: MAC address of ast node
  409. * @hw_peer_id: HW AST Index returned by target in peer map event
  410. * @vdev_id: vdev id for VAP to which the peer belongs to
  411. * @ast_hash: ast hash value in HW
  412. *
  413. * Return: None
  414. */
  415. static inline void dp_peer_map_ast(struct dp_soc *soc,
  416. struct dp_peer *peer, uint8_t *mac_addr, uint16_t hw_peer_id,
  417. uint8_t vdev_id, uint16_t ast_hash)
  418. {
  419. struct dp_ast_entry *ast_entry = NULL;
  420. enum cdp_txrx_ast_entry_type peer_type = CDP_TXRX_AST_TYPE_STATIC;
  421. if (!peer) {
  422. return;
  423. }
  424. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  425. "%s: peer %pK ID %d vid %d mac %02x:%02x:%02x:%02x:%02x:%02x",
  426. __func__, peer, hw_peer_id, vdev_id, mac_addr[0],
  427. mac_addr[1], mac_addr[2], mac_addr[3],
  428. mac_addr[4], mac_addr[5]);
  429. qdf_spin_lock_bh(&soc->ast_lock);
  430. ast_entry = dp_peer_ast_list_find(soc, peer, mac_addr);
  431. if (ast_entry) {
  432. ast_entry->ast_idx = hw_peer_id;
  433. soc->ast_table[hw_peer_id] = ast_entry;
  434. ast_entry->is_active = TRUE;
  435. peer_type = ast_entry->type;
  436. ast_entry->ast_hash_value = ast_hash;
  437. ast_entry->is_mapped = TRUE;
  438. }
  439. if (ast_entry || (peer->vdev && peer->vdev->proxysta_vdev)) {
  440. if (soc->cdp_soc.ol_ops->peer_map_event) {
  441. soc->cdp_soc.ol_ops->peer_map_event(
  442. soc->ctrl_psoc, peer->peer_ids[0],
  443. hw_peer_id, vdev_id,
  444. mac_addr, peer_type, ast_hash);
  445. }
  446. } else {
  447. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  448. "AST entry not found");
  449. }
  450. qdf_spin_unlock_bh(&soc->ast_lock);
  451. return;
  452. }
  453. void dp_peer_free_hmwds_cb(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  454. struct cdp_soc *dp_soc,
  455. void *cookie,
  456. enum cdp_ast_free_status status)
  457. {
  458. struct dp_ast_free_cb_params *param =
  459. (struct dp_ast_free_cb_params *)cookie;
  460. struct dp_soc *soc = (struct dp_soc *)dp_soc;
  461. struct dp_peer *peer = NULL;
  462. if (status != CDP_TXRX_AST_DELETED) {
  463. qdf_mem_free(cookie);
  464. return;
  465. }
  466. peer = dp_peer_find_hash_find(soc, &param->peer_mac_addr.raw[0],
  467. 0, param->vdev_id);
  468. if (peer) {
  469. dp_peer_add_ast(soc, peer,
  470. &param->mac_addr.raw[0],
  471. param->type,
  472. param->flags);
  473. dp_peer_unref_delete(peer);
  474. }
  475. qdf_mem_free(cookie);
  476. }
  477. /*
  478. * dp_peer_add_ast() - Allocate and add AST entry into peer list
  479. * @soc: SoC handle
  480. * @peer: peer to which ast node belongs
  481. * @mac_addr: MAC address of ast node
  482. * @is_self: Is this base AST entry with peer mac address
  483. *
  484. * This API is used by WDS source port learning function to
  485. * add a new AST entry into peer AST list
  486. *
  487. * Return: 0 if new entry is allocated,
  488. * -1 if entry add failed
  489. */
  490. int dp_peer_add_ast(struct dp_soc *soc,
  491. struct dp_peer *peer,
  492. uint8_t *mac_addr,
  493. enum cdp_txrx_ast_entry_type type,
  494. uint32_t flags)
  495. {
  496. struct dp_ast_entry *ast_entry = NULL;
  497. struct dp_vdev *vdev = NULL, *tmp_vdev = NULL;
  498. struct dp_pdev *pdev = NULL;
  499. uint8_t next_node_mac[6];
  500. int ret = -1;
  501. txrx_ast_free_cb cb = NULL;
  502. void *cookie = NULL;
  503. struct dp_peer *tmp_peer = NULL;
  504. bool is_peer_found = false;
  505. vdev = peer->vdev;
  506. if (!vdev) {
  507. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  508. FL("Peers vdev is NULL"));
  509. QDF_ASSERT(0);
  510. return ret;
  511. }
  512. pdev = vdev->pdev;
  513. tmp_peer = dp_peer_find_hash_find(soc, mac_addr, 0,
  514. DP_VDEV_ALL);
  515. if (tmp_peer) {
  516. tmp_vdev = tmp_peer->vdev;
  517. if (!tmp_vdev) {
  518. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  519. FL("Peers vdev is NULL"));
  520. QDF_ASSERT(0);
  521. dp_peer_unref_delete(tmp_peer);
  522. return ret;
  523. }
  524. if (tmp_vdev->pdev->pdev_id == pdev->pdev_id)
  525. is_peer_found = true;
  526. dp_peer_unref_delete(tmp_peer);
  527. }
  528. qdf_spin_lock_bh(&soc->ast_lock);
  529. if (peer->delete_in_progress) {
  530. qdf_spin_unlock_bh(&soc->ast_lock);
  531. return ret;
  532. }
  533. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  534. "%s: pdevid: %u vdev: %u ast_entry->type: %d flags: 0x%x peer_mac: %pM peer: %pK mac %pM",
  535. __func__, pdev->pdev_id, vdev->vdev_id, type, flags,
  536. peer->mac_addr.raw, peer, mac_addr);
  537. /* fw supports only 2 times the max_peers ast entries */
  538. if (soc->num_ast_entries >=
  539. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  540. qdf_spin_unlock_bh(&soc->ast_lock);
  541. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  542. FL("Max ast entries reached"));
  543. return ret;
  544. }
  545. /* If AST entry already exists , just return from here
  546. * ast entry with same mac address can exist on different radios
  547. * if ast_override support is enabled use search by pdev in this
  548. * case
  549. */
  550. if (soc->ast_override_support) {
  551. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, mac_addr,
  552. pdev->pdev_id);
  553. if (ast_entry) {
  554. if ((type == CDP_TXRX_AST_TYPE_MEC) &&
  555. (ast_entry->type == CDP_TXRX_AST_TYPE_MEC))
  556. ast_entry->is_active = TRUE;
  557. qdf_spin_unlock_bh(&soc->ast_lock);
  558. return 0;
  559. }
  560. if (is_peer_found) {
  561. /* During WDS to static roaming, peer is added
  562. * to the list before static AST entry create.
  563. * So, allow AST entry for STATIC type
  564. * even if peer is present
  565. */
  566. if (type != CDP_TXRX_AST_TYPE_STATIC) {
  567. qdf_spin_unlock_bh(&soc->ast_lock);
  568. return 0;
  569. }
  570. }
  571. } else {
  572. /* For HWMWDS_SEC entries can be added for same mac address
  573. * do not check for existing entry
  574. */
  575. if (type == CDP_TXRX_AST_TYPE_WDS_HM_SEC)
  576. goto add_ast_entry;
  577. ast_entry = dp_peer_ast_hash_find_soc(soc, mac_addr);
  578. if (ast_entry) {
  579. if ((type == CDP_TXRX_AST_TYPE_MEC) &&
  580. (ast_entry->type == CDP_TXRX_AST_TYPE_MEC))
  581. ast_entry->is_active = TRUE;
  582. if ((ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM) &&
  583. !ast_entry->delete_in_progress) {
  584. qdf_spin_unlock_bh(&soc->ast_lock);
  585. return 0;
  586. }
  587. /* Add for HMWDS entry we cannot be ignored if there
  588. * is AST entry with same mac address
  589. *
  590. * if ast entry exists with the requested mac address
  591. * send a delete command and register callback which
  592. * can take care of adding HMWDS ast enty on delete
  593. * confirmation from target
  594. */
  595. if ((type == CDP_TXRX_AST_TYPE_WDS_HM) &&
  596. soc->is_peer_map_unmap_v2) {
  597. struct dp_ast_free_cb_params *param = NULL;
  598. if (ast_entry->type ==
  599. CDP_TXRX_AST_TYPE_WDS_HM_SEC)
  600. goto add_ast_entry;
  601. /* save existing callback */
  602. if (ast_entry->callback) {
  603. cb = ast_entry->callback;
  604. cookie = ast_entry->cookie;
  605. }
  606. param = qdf_mem_malloc(sizeof(*param));
  607. if (!param) {
  608. QDF_TRACE(QDF_MODULE_ID_TXRX,
  609. QDF_TRACE_LEVEL_ERROR,
  610. "Allocation failed");
  611. qdf_spin_unlock_bh(&soc->ast_lock);
  612. return ret;
  613. }
  614. qdf_mem_copy(&param->mac_addr.raw[0], mac_addr,
  615. QDF_MAC_ADDR_SIZE);
  616. qdf_mem_copy(&param->peer_mac_addr.raw[0],
  617. &peer->mac_addr.raw[0],
  618. QDF_MAC_ADDR_SIZE);
  619. param->type = type;
  620. param->flags = flags;
  621. param->vdev_id = vdev->vdev_id;
  622. ast_entry->callback = dp_peer_free_hmwds_cb;
  623. ast_entry->pdev_id = vdev->pdev->pdev_id;
  624. ast_entry->type = type;
  625. ast_entry->cookie = (void *)param;
  626. if (!ast_entry->delete_in_progress)
  627. dp_peer_del_ast(soc, ast_entry);
  628. }
  629. /* Modify an already existing AST entry from type
  630. * WDS to MEC on promption. This serves as a fix when
  631. * backbone of interfaces are interchanged wherein
  632. * wds entr becomes its own MEC. The entry should be
  633. * replaced only when the ast_entry peer matches the
  634. * peer received in mec event. This additional check
  635. * is needed in wds repeater cases where a multicast
  636. * packet from station to the root via the repeater
  637. * should not remove the wds entry.
  638. */
  639. if ((ast_entry->type == CDP_TXRX_AST_TYPE_WDS) &&
  640. (type == CDP_TXRX_AST_TYPE_MEC) &&
  641. (ast_entry->peer == peer)) {
  642. ast_entry->is_active = FALSE;
  643. dp_peer_del_ast(soc, ast_entry);
  644. }
  645. qdf_spin_unlock_bh(&soc->ast_lock);
  646. /* Call the saved callback*/
  647. if (cb) {
  648. cb(soc->ctrl_psoc,
  649. dp_soc_to_cdp_soc(soc),
  650. cookie,
  651. CDP_TXRX_AST_DELETE_IN_PROGRESS);
  652. }
  653. return 0;
  654. }
  655. }
  656. add_ast_entry:
  657. ast_entry = (struct dp_ast_entry *)
  658. qdf_mem_malloc(sizeof(struct dp_ast_entry));
  659. if (!ast_entry) {
  660. qdf_spin_unlock_bh(&soc->ast_lock);
  661. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  662. FL("fail to allocate ast_entry"));
  663. QDF_ASSERT(0);
  664. return ret;
  665. }
  666. qdf_mem_copy(&ast_entry->mac_addr.raw[0], mac_addr, QDF_MAC_ADDR_SIZE);
  667. ast_entry->pdev_id = vdev->pdev->pdev_id;
  668. ast_entry->is_mapped = false;
  669. ast_entry->delete_in_progress = false;
  670. switch (type) {
  671. case CDP_TXRX_AST_TYPE_STATIC:
  672. peer->self_ast_entry = ast_entry;
  673. ast_entry->type = CDP_TXRX_AST_TYPE_STATIC;
  674. if (peer->vdev->opmode == wlan_op_mode_sta)
  675. ast_entry->type = CDP_TXRX_AST_TYPE_STA_BSS;
  676. break;
  677. case CDP_TXRX_AST_TYPE_SELF:
  678. peer->self_ast_entry = ast_entry;
  679. ast_entry->type = CDP_TXRX_AST_TYPE_SELF;
  680. break;
  681. case CDP_TXRX_AST_TYPE_WDS:
  682. ast_entry->next_hop = 1;
  683. ast_entry->type = CDP_TXRX_AST_TYPE_WDS;
  684. break;
  685. case CDP_TXRX_AST_TYPE_WDS_HM:
  686. ast_entry->next_hop = 1;
  687. ast_entry->type = CDP_TXRX_AST_TYPE_WDS_HM;
  688. break;
  689. case CDP_TXRX_AST_TYPE_WDS_HM_SEC:
  690. ast_entry->next_hop = 1;
  691. ast_entry->type = CDP_TXRX_AST_TYPE_WDS_HM_SEC;
  692. break;
  693. case CDP_TXRX_AST_TYPE_MEC:
  694. ast_entry->next_hop = 1;
  695. ast_entry->type = CDP_TXRX_AST_TYPE_MEC;
  696. break;
  697. case CDP_TXRX_AST_TYPE_DA:
  698. peer = peer->vdev->vap_bss_peer;
  699. ast_entry->next_hop = 1;
  700. ast_entry->type = CDP_TXRX_AST_TYPE_DA;
  701. break;
  702. default:
  703. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  704. FL("Incorrect AST entry type"));
  705. }
  706. ast_entry->is_active = TRUE;
  707. DP_STATS_INC(soc, ast.added, 1);
  708. soc->num_ast_entries++;
  709. dp_peer_ast_hash_add(soc, ast_entry);
  710. ast_entry->peer = peer;
  711. if (type == CDP_TXRX_AST_TYPE_MEC)
  712. qdf_mem_copy(next_node_mac, peer->vdev->mac_addr.raw, 6);
  713. else
  714. qdf_mem_copy(next_node_mac, peer->mac_addr.raw, 6);
  715. TAILQ_INSERT_TAIL(&peer->ast_entry_list, ast_entry, ase_list_elem);
  716. if ((ast_entry->type != CDP_TXRX_AST_TYPE_STATIC) &&
  717. (ast_entry->type != CDP_TXRX_AST_TYPE_SELF) &&
  718. (ast_entry->type != CDP_TXRX_AST_TYPE_STA_BSS) &&
  719. (ast_entry->type != CDP_TXRX_AST_TYPE_WDS_HM_SEC)) {
  720. if (QDF_STATUS_SUCCESS ==
  721. soc->cdp_soc.ol_ops->peer_add_wds_entry(
  722. soc->ctrl_psoc,
  723. peer->vdev->vdev_id,
  724. peer->mac_addr.raw,
  725. mac_addr,
  726. next_node_mac,
  727. flags)) {
  728. qdf_spin_unlock_bh(&soc->ast_lock);
  729. return 0;
  730. }
  731. }
  732. qdf_spin_unlock_bh(&soc->ast_lock);
  733. return ret;
  734. }
  735. /*
  736. * dp_peer_del_ast() - Delete and free AST entry
  737. * @soc: SoC handle
  738. * @ast_entry: AST entry of the node
  739. *
  740. * This function removes the AST entry from peer and soc tables
  741. * It assumes caller has taken the ast lock to protect the access to these
  742. * tables
  743. *
  744. * Return: None
  745. */
  746. void dp_peer_del_ast(struct dp_soc *soc, struct dp_ast_entry *ast_entry)
  747. {
  748. struct dp_peer *peer;
  749. if (!ast_entry)
  750. return;
  751. peer = ast_entry->peer;
  752. dp_peer_ast_send_wds_del(soc, ast_entry);
  753. /*
  754. * release the reference only if it is mapped
  755. * to ast_table
  756. */
  757. if (ast_entry->is_mapped)
  758. soc->ast_table[ast_entry->ast_idx] = NULL;
  759. /*
  760. * if peer map v2 is enabled we are not freeing ast entry
  761. * here and it is supposed to be freed in unmap event (after
  762. * we receive delete confirmation from target)
  763. *
  764. * if peer_id is invalid we did not get the peer map event
  765. * for the peer free ast entry from here only in this case
  766. */
  767. if (soc->is_peer_map_unmap_v2) {
  768. /*
  769. * For HM_SEC and SELF type we do not receive unmap event
  770. * free ast_entry from here it self
  771. */
  772. if ((ast_entry->type != CDP_TXRX_AST_TYPE_WDS_HM_SEC) &&
  773. (ast_entry->type != CDP_TXRX_AST_TYPE_SELF))
  774. return;
  775. }
  776. /* SELF and STATIC entries are removed in teardown itself */
  777. if (ast_entry->next_hop)
  778. TAILQ_REMOVE(&peer->ast_entry_list, ast_entry, ase_list_elem);
  779. DP_STATS_INC(soc, ast.deleted, 1);
  780. dp_peer_ast_hash_remove(soc, ast_entry);
  781. dp_peer_ast_cleanup(soc, ast_entry);
  782. qdf_mem_free(ast_entry);
  783. soc->num_ast_entries--;
  784. }
  785. /*
  786. * dp_peer_update_ast() - Delete and free AST entry
  787. * @soc: SoC handle
  788. * @peer: peer to which ast node belongs
  789. * @ast_entry: AST entry of the node
  790. * @flags: wds or hmwds
  791. *
  792. * This function update the AST entry to the roamed peer and soc tables
  793. * It assumes caller has taken the ast lock to protect the access to these
  794. * tables
  795. *
  796. * Return: 0 if ast entry is updated successfully
  797. * -1 failure
  798. */
  799. int dp_peer_update_ast(struct dp_soc *soc, struct dp_peer *peer,
  800. struct dp_ast_entry *ast_entry, uint32_t flags)
  801. {
  802. int ret = -1;
  803. struct dp_peer *old_peer;
  804. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  805. "%s: ast_entry->type: %d pdevid: %u vdevid: %u flags: 0x%x mac_addr: %pM peer_mac: %pM\n",
  806. __func__, ast_entry->type, peer->vdev->pdev->pdev_id,
  807. peer->vdev->vdev_id, flags, ast_entry->mac_addr.raw,
  808. peer->mac_addr.raw);
  809. /* Do not send AST update in below cases
  810. * 1) Ast entry delete has already triggered
  811. * 2) Peer delete is already triggered
  812. * 3) We did not get the HTT map for create event
  813. */
  814. if (ast_entry->delete_in_progress || peer->delete_in_progress ||
  815. !ast_entry->is_mapped)
  816. return ret;
  817. if ((ast_entry->type == CDP_TXRX_AST_TYPE_STATIC) ||
  818. (ast_entry->type == CDP_TXRX_AST_TYPE_SELF) ||
  819. (ast_entry->type == CDP_TXRX_AST_TYPE_STA_BSS) ||
  820. (ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC))
  821. return 0;
  822. /*
  823. * Avoids flood of WMI update messages sent to FW for same peer.
  824. */
  825. if (qdf_unlikely(ast_entry->peer == peer) &&
  826. (ast_entry->type == CDP_TXRX_AST_TYPE_WDS) &&
  827. (ast_entry->peer->vdev == peer->vdev) &&
  828. (ast_entry->is_active))
  829. return 0;
  830. old_peer = ast_entry->peer;
  831. TAILQ_REMOVE(&old_peer->ast_entry_list, ast_entry, ase_list_elem);
  832. ast_entry->peer = peer;
  833. ast_entry->type = CDP_TXRX_AST_TYPE_WDS;
  834. ast_entry->pdev_id = peer->vdev->pdev->pdev_id;
  835. ast_entry->is_active = TRUE;
  836. TAILQ_INSERT_TAIL(&peer->ast_entry_list, ast_entry, ase_list_elem);
  837. ret = soc->cdp_soc.ol_ops->peer_update_wds_entry(
  838. soc->ctrl_psoc,
  839. peer->vdev->vdev_id,
  840. ast_entry->mac_addr.raw,
  841. peer->mac_addr.raw,
  842. flags);
  843. return ret;
  844. }
  845. /*
  846. * dp_peer_ast_get_pdev_id() - get pdev_id from the ast entry
  847. * @soc: SoC handle
  848. * @ast_entry: AST entry of the node
  849. *
  850. * This function gets the pdev_id from the ast entry.
  851. *
  852. * Return: (uint8_t) pdev_id
  853. */
  854. uint8_t dp_peer_ast_get_pdev_id(struct dp_soc *soc,
  855. struct dp_ast_entry *ast_entry)
  856. {
  857. return ast_entry->pdev_id;
  858. }
  859. /*
  860. * dp_peer_ast_get_next_hop() - get next_hop from the ast entry
  861. * @soc: SoC handle
  862. * @ast_entry: AST entry of the node
  863. *
  864. * This function gets the next hop from the ast entry.
  865. *
  866. * Return: (uint8_t) next_hop
  867. */
  868. uint8_t dp_peer_ast_get_next_hop(struct dp_soc *soc,
  869. struct dp_ast_entry *ast_entry)
  870. {
  871. return ast_entry->next_hop;
  872. }
  873. /*
  874. * dp_peer_ast_set_type() - set type from the ast entry
  875. * @soc: SoC handle
  876. * @ast_entry: AST entry of the node
  877. *
  878. * This function sets the type in the ast entry.
  879. *
  880. * Return:
  881. */
  882. void dp_peer_ast_set_type(struct dp_soc *soc,
  883. struct dp_ast_entry *ast_entry,
  884. enum cdp_txrx_ast_entry_type type)
  885. {
  886. ast_entry->type = type;
  887. }
  888. #else
  889. int dp_peer_add_ast(struct dp_soc *soc, struct dp_peer *peer,
  890. uint8_t *mac_addr, enum cdp_txrx_ast_entry_type type,
  891. uint32_t flags)
  892. {
  893. return 1;
  894. }
  895. void dp_peer_del_ast(struct dp_soc *soc, struct dp_ast_entry *ast_entry)
  896. {
  897. }
  898. int dp_peer_update_ast(struct dp_soc *soc, struct dp_peer *peer,
  899. struct dp_ast_entry *ast_entry, uint32_t flags)
  900. {
  901. return 1;
  902. }
  903. struct dp_ast_entry *dp_peer_ast_hash_find_soc(struct dp_soc *soc,
  904. uint8_t *ast_mac_addr)
  905. {
  906. return NULL;
  907. }
  908. struct dp_ast_entry *dp_peer_ast_hash_find_by_pdevid(struct dp_soc *soc,
  909. uint8_t *ast_mac_addr,
  910. uint8_t pdev_id)
  911. {
  912. return NULL;
  913. }
  914. static int dp_peer_ast_hash_attach(struct dp_soc *soc)
  915. {
  916. return 0;
  917. }
  918. static inline void dp_peer_map_ast(struct dp_soc *soc,
  919. struct dp_peer *peer, uint8_t *mac_addr, uint16_t hw_peer_id,
  920. uint8_t vdev_id, uint16_t ast_hash)
  921. {
  922. return;
  923. }
  924. static void dp_peer_ast_hash_detach(struct dp_soc *soc)
  925. {
  926. }
  927. void dp_peer_ast_set_type(struct dp_soc *soc,
  928. struct dp_ast_entry *ast_entry,
  929. enum cdp_txrx_ast_entry_type type)
  930. {
  931. }
  932. uint8_t dp_peer_ast_get_pdev_id(struct dp_soc *soc,
  933. struct dp_ast_entry *ast_entry)
  934. {
  935. return 0xff;
  936. }
  937. uint8_t dp_peer_ast_get_next_hop(struct dp_soc *soc,
  938. struct dp_ast_entry *ast_entry)
  939. {
  940. return 0xff;
  941. }
  942. int dp_peer_update_ast(struct dp_soc *soc, struct dp_peer *peer,
  943. struct dp_ast_entry *ast_entry, uint32_t flags)
  944. {
  945. return 1;
  946. }
  947. #endif
  948. void dp_peer_ast_send_wds_del(struct dp_soc *soc,
  949. struct dp_ast_entry *ast_entry)
  950. {
  951. struct dp_peer *peer = ast_entry->peer;
  952. struct cdp_soc_t *cdp_soc = &soc->cdp_soc;
  953. if (ast_entry->delete_in_progress)
  954. return;
  955. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_TRACE,
  956. "%s: ast_entry->type: %d pdevid: %u vdev: %u mac_addr: %pM next_hop: %u peer_mac: %pM\n",
  957. __func__, ast_entry->type, peer->vdev->pdev->pdev_id,
  958. peer->vdev->vdev_id, ast_entry->mac_addr.raw,
  959. ast_entry->next_hop, ast_entry->peer->mac_addr.raw);
  960. if (ast_entry->next_hop) {
  961. cdp_soc->ol_ops->peer_del_wds_entry(soc->ctrl_psoc,
  962. peer->vdev->vdev_id,
  963. ast_entry->mac_addr.raw,
  964. ast_entry->type);
  965. }
  966. /* Remove SELF and STATIC entries in teardown itself */
  967. if (!ast_entry->next_hop) {
  968. TAILQ_REMOVE(&peer->ast_entry_list, ast_entry, ase_list_elem);
  969. peer->self_ast_entry = NULL;
  970. ast_entry->peer = NULL;
  971. }
  972. ast_entry->delete_in_progress = true;
  973. }
  974. /**
  975. * dp_peer_ast_free_entry_by_mac() - find ast entry by MAC address and delete
  976. * @soc: soc handle
  977. * @peer: peer handle
  978. * @mac_addr: mac address of the AST entry to searc and delete
  979. *
  980. * find the ast entry from the peer list using the mac address and free
  981. * the entry.
  982. *
  983. * Return: SUCCESS or NOENT
  984. */
  985. static int dp_peer_ast_free_entry_by_mac(struct dp_soc *soc,
  986. struct dp_peer *peer,
  987. uint8_t *mac_addr)
  988. {
  989. struct dp_ast_entry *ast_entry;
  990. void *cookie = NULL;
  991. txrx_ast_free_cb cb = NULL;
  992. /*
  993. * release the reference only if it is mapped
  994. * to ast_table
  995. */
  996. qdf_spin_lock_bh(&soc->ast_lock);
  997. ast_entry = dp_peer_ast_list_find(soc, peer, mac_addr);
  998. if (!ast_entry) {
  999. qdf_spin_unlock_bh(&soc->ast_lock);
  1000. return QDF_STATUS_E_NOENT;
  1001. } else if (ast_entry->is_mapped) {
  1002. soc->ast_table[ast_entry->ast_idx] = NULL;
  1003. }
  1004. TAILQ_REMOVE(&peer->ast_entry_list, ast_entry, ase_list_elem);
  1005. DP_STATS_INC(soc, ast.deleted, 1);
  1006. dp_peer_ast_hash_remove(soc, ast_entry);
  1007. cb = ast_entry->callback;
  1008. cookie = ast_entry->cookie;
  1009. ast_entry->callback = NULL;
  1010. ast_entry->cookie = NULL;
  1011. if (ast_entry == peer->self_ast_entry)
  1012. peer->self_ast_entry = NULL;
  1013. soc->num_ast_entries--;
  1014. qdf_spin_unlock_bh(&soc->ast_lock);
  1015. if (cb) {
  1016. cb(soc->ctrl_psoc,
  1017. dp_soc_to_cdp_soc(soc),
  1018. cookie,
  1019. CDP_TXRX_AST_DELETED);
  1020. }
  1021. qdf_mem_free(ast_entry);
  1022. return QDF_STATUS_SUCCESS;
  1023. }
  1024. struct dp_peer *dp_peer_find_hash_find(struct dp_soc *soc,
  1025. uint8_t *peer_mac_addr, int mac_addr_is_aligned, uint8_t vdev_id)
  1026. {
  1027. union dp_align_mac_addr local_mac_addr_aligned, *mac_addr;
  1028. unsigned index;
  1029. struct dp_peer *peer;
  1030. if (mac_addr_is_aligned) {
  1031. mac_addr = (union dp_align_mac_addr *) peer_mac_addr;
  1032. } else {
  1033. qdf_mem_copy(
  1034. &local_mac_addr_aligned.raw[0],
  1035. peer_mac_addr, QDF_MAC_ADDR_SIZE);
  1036. mac_addr = &local_mac_addr_aligned;
  1037. }
  1038. index = dp_peer_find_hash_index(soc, mac_addr);
  1039. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  1040. TAILQ_FOREACH(peer, &soc->peer_hash.bins[index], hash_list_elem) {
  1041. if (dp_peer_find_mac_addr_cmp(mac_addr, &peer->mac_addr) == 0 &&
  1042. ((peer->vdev->vdev_id == vdev_id) ||
  1043. (vdev_id == DP_VDEV_ALL))) {
  1044. /* found it - increment the ref count before releasing
  1045. * the lock
  1046. */
  1047. qdf_atomic_inc(&peer->ref_cnt);
  1048. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1049. return peer;
  1050. }
  1051. }
  1052. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  1053. return NULL; /* failure */
  1054. }
  1055. void dp_peer_find_hash_remove(struct dp_soc *soc, struct dp_peer *peer)
  1056. {
  1057. unsigned index;
  1058. struct dp_peer *tmppeer = NULL;
  1059. int found = 0;
  1060. index = dp_peer_find_hash_index(soc, &peer->mac_addr);
  1061. /* Check if tail is not empty before delete*/
  1062. QDF_ASSERT(!TAILQ_EMPTY(&soc->peer_hash.bins[index]));
  1063. /*
  1064. * DO NOT take the peer_ref_mutex lock here - it needs to be taken
  1065. * by the caller.
  1066. * The caller needs to hold the lock from the time the peer object's
  1067. * reference count is decremented and tested up through the time the
  1068. * reference to the peer object is removed from the hash table, by
  1069. * this function.
  1070. * Holding the lock only while removing the peer object reference
  1071. * from the hash table keeps the hash table consistent, but does not
  1072. * protect against a new HL tx context starting to use the peer object
  1073. * if it looks up the peer object from its MAC address just after the
  1074. * peer ref count is decremented to zero, but just before the peer
  1075. * object reference is removed from the hash table.
  1076. */
  1077. TAILQ_FOREACH(tmppeer, &soc->peer_hash.bins[index], hash_list_elem) {
  1078. if (tmppeer == peer) {
  1079. found = 1;
  1080. break;
  1081. }
  1082. }
  1083. QDF_ASSERT(found);
  1084. TAILQ_REMOVE(&soc->peer_hash.bins[index], peer, hash_list_elem);
  1085. }
  1086. void dp_peer_find_hash_erase(struct dp_soc *soc)
  1087. {
  1088. int i;
  1089. /*
  1090. * Not really necessary to take peer_ref_mutex lock - by this point,
  1091. * it's known that the soc is no longer in use.
  1092. */
  1093. for (i = 0; i <= soc->peer_hash.mask; i++) {
  1094. if (!TAILQ_EMPTY(&soc->peer_hash.bins[i])) {
  1095. struct dp_peer *peer, *peer_next;
  1096. /*
  1097. * TAILQ_FOREACH_SAFE must be used here to avoid any
  1098. * memory access violation after peer is freed
  1099. */
  1100. TAILQ_FOREACH_SAFE(peer, &soc->peer_hash.bins[i],
  1101. hash_list_elem, peer_next) {
  1102. /*
  1103. * Don't remove the peer from the hash table -
  1104. * that would modify the list we are currently
  1105. * traversing, and it's not necessary anyway.
  1106. */
  1107. /*
  1108. * Artificially adjust the peer's ref count to
  1109. * 1, so it will get deleted by
  1110. * dp_peer_unref_delete.
  1111. */
  1112. /* set to zero */
  1113. qdf_atomic_init(&peer->ref_cnt);
  1114. /* incr to one */
  1115. qdf_atomic_inc(&peer->ref_cnt);
  1116. dp_peer_unref_delete(peer);
  1117. }
  1118. }
  1119. }
  1120. }
  1121. static void dp_peer_ast_table_detach(struct dp_soc *soc)
  1122. {
  1123. if (soc->ast_table) {
  1124. qdf_mem_free(soc->ast_table);
  1125. soc->ast_table = NULL;
  1126. }
  1127. }
  1128. static void dp_peer_find_map_detach(struct dp_soc *soc)
  1129. {
  1130. if (soc->peer_id_to_obj_map) {
  1131. qdf_mem_free(soc->peer_id_to_obj_map);
  1132. soc->peer_id_to_obj_map = NULL;
  1133. }
  1134. }
  1135. int dp_peer_find_attach(struct dp_soc *soc)
  1136. {
  1137. if (dp_peer_find_map_attach(soc))
  1138. return 1;
  1139. if (dp_peer_find_hash_attach(soc)) {
  1140. dp_peer_find_map_detach(soc);
  1141. return 1;
  1142. }
  1143. if (dp_peer_ast_table_attach(soc)) {
  1144. dp_peer_find_hash_detach(soc);
  1145. dp_peer_find_map_detach(soc);
  1146. return 1;
  1147. }
  1148. if (dp_peer_ast_hash_attach(soc)) {
  1149. dp_peer_ast_table_detach(soc);
  1150. dp_peer_find_hash_detach(soc);
  1151. dp_peer_find_map_detach(soc);
  1152. return 1;
  1153. }
  1154. return 0; /* success */
  1155. }
  1156. void dp_rx_tid_stats_cb(struct dp_soc *soc, void *cb_ctxt,
  1157. union hal_reo_status *reo_status)
  1158. {
  1159. struct dp_rx_tid *rx_tid = (struct dp_rx_tid *)cb_ctxt;
  1160. struct hal_reo_queue_status *queue_status = &(reo_status->queue_status);
  1161. if (queue_status->header.status == HAL_REO_CMD_DRAIN)
  1162. return;
  1163. if (queue_status->header.status != HAL_REO_CMD_SUCCESS) {
  1164. DP_PRINT_STATS("REO stats failure %d for TID %d\n",
  1165. queue_status->header.status, rx_tid->tid);
  1166. return;
  1167. }
  1168. DP_PRINT_STATS("REO queue stats (TID: %d):\n"
  1169. "ssn: %d\n"
  1170. "curr_idx : %d\n"
  1171. "pn_31_0 : %08x\n"
  1172. "pn_63_32 : %08x\n"
  1173. "pn_95_64 : %08x\n"
  1174. "pn_127_96 : %08x\n"
  1175. "last_rx_enq_tstamp : %08x\n"
  1176. "last_rx_deq_tstamp : %08x\n"
  1177. "rx_bitmap_31_0 : %08x\n"
  1178. "rx_bitmap_63_32 : %08x\n"
  1179. "rx_bitmap_95_64 : %08x\n"
  1180. "rx_bitmap_127_96 : %08x\n"
  1181. "rx_bitmap_159_128 : %08x\n"
  1182. "rx_bitmap_191_160 : %08x\n"
  1183. "rx_bitmap_223_192 : %08x\n"
  1184. "rx_bitmap_255_224 : %08x\n",
  1185. rx_tid->tid,
  1186. queue_status->ssn, queue_status->curr_idx,
  1187. queue_status->pn_31_0, queue_status->pn_63_32,
  1188. queue_status->pn_95_64, queue_status->pn_127_96,
  1189. queue_status->last_rx_enq_tstamp,
  1190. queue_status->last_rx_deq_tstamp,
  1191. queue_status->rx_bitmap_31_0,
  1192. queue_status->rx_bitmap_63_32,
  1193. queue_status->rx_bitmap_95_64,
  1194. queue_status->rx_bitmap_127_96,
  1195. queue_status->rx_bitmap_159_128,
  1196. queue_status->rx_bitmap_191_160,
  1197. queue_status->rx_bitmap_223_192,
  1198. queue_status->rx_bitmap_255_224);
  1199. DP_PRINT_STATS(
  1200. "curr_mpdu_cnt : %d\n"
  1201. "curr_msdu_cnt : %d\n"
  1202. "fwd_timeout_cnt : %d\n"
  1203. "fwd_bar_cnt : %d\n"
  1204. "dup_cnt : %d\n"
  1205. "frms_in_order_cnt : %d\n"
  1206. "bar_rcvd_cnt : %d\n"
  1207. "mpdu_frms_cnt : %d\n"
  1208. "msdu_frms_cnt : %d\n"
  1209. "total_byte_cnt : %d\n"
  1210. "late_recv_mpdu_cnt : %d\n"
  1211. "win_jump_2k : %d\n"
  1212. "hole_cnt : %d\n",
  1213. queue_status->curr_mpdu_cnt,
  1214. queue_status->curr_msdu_cnt,
  1215. queue_status->fwd_timeout_cnt,
  1216. queue_status->fwd_bar_cnt,
  1217. queue_status->dup_cnt,
  1218. queue_status->frms_in_order_cnt,
  1219. queue_status->bar_rcvd_cnt,
  1220. queue_status->mpdu_frms_cnt,
  1221. queue_status->msdu_frms_cnt,
  1222. queue_status->total_cnt,
  1223. queue_status->late_recv_mpdu_cnt,
  1224. queue_status->win_jump_2k,
  1225. queue_status->hole_cnt);
  1226. DP_PRINT_STATS("Addba Req : %d\n"
  1227. "Addba Resp : %d\n"
  1228. "Addba Resp success : %d\n"
  1229. "Addba Resp failed : %d\n"
  1230. "Delba Req received : %d\n"
  1231. "Delba Tx success : %d\n"
  1232. "Delba Tx Fail : %d\n"
  1233. "BA window size : %d\n"
  1234. "Pn size : %d\n",
  1235. rx_tid->num_of_addba_req,
  1236. rx_tid->num_of_addba_resp,
  1237. rx_tid->num_addba_rsp_success,
  1238. rx_tid->num_addba_rsp_failed,
  1239. rx_tid->num_of_delba_req,
  1240. rx_tid->delba_tx_success_cnt,
  1241. rx_tid->delba_tx_fail_cnt,
  1242. rx_tid->ba_win_size,
  1243. rx_tid->pn_size);
  1244. }
  1245. static inline struct dp_peer *dp_peer_find_add_id(struct dp_soc *soc,
  1246. uint8_t *peer_mac_addr, uint16_t peer_id, uint16_t hw_peer_id,
  1247. uint8_t vdev_id)
  1248. {
  1249. struct dp_peer *peer;
  1250. QDF_ASSERT(peer_id <= soc->max_peers);
  1251. /* check if there's already a peer object with this MAC address */
  1252. peer = dp_peer_find_hash_find(soc, peer_mac_addr,
  1253. 0 /* is aligned */, vdev_id);
  1254. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1255. "%s: peer %pK ID %d vid %d mac %02x:%02x:%02x:%02x:%02x:%02x",
  1256. __func__, peer, peer_id, vdev_id, peer_mac_addr[0],
  1257. peer_mac_addr[1], peer_mac_addr[2], peer_mac_addr[3],
  1258. peer_mac_addr[4], peer_mac_addr[5]);
  1259. if (peer) {
  1260. /* peer's ref count was already incremented by
  1261. * peer_find_hash_find
  1262. */
  1263. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1264. "%s: ref_cnt: %d", __func__,
  1265. qdf_atomic_read(&peer->ref_cnt));
  1266. if (!soc->peer_id_to_obj_map[peer_id])
  1267. soc->peer_id_to_obj_map[peer_id] = peer;
  1268. else {
  1269. /* Peer map event came for peer_id which
  1270. * is already mapped, this is not expected
  1271. */
  1272. QDF_ASSERT(0);
  1273. }
  1274. if (dp_peer_find_add_id_to_obj(peer, peer_id)) {
  1275. /* TBDXXX: assert for now */
  1276. QDF_ASSERT(0);
  1277. }
  1278. return peer;
  1279. }
  1280. return NULL;
  1281. }
  1282. /**
  1283. * dp_rx_peer_map_handler() - handle peer map event from firmware
  1284. * @soc_handle - genereic soc handle
  1285. * @peeri_id - peer_id from firmware
  1286. * @hw_peer_id - ast index for this peer
  1287. * @vdev_id - vdev ID
  1288. * @peer_mac_addr - mac address of the peer
  1289. * @ast_hash - ast hash value
  1290. * @is_wds - flag to indicate peer map event for WDS ast entry
  1291. *
  1292. * associate the peer_id that firmware provided with peer entry
  1293. * and update the ast table in the host with the hw_peer_id.
  1294. *
  1295. * Return: none
  1296. */
  1297. void
  1298. dp_rx_peer_map_handler(struct dp_soc *soc, uint16_t peer_id,
  1299. uint16_t hw_peer_id, uint8_t vdev_id,
  1300. uint8_t *peer_mac_addr, uint16_t ast_hash,
  1301. uint8_t is_wds)
  1302. {
  1303. struct dp_peer *peer = NULL;
  1304. enum cdp_txrx_ast_entry_type type = CDP_TXRX_AST_TYPE_STATIC;
  1305. dp_info("peer_map_event (soc:%pK): peer_id %d, hw_peer_id %d, peer_mac %02x:%02x:%02x:%02x:%02x:%02x, vdev_id %d",
  1306. soc, peer_id, hw_peer_id, peer_mac_addr[0], peer_mac_addr[1],
  1307. peer_mac_addr[2], peer_mac_addr[3], peer_mac_addr[4],
  1308. peer_mac_addr[5], vdev_id);
  1309. /* Peer map event for WDS ast entry get the peer from
  1310. * obj map
  1311. */
  1312. if (is_wds) {
  1313. peer = soc->peer_id_to_obj_map[peer_id];
  1314. /*
  1315. * In certain cases like Auth attack on a repeater
  1316. * can result in the number of ast_entries falling
  1317. * in the same hash bucket to exceed the max_skid
  1318. * length supported by HW in root AP. In these cases
  1319. * the FW will return the hw_peer_id (ast_index) as
  1320. * 0xffff indicating HW could not add the entry in
  1321. * its table. Host has to delete the entry from its
  1322. * table in these cases.
  1323. */
  1324. if (hw_peer_id == HTT_INVALID_PEER) {
  1325. DP_STATS_INC(soc, ast.map_err, 1);
  1326. if (!dp_peer_ast_free_entry_by_mac(soc,
  1327. peer,
  1328. peer_mac_addr))
  1329. return;
  1330. dp_alert("AST entry not found with peer %pK peer_id %u peer_mac %pM mac_addr %pM vdev_id %u next_hop %u",
  1331. peer, peer->peer_ids[0],
  1332. peer->mac_addr.raw, peer_mac_addr, vdev_id,
  1333. is_wds);
  1334. return;
  1335. }
  1336. } else {
  1337. /*
  1338. * It's the responsibility of the CP and FW to ensure
  1339. * that peer is created successfully. Ideally DP should
  1340. * not hit the below condition for directly assocaited
  1341. * peers.
  1342. */
  1343. if ((hw_peer_id < 0) ||
  1344. (hw_peer_id >=
  1345. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx))) {
  1346. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1347. "invalid hw_peer_id: %d", hw_peer_id);
  1348. qdf_assert_always(0);
  1349. }
  1350. peer = dp_peer_find_add_id(soc, peer_mac_addr, peer_id,
  1351. hw_peer_id, vdev_id);
  1352. if (peer) {
  1353. if (wlan_op_mode_sta == peer->vdev->opmode &&
  1354. qdf_mem_cmp(peer->mac_addr.raw,
  1355. peer->vdev->mac_addr.raw,
  1356. QDF_MAC_ADDR_SIZE) != 0) {
  1357. dp_info("STA vdev bss_peer!!!!");
  1358. peer->bss_peer = 1;
  1359. peer->vdev->vap_bss_peer = peer;
  1360. }
  1361. if (peer->vdev->opmode == wlan_op_mode_sta) {
  1362. peer->vdev->bss_ast_hash = ast_hash;
  1363. peer->vdev->bss_ast_idx = hw_peer_id;
  1364. }
  1365. /* Add ast entry incase self ast entry is
  1366. * deleted due to DP CP sync issue
  1367. *
  1368. * self_ast_entry is modified in peer create
  1369. * and peer unmap path which cannot run in
  1370. * parllel with peer map, no lock need before
  1371. * referring it
  1372. */
  1373. if (!peer->self_ast_entry) {
  1374. dp_info("Add self ast from map %pM",
  1375. peer_mac_addr);
  1376. dp_peer_add_ast(soc, peer,
  1377. peer_mac_addr,
  1378. type, 0);
  1379. }
  1380. }
  1381. }
  1382. dp_peer_map_ast(soc, peer, peer_mac_addr,
  1383. hw_peer_id, vdev_id, ast_hash);
  1384. }
  1385. /**
  1386. * dp_rx_peer_unmap_handler() - handle peer unmap event from firmware
  1387. * @soc_handle - genereic soc handle
  1388. * @peeri_id - peer_id from firmware
  1389. * @vdev_id - vdev ID
  1390. * @mac_addr - mac address of the peer or wds entry
  1391. * @is_wds - flag to indicate peer map event for WDS ast entry
  1392. *
  1393. * Return: none
  1394. */
  1395. void
  1396. dp_rx_peer_unmap_handler(struct dp_soc *soc, uint16_t peer_id,
  1397. uint8_t vdev_id, uint8_t *mac_addr,
  1398. uint8_t is_wds)
  1399. {
  1400. struct dp_peer *peer;
  1401. uint8_t i;
  1402. peer = __dp_peer_find_by_id(soc, peer_id);
  1403. /*
  1404. * Currently peer IDs are assigned for vdevs as well as peers.
  1405. * If the peer ID is for a vdev, then the peer pointer stored
  1406. * in peer_id_to_obj_map will be NULL.
  1407. */
  1408. if (!peer) {
  1409. dp_err("Received unmap event for invalid peer_id %u", peer_id);
  1410. return;
  1411. }
  1412. /* If V2 Peer map messages are enabled AST entry has to be freed here
  1413. */
  1414. if (soc->is_peer_map_unmap_v2 && is_wds) {
  1415. if (!dp_peer_ast_free_entry_by_mac(soc, peer, mac_addr))
  1416. return;
  1417. dp_alert("AST entry not found with peer %pK peer_id %u peer_mac %pM mac_addr %pM vdev_id %u next_hop %u",
  1418. peer, peer->peer_ids[0],
  1419. peer->mac_addr.raw, mac_addr, vdev_id,
  1420. is_wds);
  1421. return;
  1422. }
  1423. dp_info("peer_unmap_event (soc:%pK) peer_id %d peer %pK",
  1424. soc, peer_id, peer);
  1425. soc->peer_id_to_obj_map[peer_id] = NULL;
  1426. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++) {
  1427. if (peer->peer_ids[i] == peer_id) {
  1428. peer->peer_ids[i] = HTT_INVALID_PEER;
  1429. break;
  1430. }
  1431. }
  1432. if (soc->cdp_soc.ol_ops->peer_unmap_event) {
  1433. soc->cdp_soc.ol_ops->peer_unmap_event(soc->ctrl_psoc,
  1434. peer_id, vdev_id);
  1435. }
  1436. /*
  1437. * Remove a reference to the peer.
  1438. * If there are no more references, delete the peer object.
  1439. */
  1440. dp_peer_unref_delete(peer);
  1441. }
  1442. void
  1443. dp_peer_find_detach(struct dp_soc *soc)
  1444. {
  1445. dp_peer_find_map_detach(soc);
  1446. dp_peer_find_hash_detach(soc);
  1447. dp_peer_ast_hash_detach(soc);
  1448. dp_peer_ast_table_detach(soc);
  1449. }
  1450. static void dp_rx_tid_update_cb(struct dp_soc *soc, void *cb_ctxt,
  1451. union hal_reo_status *reo_status)
  1452. {
  1453. struct dp_rx_tid *rx_tid = (struct dp_rx_tid *)cb_ctxt;
  1454. if ((reo_status->rx_queue_status.header.status !=
  1455. HAL_REO_CMD_SUCCESS) &&
  1456. (reo_status->rx_queue_status.header.status !=
  1457. HAL_REO_CMD_DRAIN)) {
  1458. /* Should not happen normally. Just print error for now */
  1459. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1460. "%s: Rx tid HW desc update failed(%d): tid %d",
  1461. __func__,
  1462. reo_status->rx_queue_status.header.status,
  1463. rx_tid->tid);
  1464. }
  1465. }
  1466. /*
  1467. * dp_find_peer_by_addr - find peer instance by mac address
  1468. * @dev: physical device instance
  1469. * @peer_mac_addr: peer mac address
  1470. *
  1471. * Return: peer instance pointer
  1472. */
  1473. void *dp_find_peer_by_addr(struct cdp_pdev *dev, uint8_t *peer_mac_addr)
  1474. {
  1475. struct dp_pdev *pdev = (struct dp_pdev *)dev;
  1476. struct dp_peer *peer;
  1477. peer = dp_peer_find_hash_find(pdev->soc, peer_mac_addr, 0, DP_VDEV_ALL);
  1478. if (!peer)
  1479. return NULL;
  1480. dp_verbose_debug("peer %pK mac: %pM", peer,
  1481. peer->mac_addr.raw);
  1482. /* ref_cnt is incremented inside dp_peer_find_hash_find().
  1483. * Decrement it here.
  1484. */
  1485. dp_peer_unref_delete(peer);
  1486. return peer;
  1487. }
  1488. static bool dp_get_peer_vdev_roaming_in_progress(struct dp_peer *peer)
  1489. {
  1490. struct ol_if_ops *ol_ops = NULL;
  1491. bool is_roaming = false;
  1492. uint8_t vdev_id = -1;
  1493. if (!peer) {
  1494. dp_info("Peer is NULL. No roaming possible");
  1495. return false;
  1496. }
  1497. ol_ops = peer->vdev->pdev->soc->cdp_soc.ol_ops;
  1498. if (ol_ops && ol_ops->is_roam_inprogress) {
  1499. dp_get_vdevid(peer, &vdev_id);
  1500. is_roaming = ol_ops->is_roam_inprogress(vdev_id);
  1501. }
  1502. dp_info("peer: %pM, vdev_id: %d, is_roaming: %d",
  1503. peer->mac_addr.raw, vdev_id, is_roaming);
  1504. return is_roaming;
  1505. }
  1506. QDF_STATUS dp_rx_tid_update_wifi3(struct dp_peer *peer, int tid, uint32_t
  1507. ba_window_size, uint32_t start_seq)
  1508. {
  1509. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  1510. struct dp_soc *soc = peer->vdev->pdev->soc;
  1511. struct hal_reo_cmd_params params;
  1512. qdf_mem_zero(&params, sizeof(params));
  1513. params.std.need_status = 1;
  1514. params.std.addr_lo = rx_tid->hw_qdesc_paddr & 0xffffffff;
  1515. params.std.addr_hi = (uint64_t)(rx_tid->hw_qdesc_paddr) >> 32;
  1516. params.u.upd_queue_params.update_ba_window_size = 1;
  1517. params.u.upd_queue_params.ba_window_size = ba_window_size;
  1518. if (start_seq < IEEE80211_SEQ_MAX) {
  1519. params.u.upd_queue_params.update_ssn = 1;
  1520. params.u.upd_queue_params.ssn = start_seq;
  1521. } else {
  1522. dp_set_ssn_valid_flag(&params, 0);
  1523. }
  1524. if (dp_reo_send_cmd(soc, CMD_UPDATE_RX_REO_QUEUE, &params,
  1525. dp_rx_tid_update_cb, rx_tid)) {
  1526. dp_err_log("failed to send reo cmd CMD_UPDATE_RX_REO_QUEUE");
  1527. DP_STATS_INC(soc, rx.err.reo_cmd_send_fail, 1);
  1528. }
  1529. rx_tid->ba_win_size = ba_window_size;
  1530. if (dp_get_peer_vdev_roaming_in_progress(peer))
  1531. return QDF_STATUS_E_PERM;
  1532. if (soc->cdp_soc.ol_ops->peer_rx_reorder_queue_setup)
  1533. soc->cdp_soc.ol_ops->peer_rx_reorder_queue_setup(
  1534. soc->ctrl_psoc, peer->vdev->pdev->pdev_id,
  1535. peer->vdev->vdev_id, peer->mac_addr.raw,
  1536. rx_tid->hw_qdesc_paddr, tid, tid, 1, ba_window_size);
  1537. return QDF_STATUS_SUCCESS;
  1538. }
  1539. /*
  1540. * dp_reo_desc_free() - Callback free reo descriptor memory after
  1541. * HW cache flush
  1542. *
  1543. * @soc: DP SOC handle
  1544. * @cb_ctxt: Callback context
  1545. * @reo_status: REO command status
  1546. */
  1547. static void dp_reo_desc_free(struct dp_soc *soc, void *cb_ctxt,
  1548. union hal_reo_status *reo_status)
  1549. {
  1550. struct reo_desc_list_node *freedesc =
  1551. (struct reo_desc_list_node *)cb_ctxt;
  1552. struct dp_rx_tid *rx_tid = &freedesc->rx_tid;
  1553. if ((reo_status->fl_cache_status.header.status !=
  1554. HAL_REO_CMD_SUCCESS) &&
  1555. (reo_status->fl_cache_status.header.status !=
  1556. HAL_REO_CMD_DRAIN)) {
  1557. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1558. "%s: Rx tid HW desc flush failed(%d): tid %d",
  1559. __func__,
  1560. reo_status->rx_queue_status.header.status,
  1561. freedesc->rx_tid.tid);
  1562. }
  1563. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1564. "%s: hw_qdesc_paddr: %pK, tid:%d", __func__,
  1565. (void *)(rx_tid->hw_qdesc_paddr), rx_tid->tid);
  1566. qdf_mem_unmap_nbytes_single(soc->osdev,
  1567. rx_tid->hw_qdesc_paddr,
  1568. QDF_DMA_BIDIRECTIONAL,
  1569. rx_tid->hw_qdesc_alloc_size);
  1570. qdf_mem_free(rx_tid->hw_qdesc_vaddr_unaligned);
  1571. qdf_mem_free(freedesc);
  1572. }
  1573. #if defined(QCA_WIFI_QCA8074_VP) && defined(BUILD_X86)
  1574. /* Hawkeye emulation requires bus address to be >= 0x50000000 */
  1575. static inline int dp_reo_desc_addr_chk(qdf_dma_addr_t dma_addr)
  1576. {
  1577. if (dma_addr < 0x50000000)
  1578. return QDF_STATUS_E_FAILURE;
  1579. else
  1580. return QDF_STATUS_SUCCESS;
  1581. }
  1582. #else
  1583. static inline int dp_reo_desc_addr_chk(qdf_dma_addr_t dma_addr)
  1584. {
  1585. return QDF_STATUS_SUCCESS;
  1586. }
  1587. #endif
  1588. /*
  1589. * dp_rx_tid_setup_wifi3() – Setup receive TID state
  1590. * @peer: Datapath peer handle
  1591. * @tid: TID
  1592. * @ba_window_size: BlockAck window size
  1593. * @start_seq: Starting sequence number
  1594. *
  1595. * Return: QDF_STATUS code
  1596. */
  1597. QDF_STATUS dp_rx_tid_setup_wifi3(struct dp_peer *peer, int tid,
  1598. uint32_t ba_window_size, uint32_t start_seq)
  1599. {
  1600. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  1601. struct dp_vdev *vdev = peer->vdev;
  1602. struct dp_soc *soc = vdev->pdev->soc;
  1603. uint32_t hw_qdesc_size;
  1604. uint32_t hw_qdesc_align;
  1605. int hal_pn_type;
  1606. void *hw_qdesc_vaddr;
  1607. uint32_t alloc_tries = 0;
  1608. QDF_STATUS err = QDF_STATUS_SUCCESS;
  1609. if (peer->delete_in_progress ||
  1610. !qdf_atomic_read(&peer->is_default_route_set))
  1611. return QDF_STATUS_E_FAILURE;
  1612. rx_tid->ba_win_size = ba_window_size;
  1613. if (rx_tid->hw_qdesc_vaddr_unaligned)
  1614. return dp_rx_tid_update_wifi3(peer, tid, ba_window_size,
  1615. start_seq);
  1616. rx_tid->delba_tx_status = 0;
  1617. rx_tid->ppdu_id_2k = 0;
  1618. rx_tid->num_of_addba_req = 0;
  1619. rx_tid->num_of_delba_req = 0;
  1620. rx_tid->num_of_addba_resp = 0;
  1621. rx_tid->num_addba_rsp_failed = 0;
  1622. rx_tid->num_addba_rsp_success = 0;
  1623. rx_tid->delba_tx_success_cnt = 0;
  1624. rx_tid->delba_tx_fail_cnt = 0;
  1625. rx_tid->statuscode = 0;
  1626. /* TODO: Allocating HW queue descriptors based on max BA window size
  1627. * for all QOS TIDs so that same descriptor can be used later when
  1628. * ADDBA request is recevied. This should be changed to allocate HW
  1629. * queue descriptors based on BA window size being negotiated (0 for
  1630. * non BA cases), and reallocate when BA window size changes and also
  1631. * send WMI message to FW to change the REO queue descriptor in Rx
  1632. * peer entry as part of dp_rx_tid_update.
  1633. */
  1634. if (tid != DP_NON_QOS_TID)
  1635. hw_qdesc_size = hal_get_reo_qdesc_size(soc->hal_soc,
  1636. HAL_RX_MAX_BA_WINDOW, tid);
  1637. else
  1638. hw_qdesc_size = hal_get_reo_qdesc_size(soc->hal_soc,
  1639. ba_window_size, tid);
  1640. hw_qdesc_align = hal_get_reo_qdesc_align(soc->hal_soc);
  1641. /* To avoid unnecessary extra allocation for alignment, try allocating
  1642. * exact size and see if we already have aligned address.
  1643. */
  1644. rx_tid->hw_qdesc_alloc_size = hw_qdesc_size;
  1645. try_desc_alloc:
  1646. rx_tid->hw_qdesc_vaddr_unaligned =
  1647. qdf_mem_malloc(rx_tid->hw_qdesc_alloc_size);
  1648. if (!rx_tid->hw_qdesc_vaddr_unaligned) {
  1649. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1650. "%s: Rx tid HW desc alloc failed: tid %d",
  1651. __func__, tid);
  1652. return QDF_STATUS_E_NOMEM;
  1653. }
  1654. if ((unsigned long)(rx_tid->hw_qdesc_vaddr_unaligned) %
  1655. hw_qdesc_align) {
  1656. /* Address allocated above is not alinged. Allocate extra
  1657. * memory for alignment
  1658. */
  1659. qdf_mem_free(rx_tid->hw_qdesc_vaddr_unaligned);
  1660. rx_tid->hw_qdesc_vaddr_unaligned =
  1661. qdf_mem_malloc(rx_tid->hw_qdesc_alloc_size +
  1662. hw_qdesc_align - 1);
  1663. if (!rx_tid->hw_qdesc_vaddr_unaligned) {
  1664. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1665. "%s: Rx tid HW desc alloc failed: tid %d",
  1666. __func__, tid);
  1667. return QDF_STATUS_E_NOMEM;
  1668. }
  1669. hw_qdesc_vaddr = (void *)qdf_align((unsigned long)
  1670. rx_tid->hw_qdesc_vaddr_unaligned,
  1671. hw_qdesc_align);
  1672. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1673. "%s: Total Size %d Aligned Addr %pK",
  1674. __func__, rx_tid->hw_qdesc_alloc_size,
  1675. hw_qdesc_vaddr);
  1676. } else {
  1677. hw_qdesc_vaddr = rx_tid->hw_qdesc_vaddr_unaligned;
  1678. }
  1679. /* TODO: Ensure that sec_type is set before ADDBA is received.
  1680. * Currently this is set based on htt indication
  1681. * HTT_T2H_MSG_TYPE_SEC_IND from target
  1682. */
  1683. switch (peer->security[dp_sec_ucast].sec_type) {
  1684. case cdp_sec_type_tkip_nomic:
  1685. case cdp_sec_type_aes_ccmp:
  1686. case cdp_sec_type_aes_ccmp_256:
  1687. case cdp_sec_type_aes_gcmp:
  1688. case cdp_sec_type_aes_gcmp_256:
  1689. hal_pn_type = HAL_PN_WPA;
  1690. break;
  1691. case cdp_sec_type_wapi:
  1692. if (vdev->opmode == wlan_op_mode_ap)
  1693. hal_pn_type = HAL_PN_WAPI_EVEN;
  1694. else
  1695. hal_pn_type = HAL_PN_WAPI_UNEVEN;
  1696. break;
  1697. default:
  1698. hal_pn_type = HAL_PN_NONE;
  1699. break;
  1700. }
  1701. hal_reo_qdesc_setup(soc->hal_soc, tid, ba_window_size, start_seq,
  1702. hw_qdesc_vaddr, rx_tid->hw_qdesc_paddr, hal_pn_type);
  1703. qdf_mem_map_nbytes_single(soc->osdev, hw_qdesc_vaddr,
  1704. QDF_DMA_BIDIRECTIONAL, rx_tid->hw_qdesc_alloc_size,
  1705. &(rx_tid->hw_qdesc_paddr));
  1706. if (dp_reo_desc_addr_chk(rx_tid->hw_qdesc_paddr) !=
  1707. QDF_STATUS_SUCCESS) {
  1708. if (alloc_tries++ < 10) {
  1709. qdf_mem_free(rx_tid->hw_qdesc_vaddr_unaligned);
  1710. rx_tid->hw_qdesc_vaddr_unaligned = NULL;
  1711. goto try_desc_alloc;
  1712. } else {
  1713. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1714. "%s: Rx tid HW desc alloc failed (lowmem): tid %d",
  1715. __func__, tid);
  1716. err = QDF_STATUS_E_NOMEM;
  1717. goto error;
  1718. }
  1719. }
  1720. if (dp_get_peer_vdev_roaming_in_progress(peer)) {
  1721. err = QDF_STATUS_E_PERM;
  1722. goto error;
  1723. }
  1724. if (soc->cdp_soc.ol_ops->peer_rx_reorder_queue_setup) {
  1725. if (soc->cdp_soc.ol_ops->peer_rx_reorder_queue_setup(
  1726. soc->ctrl_psoc,
  1727. peer->vdev->pdev->pdev_id,
  1728. peer->vdev->vdev_id,
  1729. peer->mac_addr.raw, rx_tid->hw_qdesc_paddr, tid, tid,
  1730. 1, ba_window_size)) {
  1731. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1732. "%s: Failed to send reo queue setup to FW - tid %d\n",
  1733. __func__, tid);
  1734. err = QDF_STATUS_E_FAILURE;
  1735. goto error;
  1736. }
  1737. }
  1738. return 0;
  1739. error:
  1740. if (rx_tid->hw_qdesc_vaddr_unaligned) {
  1741. if (dp_reo_desc_addr_chk(rx_tid->hw_qdesc_paddr) ==
  1742. QDF_STATUS_SUCCESS)
  1743. qdf_mem_unmap_nbytes_single(
  1744. soc->osdev,
  1745. rx_tid->hw_qdesc_paddr,
  1746. QDF_DMA_BIDIRECTIONAL,
  1747. rx_tid->hw_qdesc_alloc_size);
  1748. qdf_mem_free(rx_tid->hw_qdesc_vaddr_unaligned);
  1749. rx_tid->hw_qdesc_vaddr_unaligned = NULL;
  1750. }
  1751. return err;
  1752. }
  1753. #ifdef REO_DESC_DEFER_FREE
  1754. /*
  1755. * dp_reo_desc_clean_up() - If cmd to flush base desc fails add
  1756. * desc back to freelist and defer the deletion
  1757. *
  1758. * @soc: DP SOC handle
  1759. * @desc: Base descriptor to be freed
  1760. * @reo_status: REO command status
  1761. */
  1762. static void dp_reo_desc_clean_up(struct dp_soc *soc,
  1763. struct reo_desc_list_node *desc,
  1764. union hal_reo_status *reo_status)
  1765. {
  1766. desc->free_ts = qdf_get_system_timestamp();
  1767. DP_STATS_INC(soc, rx.err.reo_cmd_send_fail, 1);
  1768. qdf_list_insert_back(&soc->reo_desc_freelist,
  1769. (qdf_list_node_t *)desc);
  1770. }
  1771. #else
  1772. /*
  1773. * dp_reo_desc_clean_up() - If send cmd to REO inorder to flush
  1774. * cache fails free the base REO desc anyway
  1775. *
  1776. * @soc: DP SOC handle
  1777. * @desc: Base descriptor to be freed
  1778. * @reo_status: REO command status
  1779. */
  1780. static void dp_reo_desc_clean_up(struct dp_soc *soc,
  1781. struct reo_desc_list_node *desc,
  1782. union hal_reo_status *reo_status)
  1783. {
  1784. if (reo_status) {
  1785. qdf_mem_zero(reo_status, sizeof(*reo_status));
  1786. reo_status->fl_cache_status.header.status = 0;
  1787. dp_reo_desc_free(soc, (void *)desc, reo_status);
  1788. }
  1789. }
  1790. #endif
  1791. /*
  1792. * dp_resend_update_reo_cmd() - Resend the UPDATE_REO_QUEUE
  1793. * cmd and re-insert desc into free list if send fails.
  1794. *
  1795. * @soc: DP SOC handle
  1796. * @desc: desc with resend update cmd flag set
  1797. * @rx_tid: Desc RX tid associated with update cmd for resetting
  1798. * valid field to 0 in h/w
  1799. */
  1800. static void dp_resend_update_reo_cmd(struct dp_soc *soc,
  1801. struct reo_desc_list_node *desc,
  1802. struct dp_rx_tid *rx_tid)
  1803. {
  1804. struct hal_reo_cmd_params params;
  1805. qdf_mem_zero(&params, sizeof(params));
  1806. params.std.need_status = 1;
  1807. params.std.addr_lo =
  1808. rx_tid->hw_qdesc_paddr & 0xffffffff;
  1809. params.std.addr_hi =
  1810. (uint64_t)(rx_tid->hw_qdesc_paddr) >> 32;
  1811. params.u.upd_queue_params.update_vld = 1;
  1812. params.u.upd_queue_params.vld = 0;
  1813. desc->resend_update_reo_cmd = false;
  1814. /*
  1815. * If the cmd send fails then set resend_update_reo_cmd flag
  1816. * and insert the desc at the end of the free list to retry.
  1817. */
  1818. if (dp_reo_send_cmd(soc,
  1819. CMD_UPDATE_RX_REO_QUEUE,
  1820. &params,
  1821. dp_rx_tid_delete_cb,
  1822. (void *)desc)
  1823. != QDF_STATUS_SUCCESS) {
  1824. desc->resend_update_reo_cmd = true;
  1825. desc->free_ts = qdf_get_system_timestamp();
  1826. qdf_list_insert_back(&soc->reo_desc_freelist,
  1827. (qdf_list_node_t *)desc);
  1828. dp_err_log("failed to send reo cmd CMD_UPDATE_RX_REO_QUEUE");
  1829. DP_STATS_INC(soc, rx.err.reo_cmd_send_fail, 1);
  1830. }
  1831. }
  1832. /*
  1833. * dp_rx_tid_delete_cb() - Callback to flush reo descriptor HW cache
  1834. * after deleting the entries (ie., setting valid=0)
  1835. *
  1836. * @soc: DP SOC handle
  1837. * @cb_ctxt: Callback context
  1838. * @reo_status: REO command status
  1839. */
  1840. void dp_rx_tid_delete_cb(struct dp_soc *soc, void *cb_ctxt,
  1841. union hal_reo_status *reo_status)
  1842. {
  1843. struct reo_desc_list_node *freedesc =
  1844. (struct reo_desc_list_node *)cb_ctxt;
  1845. uint32_t list_size;
  1846. struct reo_desc_list_node *desc;
  1847. unsigned long curr_ts = qdf_get_system_timestamp();
  1848. uint32_t desc_size, tot_desc_size;
  1849. struct hal_reo_cmd_params params;
  1850. if (reo_status->rx_queue_status.header.status == HAL_REO_CMD_DRAIN) {
  1851. qdf_mem_zero(reo_status, sizeof(*reo_status));
  1852. reo_status->fl_cache_status.header.status = HAL_REO_CMD_DRAIN;
  1853. dp_reo_desc_free(soc, (void *)freedesc, reo_status);
  1854. return;
  1855. } else if (reo_status->rx_queue_status.header.status !=
  1856. HAL_REO_CMD_SUCCESS) {
  1857. /* Should not happen normally. Just print error for now */
  1858. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1859. "%s: Rx tid HW desc deletion failed(%d): tid %d",
  1860. __func__,
  1861. reo_status->rx_queue_status.header.status,
  1862. freedesc->rx_tid.tid);
  1863. }
  1864. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  1865. "%s: rx_tid: %d status: %d", __func__,
  1866. freedesc->rx_tid.tid,
  1867. reo_status->rx_queue_status.header.status);
  1868. qdf_spin_lock_bh(&soc->reo_desc_freelist_lock);
  1869. freedesc->free_ts = curr_ts;
  1870. qdf_list_insert_back_size(&soc->reo_desc_freelist,
  1871. (qdf_list_node_t *)freedesc, &list_size);
  1872. while ((qdf_list_peek_front(&soc->reo_desc_freelist,
  1873. (qdf_list_node_t **)&desc) == QDF_STATUS_SUCCESS) &&
  1874. ((list_size >= REO_DESC_FREELIST_SIZE) ||
  1875. (curr_ts > (desc->free_ts + REO_DESC_FREE_DEFER_MS)) ||
  1876. (desc->resend_update_reo_cmd && list_size))) {
  1877. struct dp_rx_tid *rx_tid;
  1878. qdf_list_remove_front(&soc->reo_desc_freelist,
  1879. (qdf_list_node_t **)&desc);
  1880. list_size--;
  1881. rx_tid = &desc->rx_tid;
  1882. /* First process descs with resend_update_reo_cmd set */
  1883. if (desc->resend_update_reo_cmd) {
  1884. dp_resend_update_reo_cmd(soc, desc, rx_tid);
  1885. continue;
  1886. }
  1887. /* Flush and invalidate REO descriptor from HW cache: Base and
  1888. * extension descriptors should be flushed separately */
  1889. tot_desc_size = rx_tid->hw_qdesc_alloc_size;
  1890. /* Get base descriptor size by passing non-qos TID */
  1891. desc_size = hal_get_reo_qdesc_size(soc->hal_soc, 0,
  1892. DP_NON_QOS_TID);
  1893. /* Flush reo extension descriptors */
  1894. while ((tot_desc_size -= desc_size) > 0) {
  1895. qdf_mem_zero(&params, sizeof(params));
  1896. params.std.addr_lo =
  1897. ((uint64_t)(rx_tid->hw_qdesc_paddr) +
  1898. tot_desc_size) & 0xffffffff;
  1899. params.std.addr_hi =
  1900. (uint64_t)(rx_tid->hw_qdesc_paddr) >> 32;
  1901. if (QDF_STATUS_SUCCESS != dp_reo_send_cmd(soc,
  1902. CMD_FLUSH_CACHE,
  1903. &params,
  1904. NULL,
  1905. NULL)) {
  1906. dp_err_rl("fail to send CMD_CACHE_FLUSH:"
  1907. "tid %d desc %pK", rx_tid->tid,
  1908. (void *)(rx_tid->hw_qdesc_paddr));
  1909. DP_STATS_INC(soc, rx.err.reo_cmd_send_fail, 1);
  1910. }
  1911. }
  1912. /* Flush base descriptor */
  1913. qdf_mem_zero(&params, sizeof(params));
  1914. params.std.need_status = 1;
  1915. params.std.addr_lo =
  1916. (uint64_t)(rx_tid->hw_qdesc_paddr) & 0xffffffff;
  1917. params.std.addr_hi = (uint64_t)(rx_tid->hw_qdesc_paddr) >> 32;
  1918. if (QDF_STATUS_SUCCESS != dp_reo_send_cmd(soc,
  1919. CMD_FLUSH_CACHE,
  1920. &params,
  1921. dp_reo_desc_free,
  1922. (void *)desc)) {
  1923. union hal_reo_status reo_status;
  1924. /*
  1925. * If dp_reo_send_cmd return failure, related TID queue desc
  1926. * should be unmapped. Also locally reo_desc, together with
  1927. * TID queue desc also need to be freed accordingly.
  1928. *
  1929. * Here invoke desc_free function directly to do clean up.
  1930. *
  1931. * In case of MCL path add the desc back to the free
  1932. * desc list and defer deletion.
  1933. */
  1934. dp_err_log("%s: fail to send REO cmd to flush cache: tid %d",
  1935. __func__, rx_tid->tid);
  1936. dp_reo_desc_clean_up(soc, desc, &reo_status);
  1937. DP_STATS_INC(soc, rx.err.reo_cmd_send_fail, 1);
  1938. }
  1939. }
  1940. qdf_spin_unlock_bh(&soc->reo_desc_freelist_lock);
  1941. }
  1942. /*
  1943. * dp_rx_tid_delete_wifi3() – Delete receive TID queue
  1944. * @peer: Datapath peer handle
  1945. * @tid: TID
  1946. *
  1947. * Return: 0 on success, error code on failure
  1948. */
  1949. static int dp_rx_tid_delete_wifi3(struct dp_peer *peer, int tid)
  1950. {
  1951. struct dp_rx_tid *rx_tid = &(peer->rx_tid[tid]);
  1952. struct dp_soc *soc = peer->vdev->pdev->soc;
  1953. struct hal_reo_cmd_params params;
  1954. struct reo_desc_list_node *freedesc =
  1955. qdf_mem_malloc(sizeof(*freedesc));
  1956. if (!freedesc) {
  1957. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1958. "%s: malloc failed for freedesc: tid %d",
  1959. __func__, tid);
  1960. return -ENOMEM;
  1961. }
  1962. freedesc->rx_tid = *rx_tid;
  1963. freedesc->resend_update_reo_cmd = false;
  1964. qdf_mem_zero(&params, sizeof(params));
  1965. params.std.need_status = 1;
  1966. params.std.addr_lo = rx_tid->hw_qdesc_paddr & 0xffffffff;
  1967. params.std.addr_hi = (uint64_t)(rx_tid->hw_qdesc_paddr) >> 32;
  1968. params.u.upd_queue_params.update_vld = 1;
  1969. params.u.upd_queue_params.vld = 0;
  1970. if (dp_reo_send_cmd(soc, CMD_UPDATE_RX_REO_QUEUE, &params,
  1971. dp_rx_tid_delete_cb, (void *)freedesc)
  1972. != QDF_STATUS_SUCCESS) {
  1973. /* Defer the clean up to the call back context */
  1974. qdf_spin_lock_bh(&soc->reo_desc_freelist_lock);
  1975. freedesc->free_ts = qdf_get_system_timestamp();
  1976. freedesc->resend_update_reo_cmd = true;
  1977. qdf_list_insert_front(&soc->reo_desc_freelist,
  1978. (qdf_list_node_t *)freedesc);
  1979. DP_STATS_INC(soc, rx.err.reo_cmd_send_fail, 1);
  1980. qdf_spin_unlock_bh(&soc->reo_desc_freelist_lock);
  1981. dp_info("Failed to send CMD_UPDATE_RX_REO_QUEUE");
  1982. }
  1983. rx_tid->hw_qdesc_vaddr_unaligned = NULL;
  1984. rx_tid->hw_qdesc_alloc_size = 0;
  1985. rx_tid->hw_qdesc_paddr = 0;
  1986. return 0;
  1987. }
  1988. #ifdef DP_LFR
  1989. static void dp_peer_setup_remaining_tids(struct dp_peer *peer)
  1990. {
  1991. int tid;
  1992. for (tid = 1; tid < DP_MAX_TIDS-1; tid++) {
  1993. dp_rx_tid_setup_wifi3(peer, tid, 1, 0);
  1994. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1995. "Setting up TID %d for peer %pK peer->local_id %d",
  1996. tid, peer, peer->local_id);
  1997. }
  1998. }
  1999. #else
  2000. static void dp_peer_setup_remaining_tids(struct dp_peer *peer) {};
  2001. #endif
  2002. #ifndef WLAN_TX_PKT_CAPTURE_ENH
  2003. /*
  2004. * dp_peer_tid_queue_init() – Initialize ppdu stats queue per TID
  2005. * @peer: Datapath peer
  2006. *
  2007. */
  2008. static inline void dp_peer_tid_queue_init(struct dp_peer *peer)
  2009. {
  2010. }
  2011. /*
  2012. * dp_peer_tid_queue_cleanup() – remove ppdu stats queue per TID
  2013. * @peer: Datapath peer
  2014. *
  2015. */
  2016. static inline void dp_peer_tid_queue_cleanup(struct dp_peer *peer)
  2017. {
  2018. }
  2019. /*
  2020. * dp_peer_update_80211_hdr() – dp peer update 80211 hdr
  2021. * @vdev: Datapath vdev
  2022. * @peer: Datapath peer
  2023. *
  2024. */
  2025. static inline void
  2026. dp_peer_update_80211_hdr(struct dp_vdev *vdev, struct dp_peer *peer)
  2027. {
  2028. }
  2029. #endif
  2030. /*
  2031. * dp_peer_tx_init() – Initialize receive TID state
  2032. * @pdev: Datapath pdev
  2033. * @peer: Datapath peer
  2034. *
  2035. */
  2036. void dp_peer_tx_init(struct dp_pdev *pdev, struct dp_peer *peer)
  2037. {
  2038. dp_peer_tid_queue_init(peer);
  2039. dp_peer_update_80211_hdr(peer->vdev, peer);
  2040. }
  2041. /*
  2042. * dp_peer_tx_cleanup() – Deinitialize receive TID state
  2043. * @vdev: Datapath vdev
  2044. * @peer: Datapath peer
  2045. *
  2046. */
  2047. static inline void
  2048. dp_peer_tx_cleanup(struct dp_vdev *vdev, struct dp_peer *peer)
  2049. {
  2050. dp_peer_tid_queue_cleanup(peer);
  2051. }
  2052. /*
  2053. * dp_peer_rx_init() – Initialize receive TID state
  2054. * @pdev: Datapath pdev
  2055. * @peer: Datapath peer
  2056. *
  2057. */
  2058. void dp_peer_rx_init(struct dp_pdev *pdev, struct dp_peer *peer)
  2059. {
  2060. int tid;
  2061. struct dp_rx_tid *rx_tid;
  2062. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  2063. rx_tid = &peer->rx_tid[tid];
  2064. rx_tid->array = &rx_tid->base;
  2065. rx_tid->base.head = rx_tid->base.tail = NULL;
  2066. rx_tid->tid = tid;
  2067. rx_tid->defrag_timeout_ms = 0;
  2068. rx_tid->ba_win_size = 0;
  2069. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  2070. rx_tid->defrag_waitlist_elem.tqe_next = NULL;
  2071. rx_tid->defrag_waitlist_elem.tqe_prev = NULL;
  2072. }
  2073. peer->active_ba_session_cnt = 0;
  2074. peer->hw_buffer_size = 0;
  2075. peer->kill_256_sessions = 0;
  2076. /* Setup default (non-qos) rx tid queue */
  2077. dp_rx_tid_setup_wifi3(peer, DP_NON_QOS_TID, 1, 0);
  2078. /* Setup rx tid queue for TID 0.
  2079. * Other queues will be setup on receiving first packet, which will cause
  2080. * NULL REO queue error
  2081. */
  2082. dp_rx_tid_setup_wifi3(peer, 0, 1, 0);
  2083. /*
  2084. * Setup the rest of TID's to handle LFR
  2085. */
  2086. dp_peer_setup_remaining_tids(peer);
  2087. /*
  2088. * Set security defaults: no PN check, no security. The target may
  2089. * send a HTT SEC_IND message to overwrite these defaults.
  2090. */
  2091. peer->security[dp_sec_ucast].sec_type =
  2092. peer->security[dp_sec_mcast].sec_type = cdp_sec_type_none;
  2093. }
  2094. /*
  2095. * dp_peer_rx_cleanup() – Cleanup receive TID state
  2096. * @vdev: Datapath vdev
  2097. * @peer: Datapath peer
  2098. * @reuse: Peer reference reuse
  2099. *
  2100. */
  2101. void dp_peer_rx_cleanup(struct dp_vdev *vdev, struct dp_peer *peer, bool reuse)
  2102. {
  2103. int tid;
  2104. uint32_t tid_delete_mask = 0;
  2105. dp_info("Remove tids for peer: %pK", peer);
  2106. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  2107. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  2108. qdf_spin_lock_bh(&rx_tid->tid_lock);
  2109. if (!peer->bss_peer || peer->vdev->opmode == wlan_op_mode_sta) {
  2110. /* Cleanup defrag related resource */
  2111. dp_rx_defrag_waitlist_remove(peer, tid);
  2112. dp_rx_reorder_flush_frag(peer, tid);
  2113. }
  2114. if (peer->rx_tid[tid].hw_qdesc_vaddr_unaligned) {
  2115. dp_rx_tid_delete_wifi3(peer, tid);
  2116. tid_delete_mask |= (1 << tid);
  2117. }
  2118. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2119. }
  2120. #ifdef notyet /* See if FW can remove queues as part of peer cleanup */
  2121. if (soc->ol_ops->peer_rx_reorder_queue_remove) {
  2122. soc->ol_ops->peer_rx_reorder_queue_remove(soc->ctrl_psoc,
  2123. peer->vdev->pdev->pdev_id,
  2124. peer->vdev->vdev_id, peer->mac_addr.raw,
  2125. tid_delete_mask);
  2126. }
  2127. #endif
  2128. if (!reuse)
  2129. for (tid = 0; tid < DP_MAX_TIDS; tid++)
  2130. qdf_spinlock_destroy(&peer->rx_tid[tid].tid_lock);
  2131. }
  2132. #ifdef FEATURE_PERPKT_INFO
  2133. /*
  2134. * dp_peer_ppdu_delayed_ba_init() Initialize ppdu in peer
  2135. * @peer: Datapath peer
  2136. *
  2137. * return: void
  2138. */
  2139. void dp_peer_ppdu_delayed_ba_init(struct dp_peer *peer)
  2140. {
  2141. qdf_mem_zero(&peer->delayed_ba_ppdu_stats,
  2142. sizeof(struct cdp_delayed_tx_completion_ppdu_user));
  2143. peer->last_delayed_ba = false;
  2144. peer->last_delayed_ba_ppduid = 0;
  2145. }
  2146. #else
  2147. /*
  2148. * dp_peer_ppdu_delayed_ba_init() Initialize ppdu in peer
  2149. * @peer: Datapath peer
  2150. *
  2151. * return: void
  2152. */
  2153. void dp_peer_ppdu_delayed_ba_init(struct dp_peer *peer)
  2154. {
  2155. }
  2156. #endif
  2157. /*
  2158. * dp_peer_cleanup() – Cleanup peer information
  2159. * @vdev: Datapath vdev
  2160. * @peer: Datapath peer
  2161. * @reuse: Peer reference reuse
  2162. *
  2163. */
  2164. void dp_peer_cleanup(struct dp_vdev *vdev, struct dp_peer *peer, bool reuse)
  2165. {
  2166. dp_peer_tx_cleanup(vdev, peer);
  2167. /* cleanup the Rx reorder queues for this peer */
  2168. dp_peer_rx_cleanup(vdev, peer, reuse);
  2169. }
  2170. /* dp_teardown_256_ba_session() - Teardown sessions using 256
  2171. * window size when a request with
  2172. * 64 window size is received.
  2173. * This is done as a WAR since HW can
  2174. * have only one setting per peer (64 or 256).
  2175. * For HKv2, we use per tid buffersize setting
  2176. * for 0 to per_tid_basize_max_tid. For tid
  2177. * more than per_tid_basize_max_tid we use HKv1
  2178. * method.
  2179. * @peer: Datapath peer
  2180. *
  2181. * Return: void
  2182. */
  2183. static void dp_teardown_256_ba_sessions(struct dp_peer *peer)
  2184. {
  2185. uint8_t delba_rcode = 0;
  2186. int tid;
  2187. struct dp_rx_tid *rx_tid = NULL;
  2188. tid = peer->vdev->pdev->soc->per_tid_basize_max_tid;
  2189. for (; tid < DP_MAX_TIDS; tid++) {
  2190. rx_tid = &peer->rx_tid[tid];
  2191. qdf_spin_lock_bh(&rx_tid->tid_lock);
  2192. if (rx_tid->ba_win_size <= 64) {
  2193. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2194. continue;
  2195. } else {
  2196. if (rx_tid->ba_status == DP_RX_BA_ACTIVE ||
  2197. rx_tid->ba_status == DP_RX_BA_IN_PROGRESS) {
  2198. /* send delba */
  2199. if (!rx_tid->delba_tx_status) {
  2200. rx_tid->delba_tx_retry++;
  2201. rx_tid->delba_tx_status = 1;
  2202. rx_tid->delba_rcode =
  2203. IEEE80211_REASON_QOS_SETUP_REQUIRED;
  2204. delba_rcode = rx_tid->delba_rcode;
  2205. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2206. if (peer->vdev->pdev->soc->cdp_soc.ol_ops->send_delba)
  2207. peer->vdev->pdev->soc->cdp_soc.ol_ops->send_delba(
  2208. peer->vdev->pdev->soc->ctrl_psoc,
  2209. peer->vdev->vdev_id,
  2210. peer->mac_addr.raw,
  2211. tid, delba_rcode);
  2212. } else {
  2213. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2214. }
  2215. } else {
  2216. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2217. }
  2218. }
  2219. }
  2220. }
  2221. /*
  2222. * dp_rx_addba_resp_tx_completion_wifi3() – Update Rx Tid State
  2223. *
  2224. * @soc: Datapath soc handle
  2225. * @peer_mac: Datapath peer mac address
  2226. * @vdev_id: id of atapath vdev
  2227. * @tid: TID number
  2228. * @status: tx completion status
  2229. * Return: 0 on success, error code on failure
  2230. */
  2231. int dp_addba_resp_tx_completion_wifi3(struct cdp_soc_t *cdp_soc,
  2232. uint8_t *peer_mac,
  2233. uint16_t vdev_id,
  2234. uint8_t tid, int status)
  2235. {
  2236. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)cdp_soc,
  2237. peer_mac, 0, vdev_id);
  2238. struct dp_rx_tid *rx_tid = NULL;
  2239. if (!peer || peer->delete_in_progress) {
  2240. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2241. "%s: Peer is NULL!\n", __func__);
  2242. goto fail;
  2243. }
  2244. rx_tid = &peer->rx_tid[tid];
  2245. qdf_spin_lock_bh(&rx_tid->tid_lock);
  2246. if (status) {
  2247. rx_tid->num_addba_rsp_failed++;
  2248. dp_rx_tid_update_wifi3(peer, tid, 1,
  2249. IEEE80211_SEQ_MAX);
  2250. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  2251. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2252. dp_err("RxTid- %d addba rsp tx completion failed", tid);
  2253. goto success;
  2254. }
  2255. rx_tid->num_addba_rsp_success++;
  2256. if (rx_tid->ba_status == DP_RX_BA_INACTIVE) {
  2257. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2258. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2259. "%s: Rx Tid- %d hw qdesc is not in IN_PROGRESS",
  2260. __func__, tid);
  2261. goto fail;
  2262. }
  2263. if (!qdf_atomic_read(&peer->is_default_route_set)) {
  2264. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2265. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2266. "%s: default route is not set for peer: %pM",
  2267. __func__, peer->mac_addr.raw);
  2268. goto fail;
  2269. }
  2270. /* First Session */
  2271. if (peer->active_ba_session_cnt == 0) {
  2272. if (rx_tid->ba_win_size > 64 && rx_tid->ba_win_size <= 256)
  2273. peer->hw_buffer_size = 256;
  2274. else
  2275. peer->hw_buffer_size = 64;
  2276. }
  2277. rx_tid->ba_status = DP_RX_BA_ACTIVE;
  2278. peer->active_ba_session_cnt++;
  2279. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2280. /* Kill any session having 256 buffer size
  2281. * when 64 buffer size request is received.
  2282. * Also, latch on to 64 as new buffer size.
  2283. */
  2284. if (peer->kill_256_sessions) {
  2285. dp_teardown_256_ba_sessions(peer);
  2286. peer->kill_256_sessions = 0;
  2287. }
  2288. success:
  2289. dp_peer_unref_delete(peer);
  2290. return QDF_STATUS_SUCCESS;
  2291. fail:
  2292. if (peer)
  2293. dp_peer_unref_delete(peer);
  2294. return QDF_STATUS_E_FAILURE;
  2295. }
  2296. /*
  2297. * dp_rx_addba_responsesetup_wifi3() – Process ADDBA request from peer
  2298. *
  2299. * @soc: Datapath soc handle
  2300. * @peer_mac: Datapath peer mac address
  2301. * @vdev_id: id of atapath vdev
  2302. * @tid: TID number
  2303. * @dialogtoken: output dialogtoken
  2304. * @statuscode: output dialogtoken
  2305. * @buffersize: Output BA window size
  2306. * @batimeout: Output BA timeout
  2307. */
  2308. QDF_STATUS
  2309. dp_addba_responsesetup_wifi3(struct cdp_soc_t *cdp_soc, uint8_t *peer_mac,
  2310. uint16_t vdev_id, uint8_t tid,
  2311. uint8_t *dialogtoken, uint16_t *statuscode,
  2312. uint16_t *buffersize, uint16_t *batimeout)
  2313. {
  2314. struct dp_rx_tid *rx_tid = NULL;
  2315. QDF_STATUS status = QDF_STATUS_SUCCESS;
  2316. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)cdp_soc,
  2317. peer_mac, 0, vdev_id);
  2318. if (!peer || peer->delete_in_progress) {
  2319. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2320. "%s: Peer is NULL!\n", __func__);
  2321. status = QDF_STATUS_E_FAILURE;
  2322. goto fail;
  2323. }
  2324. rx_tid = &peer->rx_tid[tid];
  2325. qdf_spin_lock_bh(&rx_tid->tid_lock);
  2326. rx_tid->num_of_addba_resp++;
  2327. /* setup ADDBA response parameters */
  2328. *dialogtoken = rx_tid->dialogtoken;
  2329. *statuscode = rx_tid->statuscode;
  2330. *buffersize = rx_tid->ba_win_size;
  2331. *batimeout = 0;
  2332. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2333. fail:
  2334. if (peer)
  2335. dp_peer_unref_delete(peer);
  2336. return status;
  2337. }
  2338. /* dp_check_ba_buffersize() - Check buffer size in request
  2339. * and latch onto this size based on
  2340. * size used in first active session.
  2341. * @peer: Datapath peer
  2342. * @tid: Tid
  2343. * @buffersize: Block ack window size
  2344. *
  2345. * Return: void
  2346. */
  2347. static void dp_check_ba_buffersize(struct dp_peer *peer,
  2348. uint16_t tid,
  2349. uint16_t buffersize)
  2350. {
  2351. struct dp_rx_tid *rx_tid = NULL;
  2352. rx_tid = &peer->rx_tid[tid];
  2353. if (peer->vdev->pdev->soc->per_tid_basize_max_tid &&
  2354. tid < peer->vdev->pdev->soc->per_tid_basize_max_tid) {
  2355. rx_tid->ba_win_size = buffersize;
  2356. return;
  2357. } else {
  2358. if (peer->active_ba_session_cnt == 0) {
  2359. rx_tid->ba_win_size = buffersize;
  2360. } else {
  2361. if (peer->hw_buffer_size == 64) {
  2362. if (buffersize <= 64)
  2363. rx_tid->ba_win_size = buffersize;
  2364. else
  2365. rx_tid->ba_win_size = peer->hw_buffer_size;
  2366. } else if (peer->hw_buffer_size == 256) {
  2367. if (buffersize > 64) {
  2368. rx_tid->ba_win_size = buffersize;
  2369. } else {
  2370. rx_tid->ba_win_size = buffersize;
  2371. peer->hw_buffer_size = 64;
  2372. peer->kill_256_sessions = 1;
  2373. }
  2374. }
  2375. }
  2376. }
  2377. }
  2378. /*
  2379. * dp_addba_requestprocess_wifi3() - Process ADDBA request from peer
  2380. *
  2381. * @soc: Datapath soc handle
  2382. * @peer_mac: Datapath peer mac address
  2383. * @vdev_id: id of atapath vdev
  2384. * @dialogtoken: dialogtoken from ADDBA frame
  2385. * @tid: TID number
  2386. * @batimeout: BA timeout
  2387. * @buffersize: BA window size
  2388. * @startseqnum: Start seq. number received in BA sequence control
  2389. *
  2390. * Return: 0 on success, error code on failure
  2391. */
  2392. int dp_addba_requestprocess_wifi3(struct cdp_soc_t *cdp_soc,
  2393. uint8_t *peer_mac,
  2394. uint16_t vdev_id,
  2395. uint8_t dialogtoken,
  2396. uint16_t tid, uint16_t batimeout,
  2397. uint16_t buffersize,
  2398. uint16_t startseqnum)
  2399. {
  2400. QDF_STATUS status = QDF_STATUS_SUCCESS;
  2401. struct dp_rx_tid *rx_tid = NULL;
  2402. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)cdp_soc,
  2403. peer_mac, 0, vdev_id);
  2404. if (!peer || peer->delete_in_progress) {
  2405. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2406. "%s: Peer is NULL!\n", __func__);
  2407. status = QDF_STATUS_E_FAILURE;
  2408. goto fail;
  2409. }
  2410. rx_tid = &peer->rx_tid[tid];
  2411. qdf_spin_lock_bh(&rx_tid->tid_lock);
  2412. rx_tid->num_of_addba_req++;
  2413. if ((rx_tid->ba_status == DP_RX_BA_ACTIVE &&
  2414. rx_tid->hw_qdesc_vaddr_unaligned)) {
  2415. dp_rx_tid_update_wifi3(peer, tid, 1, IEEE80211_SEQ_MAX);
  2416. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  2417. peer->active_ba_session_cnt--;
  2418. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2419. "%s: Rx Tid- %d hw qdesc is already setup",
  2420. __func__, tid);
  2421. }
  2422. if (rx_tid->ba_status == DP_RX_BA_IN_PROGRESS) {
  2423. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2424. status = QDF_STATUS_E_FAILURE;
  2425. goto fail;
  2426. }
  2427. dp_check_ba_buffersize(peer, tid, buffersize);
  2428. if (dp_rx_tid_setup_wifi3(peer, tid,
  2429. rx_tid->ba_win_size, startseqnum)) {
  2430. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  2431. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2432. status = QDF_STATUS_E_FAILURE;
  2433. goto fail;
  2434. }
  2435. rx_tid->ba_status = DP_RX_BA_IN_PROGRESS;
  2436. rx_tid->dialogtoken = dialogtoken;
  2437. rx_tid->startseqnum = startseqnum;
  2438. if (rx_tid->userstatuscode != IEEE80211_STATUS_SUCCESS)
  2439. rx_tid->statuscode = rx_tid->userstatuscode;
  2440. else
  2441. rx_tid->statuscode = IEEE80211_STATUS_SUCCESS;
  2442. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2443. fail:
  2444. if (peer)
  2445. dp_peer_unref_delete(peer);
  2446. return status;
  2447. }
  2448. /*
  2449. * dp_set_addba_response() – Set a user defined ADDBA response status code
  2450. *
  2451. * @soc: Datapath soc handle
  2452. * @peer_mac: Datapath peer mac address
  2453. * @vdev_id: id of atapath vdev
  2454. * @tid: TID number
  2455. * @statuscode: response status code to be set
  2456. */
  2457. QDF_STATUS
  2458. dp_set_addba_response(struct cdp_soc_t *cdp_soc, uint8_t *peer_mac,
  2459. uint16_t vdev_id, uint8_t tid, uint16_t statuscode)
  2460. {
  2461. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)cdp_soc,
  2462. peer_mac, 0, vdev_id);
  2463. struct dp_rx_tid *rx_tid;
  2464. QDF_STATUS status = QDF_STATUS_SUCCESS;
  2465. if (!peer || peer->delete_in_progress) {
  2466. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2467. "%s: Peer is NULL!\n", __func__);
  2468. status = QDF_STATUS_E_FAILURE;
  2469. goto fail;
  2470. }
  2471. rx_tid = &peer->rx_tid[tid];
  2472. qdf_spin_lock_bh(&rx_tid->tid_lock);
  2473. rx_tid->userstatuscode = statuscode;
  2474. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2475. fail:
  2476. if (peer)
  2477. dp_peer_unref_delete(peer);
  2478. return status;
  2479. }
  2480. /*
  2481. * dp_rx_delba_process_wifi3() – Process DELBA from peer
  2482. * @soc: Datapath soc handle
  2483. * @peer_mac: Datapath peer mac address
  2484. * @vdev_id: id of atapath vdev
  2485. * @tid: TID number
  2486. * @reasoncode: Reason code received in DELBA frame
  2487. *
  2488. * Return: 0 on success, error code on failure
  2489. */
  2490. int dp_delba_process_wifi3(struct cdp_soc_t *cdp_soc, uint8_t *peer_mac,
  2491. uint16_t vdev_id, int tid, uint16_t reasoncode)
  2492. {
  2493. QDF_STATUS status = QDF_STATUS_SUCCESS;
  2494. struct dp_rx_tid *rx_tid;
  2495. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)cdp_soc,
  2496. peer_mac, 0, vdev_id);
  2497. if (!peer || peer->delete_in_progress) {
  2498. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2499. "%s: Peer is NULL!\n", __func__);
  2500. status = QDF_STATUS_E_FAILURE;
  2501. goto fail;
  2502. }
  2503. rx_tid = &peer->rx_tid[tid];
  2504. qdf_spin_lock_bh(&rx_tid->tid_lock);
  2505. if (rx_tid->ba_status == DP_RX_BA_INACTIVE ||
  2506. rx_tid->ba_status == DP_RX_BA_IN_PROGRESS) {
  2507. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2508. status = QDF_STATUS_E_FAILURE;
  2509. goto fail;
  2510. }
  2511. /* TODO: See if we can delete the existing REO queue descriptor and
  2512. * replace with a new one without queue extenstion descript to save
  2513. * memory
  2514. */
  2515. rx_tid->delba_rcode = reasoncode;
  2516. rx_tid->num_of_delba_req++;
  2517. dp_rx_tid_update_wifi3(peer, tid, 1, IEEE80211_SEQ_MAX);
  2518. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  2519. peer->active_ba_session_cnt--;
  2520. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2521. fail:
  2522. if (peer)
  2523. dp_peer_unref_delete(peer);
  2524. return status;
  2525. }
  2526. /*
  2527. * dp_rx_delba_tx_completion_wifi3() – Send Delba Request
  2528. *
  2529. * @soc: Datapath soc handle
  2530. * @peer_mac: Datapath peer mac address
  2531. * @vdev_id: id of atapath vdev
  2532. * @tid: TID number
  2533. * @status: tx completion status
  2534. * Return: 0 on success, error code on failure
  2535. */
  2536. int dp_delba_tx_completion_wifi3(struct cdp_soc_t *cdp_soc, uint8_t *peer_mac,
  2537. uint16_t vdev_id,
  2538. uint8_t tid, int status)
  2539. {
  2540. QDF_STATUS ret = QDF_STATUS_SUCCESS;
  2541. struct dp_rx_tid *rx_tid = NULL;
  2542. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)cdp_soc,
  2543. peer_mac, 0, vdev_id);
  2544. if (!peer || peer->delete_in_progress) {
  2545. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2546. "%s: Peer is NULL!", __func__);
  2547. ret = QDF_STATUS_E_FAILURE;
  2548. goto end;
  2549. }
  2550. rx_tid = &peer->rx_tid[tid];
  2551. qdf_spin_lock_bh(&rx_tid->tid_lock);
  2552. if (status) {
  2553. rx_tid->delba_tx_fail_cnt++;
  2554. if (rx_tid->delba_tx_retry >= DP_MAX_DELBA_RETRY) {
  2555. rx_tid->delba_tx_retry = 0;
  2556. rx_tid->delba_tx_status = 0;
  2557. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2558. } else {
  2559. rx_tid->delba_tx_retry++;
  2560. rx_tid->delba_tx_status = 1;
  2561. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2562. if (peer->vdev->pdev->soc->cdp_soc.ol_ops->send_delba)
  2563. peer->vdev->pdev->soc->cdp_soc.ol_ops->send_delba(
  2564. peer->vdev->pdev->soc->ctrl_psoc,
  2565. peer->vdev->vdev_id,
  2566. peer->mac_addr.raw, tid,
  2567. rx_tid->delba_rcode);
  2568. }
  2569. goto end;
  2570. } else {
  2571. rx_tid->delba_tx_success_cnt++;
  2572. rx_tid->delba_tx_retry = 0;
  2573. rx_tid->delba_tx_status = 0;
  2574. }
  2575. if (rx_tid->ba_status == DP_RX_BA_ACTIVE) {
  2576. dp_rx_tid_update_wifi3(peer, tid, 1, IEEE80211_SEQ_MAX);
  2577. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  2578. peer->active_ba_session_cnt--;
  2579. }
  2580. if (rx_tid->ba_status == DP_RX_BA_IN_PROGRESS) {
  2581. dp_rx_tid_update_wifi3(peer, tid, 1, IEEE80211_SEQ_MAX);
  2582. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  2583. }
  2584. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2585. end:
  2586. if (peer)
  2587. dp_peer_unref_delete(peer);
  2588. return ret;
  2589. }
  2590. /**
  2591. * dp_set_pn_check_wifi3() - enable PN check in REO for security
  2592. * @soc: Datapath soc handle
  2593. * @peer_mac: Datapath peer mac address
  2594. * @vdev_id: id of atapath vdev
  2595. * @vdev: Datapath vdev
  2596. * @pdev - data path device instance
  2597. * @sec_type - security type
  2598. * @rx_pn - Receive pn starting number
  2599. *
  2600. */
  2601. QDF_STATUS
  2602. dp_set_pn_check_wifi3(struct cdp_soc_t *soc, uint8_t vdev_id,
  2603. uint8_t *peer_mac, enum cdp_sec_type sec_type,
  2604. uint32_t *rx_pn)
  2605. {
  2606. struct dp_pdev *pdev;
  2607. int i;
  2608. uint8_t pn_size;
  2609. struct hal_reo_cmd_params params;
  2610. QDF_STATUS status = QDF_STATUS_SUCCESS;
  2611. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  2612. peer_mac, 0, vdev_id);
  2613. struct dp_vdev *vdev =
  2614. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  2615. vdev_id);
  2616. if (!vdev || !peer || peer->delete_in_progress) {
  2617. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2618. "%s: Peer is NULL!\n", __func__);
  2619. status = QDF_STATUS_E_FAILURE;
  2620. goto fail;
  2621. }
  2622. pdev = vdev->pdev;
  2623. qdf_mem_zero(&params, sizeof(params));
  2624. params.std.need_status = 1;
  2625. params.u.upd_queue_params.update_pn_valid = 1;
  2626. params.u.upd_queue_params.update_pn_size = 1;
  2627. params.u.upd_queue_params.update_pn = 1;
  2628. params.u.upd_queue_params.update_pn_check_needed = 1;
  2629. params.u.upd_queue_params.update_svld = 1;
  2630. params.u.upd_queue_params.svld = 0;
  2631. peer->security[dp_sec_ucast].sec_type = sec_type;
  2632. switch (sec_type) {
  2633. case cdp_sec_type_tkip_nomic:
  2634. case cdp_sec_type_aes_ccmp:
  2635. case cdp_sec_type_aes_ccmp_256:
  2636. case cdp_sec_type_aes_gcmp:
  2637. case cdp_sec_type_aes_gcmp_256:
  2638. params.u.upd_queue_params.pn_check_needed = 1;
  2639. params.u.upd_queue_params.pn_size = 48;
  2640. pn_size = 48;
  2641. break;
  2642. case cdp_sec_type_wapi:
  2643. params.u.upd_queue_params.pn_check_needed = 1;
  2644. params.u.upd_queue_params.pn_size = 128;
  2645. pn_size = 128;
  2646. if (vdev->opmode == wlan_op_mode_ap) {
  2647. params.u.upd_queue_params.pn_even = 1;
  2648. params.u.upd_queue_params.update_pn_even = 1;
  2649. } else {
  2650. params.u.upd_queue_params.pn_uneven = 1;
  2651. params.u.upd_queue_params.update_pn_uneven = 1;
  2652. }
  2653. break;
  2654. default:
  2655. params.u.upd_queue_params.pn_check_needed = 0;
  2656. pn_size = 0;
  2657. break;
  2658. }
  2659. for (i = 0; i < DP_MAX_TIDS; i++) {
  2660. struct dp_rx_tid *rx_tid = &peer->rx_tid[i];
  2661. qdf_spin_lock_bh(&rx_tid->tid_lock);
  2662. if (rx_tid->hw_qdesc_vaddr_unaligned) {
  2663. params.std.addr_lo =
  2664. rx_tid->hw_qdesc_paddr & 0xffffffff;
  2665. params.std.addr_hi =
  2666. (uint64_t)(rx_tid->hw_qdesc_paddr) >> 32;
  2667. if (pn_size) {
  2668. QDF_TRACE(QDF_MODULE_ID_DP,
  2669. QDF_TRACE_LEVEL_INFO_HIGH,
  2670. "%s PN set for TID:%d pn:%x:%x:%x:%x",
  2671. __func__, i, rx_pn[3], rx_pn[2],
  2672. rx_pn[1], rx_pn[0]);
  2673. params.u.upd_queue_params.update_pn_valid = 1;
  2674. params.u.upd_queue_params.pn_31_0 = rx_pn[0];
  2675. params.u.upd_queue_params.pn_63_32 = rx_pn[1];
  2676. params.u.upd_queue_params.pn_95_64 = rx_pn[2];
  2677. params.u.upd_queue_params.pn_127_96 = rx_pn[3];
  2678. }
  2679. rx_tid->pn_size = pn_size;
  2680. if (dp_reo_send_cmd(cdp_soc_t_to_dp_soc(soc),
  2681. CMD_UPDATE_RX_REO_QUEUE,
  2682. &params, dp_rx_tid_update_cb,
  2683. rx_tid)) {
  2684. dp_err_log("fail to send CMD_UPDATE_RX_REO_QUEUE"
  2685. "tid %d desc %pK", rx_tid->tid,
  2686. (void *)(rx_tid->hw_qdesc_paddr));
  2687. DP_STATS_INC(cdp_soc_t_to_dp_soc(soc),
  2688. rx.err.reo_cmd_send_fail, 1);
  2689. }
  2690. } else {
  2691. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  2692. "PN Check not setup for TID :%d ", i);
  2693. }
  2694. qdf_spin_unlock_bh(&rx_tid->tid_lock);
  2695. }
  2696. fail:
  2697. if (peer)
  2698. dp_peer_unref_delete(peer);
  2699. return status;
  2700. }
  2701. void
  2702. dp_rx_sec_ind_handler(struct dp_soc *soc, uint16_t peer_id,
  2703. enum cdp_sec_type sec_type, int is_unicast,
  2704. u_int32_t *michael_key,
  2705. u_int32_t *rx_pn)
  2706. {
  2707. struct dp_peer *peer;
  2708. int sec_index;
  2709. peer = dp_peer_find_by_id(soc, peer_id);
  2710. if (!peer) {
  2711. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2712. "Couldn't find peer from ID %d - skipping security inits",
  2713. peer_id);
  2714. return;
  2715. }
  2716. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  2717. "sec spec for peer %pK (%02x:%02x:%02x:%02x:%02x:%02x): %s key of type %d",
  2718. peer,
  2719. peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  2720. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  2721. peer->mac_addr.raw[4], peer->mac_addr.raw[5],
  2722. is_unicast ? "ucast" : "mcast",
  2723. sec_type);
  2724. sec_index = is_unicast ? dp_sec_ucast : dp_sec_mcast;
  2725. peer->security[sec_index].sec_type = sec_type;
  2726. #ifdef notyet /* TODO: See if this is required for defrag support */
  2727. /* michael key only valid for TKIP, but for simplicity,
  2728. * copy it anyway
  2729. */
  2730. qdf_mem_copy(
  2731. &peer->security[sec_index].michael_key[0],
  2732. michael_key,
  2733. sizeof(peer->security[sec_index].michael_key));
  2734. #ifdef BIG_ENDIAN_HOST
  2735. OL_IF_SWAPBO(peer->security[sec_index].michael_key[0],
  2736. sizeof(peer->security[sec_index].michael_key));
  2737. #endif /* BIG_ENDIAN_HOST */
  2738. #endif
  2739. #ifdef notyet /* TODO: Check if this is required for wifi3.0 */
  2740. if (sec_type != cdp_sec_type_wapi) {
  2741. qdf_mem_zero(peer->tids_last_pn_valid, _EXT_TIDS);
  2742. } else {
  2743. for (i = 0; i < DP_MAX_TIDS; i++) {
  2744. /*
  2745. * Setting PN valid bit for WAPI sec_type,
  2746. * since WAPI PN has to be started with predefined value
  2747. */
  2748. peer->tids_last_pn_valid[i] = 1;
  2749. qdf_mem_copy(
  2750. (u_int8_t *) &peer->tids_last_pn[i],
  2751. (u_int8_t *) rx_pn, sizeof(union htt_rx_pn_t));
  2752. peer->tids_last_pn[i].pn128[1] =
  2753. qdf_cpu_to_le64(peer->tids_last_pn[i].pn128[1]);
  2754. peer->tids_last_pn[i].pn128[0] =
  2755. qdf_cpu_to_le64(peer->tids_last_pn[i].pn128[0]);
  2756. }
  2757. }
  2758. #endif
  2759. /* TODO: Update HW TID queue with PN check parameters (pn type for
  2760. * all security types and last pn for WAPI) once REO command API
  2761. * is available
  2762. */
  2763. dp_peer_unref_del_find_by_id(peer);
  2764. }
  2765. #ifdef DP_PEER_EXTENDED_API
  2766. /**
  2767. * dp_register_peer() - Register peer into physical device
  2768. * @pdev - data path device instance
  2769. * @sta_desc - peer description
  2770. *
  2771. * Register peer into physical device
  2772. *
  2773. * Return: QDF_STATUS_SUCCESS registration success
  2774. * QDF_STATUS_E_FAULT peer not found
  2775. */
  2776. QDF_STATUS dp_register_peer(struct cdp_pdev *pdev_handle,
  2777. struct ol_txrx_desc_type *sta_desc)
  2778. {
  2779. struct dp_peer *peer;
  2780. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  2781. peer = dp_find_peer_by_addr((struct cdp_pdev *)pdev,
  2782. sta_desc->peer_addr.bytes);
  2783. if (!peer)
  2784. return QDF_STATUS_E_FAULT;
  2785. qdf_spin_lock_bh(&peer->peer_info_lock);
  2786. peer->state = OL_TXRX_PEER_STATE_CONN;
  2787. qdf_spin_unlock_bh(&peer->peer_info_lock);
  2788. dp_rx_flush_rx_cached(peer, false);
  2789. return QDF_STATUS_SUCCESS;
  2790. }
  2791. /**
  2792. * dp_clear_peer() - remove peer from physical device
  2793. * @pdev - data path device instance
  2794. * @peer_addr - peer mac address
  2795. *
  2796. * remove peer from physical device
  2797. *
  2798. * Return: QDF_STATUS_SUCCESS registration success
  2799. * QDF_STATUS_E_FAULT peer not found
  2800. */
  2801. QDF_STATUS
  2802. dp_clear_peer(struct cdp_pdev *pdev_handle, struct qdf_mac_addr peer_addr)
  2803. {
  2804. struct dp_peer *peer;
  2805. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  2806. peer = dp_find_peer_by_addr((struct cdp_pdev *)pdev, peer_addr.bytes);
  2807. if (!peer)
  2808. return QDF_STATUS_E_FAULT;
  2809. qdf_spin_lock_bh(&peer->peer_info_lock);
  2810. peer->state = OL_TXRX_PEER_STATE_DISC;
  2811. qdf_spin_unlock_bh(&peer->peer_info_lock);
  2812. dp_rx_flush_rx_cached(peer, true);
  2813. return QDF_STATUS_SUCCESS;
  2814. }
  2815. /**
  2816. * dp_find_peer_by_addr_and_vdev() - Find peer by peer mac address within vdev
  2817. * @pdev - data path device instance
  2818. * @vdev - virtual interface instance
  2819. * @peer_addr - peer mac address
  2820. *
  2821. * Find peer by peer mac address within vdev
  2822. *
  2823. * Return: peer instance void pointer
  2824. * NULL cannot find target peer
  2825. */
  2826. void *dp_find_peer_by_addr_and_vdev(struct cdp_pdev *pdev_handle,
  2827. struct cdp_vdev *vdev_handle,
  2828. uint8_t *peer_addr)
  2829. {
  2830. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  2831. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  2832. struct dp_peer *peer;
  2833. peer = dp_peer_find_hash_find(pdev->soc, peer_addr, 0, DP_VDEV_ALL);
  2834. if (!peer)
  2835. return NULL;
  2836. if (peer->vdev != vdev) {
  2837. dp_peer_unref_delete(peer);
  2838. return NULL;
  2839. }
  2840. /* ref_cnt is incremented inside dp_peer_find_hash_find().
  2841. * Decrement it here.
  2842. */
  2843. dp_peer_unref_delete(peer);
  2844. return peer;
  2845. }
  2846. /**
  2847. * dp_peer_state_update() - update peer local state
  2848. * @pdev - data path device instance
  2849. * @peer_addr - peer mac address
  2850. * @state - new peer local state
  2851. *
  2852. * update peer local state
  2853. *
  2854. * Return: QDF_STATUS_SUCCESS registration success
  2855. */
  2856. QDF_STATUS dp_peer_state_update(struct cdp_pdev *pdev_handle, uint8_t *peer_mac,
  2857. enum ol_txrx_peer_state state)
  2858. {
  2859. struct dp_peer *peer;
  2860. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  2861. peer = dp_peer_find_hash_find(pdev->soc, peer_mac, 0, DP_VDEV_ALL);
  2862. if (!peer) {
  2863. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2864. "Failed to find peer for: [%pM]", peer_mac);
  2865. return QDF_STATUS_E_FAILURE;
  2866. }
  2867. peer->state = state;
  2868. dp_info("peer %pK state %d", peer, peer->state);
  2869. /* ref_cnt is incremented inside dp_peer_find_hash_find().
  2870. * Decrement it here.
  2871. */
  2872. dp_peer_unref_delete(peer);
  2873. return QDF_STATUS_SUCCESS;
  2874. }
  2875. /**
  2876. * dp_get_vdevid() - Get virtual interface id which peer registered
  2877. * @peer - peer instance
  2878. * @vdev_id - virtual interface id which peer registered
  2879. *
  2880. * Get virtual interface id which peer registered
  2881. *
  2882. * Return: QDF_STATUS_SUCCESS registration success
  2883. */
  2884. QDF_STATUS dp_get_vdevid(void *peer_handle, uint8_t *vdev_id)
  2885. {
  2886. struct dp_peer *peer = peer_handle;
  2887. dp_info("peer %pK vdev %pK vdev id %d",
  2888. peer, peer->vdev, peer->vdev->vdev_id);
  2889. *vdev_id = peer->vdev->vdev_id;
  2890. return QDF_STATUS_SUCCESS;
  2891. }
  2892. struct cdp_vdev *
  2893. dp_get_vdev_by_peer_addr(struct cdp_pdev *pdev_handle,
  2894. struct qdf_mac_addr peer_addr)
  2895. {
  2896. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  2897. struct dp_peer *peer = NULL;
  2898. if (!pdev) {
  2899. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  2900. "PDEV not found for peer_addr: " QDF_MAC_ADDR_STR,
  2901. QDF_MAC_ADDR_ARRAY(peer_addr.bytes));
  2902. return NULL;
  2903. }
  2904. peer = dp_find_peer_by_addr((struct cdp_pdev *)pdev, peer_addr.bytes);
  2905. if (!peer) {
  2906. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  2907. "PDEV not found for peer_addr:" QDF_MAC_ADDR_STR,
  2908. QDF_MAC_ADDR_ARRAY(peer_addr.bytes));
  2909. return NULL;
  2910. }
  2911. return (struct cdp_vdev *)peer->vdev;
  2912. }
  2913. /**
  2914. * dp_get_vdev_for_peer() - Get virtual interface instance which peer belongs
  2915. * @peer - peer instance
  2916. *
  2917. * Get virtual interface instance which peer belongs
  2918. *
  2919. * Return: virtual interface instance pointer
  2920. * NULL in case cannot find
  2921. */
  2922. struct cdp_vdev *dp_get_vdev_for_peer(void *peer_handle)
  2923. {
  2924. struct dp_peer *peer = peer_handle;
  2925. DP_TRACE(DEBUG, "peer %pK vdev %pK", peer, peer->vdev);
  2926. return (struct cdp_vdev *)peer->vdev;
  2927. }
  2928. /**
  2929. * dp_peer_get_peer_mac_addr() - Get peer mac address
  2930. * @peer - peer instance
  2931. *
  2932. * Get peer mac address
  2933. *
  2934. * Return: peer mac address pointer
  2935. * NULL in case cannot find
  2936. */
  2937. uint8_t *dp_peer_get_peer_mac_addr(void *peer_handle)
  2938. {
  2939. struct dp_peer *peer = peer_handle;
  2940. uint8_t *mac;
  2941. mac = peer->mac_addr.raw;
  2942. dp_info("peer %pK mac 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
  2943. peer, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  2944. return peer->mac_addr.raw;
  2945. }
  2946. /**
  2947. * dp_get_peer_state() - Get local peer state
  2948. * @peer - peer instance
  2949. *
  2950. * Get local peer state
  2951. *
  2952. * Return: peer status
  2953. */
  2954. int dp_get_peer_state(void *peer_handle)
  2955. {
  2956. struct dp_peer *peer = peer_handle;
  2957. DP_TRACE(DEBUG, "peer %pK stats %d", peer, peer->state);
  2958. return peer->state;
  2959. }
  2960. /**
  2961. * dp_local_peer_id_pool_init() - local peer id pool alloc for physical device
  2962. * @pdev - data path device instance
  2963. *
  2964. * local peer id pool alloc for physical device
  2965. *
  2966. * Return: none
  2967. */
  2968. void dp_local_peer_id_pool_init(struct dp_pdev *pdev)
  2969. {
  2970. int i;
  2971. /* point the freelist to the first ID */
  2972. pdev->local_peer_ids.freelist = 0;
  2973. /* link each ID to the next one */
  2974. for (i = 0; i < OL_TXRX_NUM_LOCAL_PEER_IDS; i++) {
  2975. pdev->local_peer_ids.pool[i] = i + 1;
  2976. pdev->local_peer_ids.map[i] = NULL;
  2977. }
  2978. /* link the last ID to itself, to mark the end of the list */
  2979. i = OL_TXRX_NUM_LOCAL_PEER_IDS;
  2980. pdev->local_peer_ids.pool[i] = i;
  2981. qdf_spinlock_create(&pdev->local_peer_ids.lock);
  2982. DP_TRACE(INFO, "Peer pool init");
  2983. }
  2984. /**
  2985. * dp_local_peer_id_alloc() - allocate local peer id
  2986. * @pdev - data path device instance
  2987. * @peer - new peer instance
  2988. *
  2989. * allocate local peer id
  2990. *
  2991. * Return: none
  2992. */
  2993. void dp_local_peer_id_alloc(struct dp_pdev *pdev, struct dp_peer *peer)
  2994. {
  2995. int i;
  2996. qdf_spin_lock_bh(&pdev->local_peer_ids.lock);
  2997. i = pdev->local_peer_ids.freelist;
  2998. if (pdev->local_peer_ids.pool[i] == i) {
  2999. /* the list is empty, except for the list-end marker */
  3000. peer->local_id = OL_TXRX_INVALID_LOCAL_PEER_ID;
  3001. } else {
  3002. /* take the head ID and advance the freelist */
  3003. peer->local_id = i;
  3004. pdev->local_peer_ids.freelist = pdev->local_peer_ids.pool[i];
  3005. pdev->local_peer_ids.map[i] = peer;
  3006. }
  3007. qdf_spin_unlock_bh(&pdev->local_peer_ids.lock);
  3008. dp_info("peer %pK, local id %d", peer, peer->local_id);
  3009. }
  3010. /**
  3011. * dp_local_peer_id_free() - remove local peer id
  3012. * @pdev - data path device instance
  3013. * @peer - peer instance should be removed
  3014. *
  3015. * remove local peer id
  3016. *
  3017. * Return: none
  3018. */
  3019. void dp_local_peer_id_free(struct dp_pdev *pdev, struct dp_peer *peer)
  3020. {
  3021. int i = peer->local_id;
  3022. if ((i == OL_TXRX_INVALID_LOCAL_PEER_ID) ||
  3023. (i >= OL_TXRX_NUM_LOCAL_PEER_IDS)) {
  3024. return;
  3025. }
  3026. /* put this ID on the head of the freelist */
  3027. qdf_spin_lock_bh(&pdev->local_peer_ids.lock);
  3028. pdev->local_peer_ids.pool[i] = pdev->local_peer_ids.freelist;
  3029. pdev->local_peer_ids.freelist = i;
  3030. pdev->local_peer_ids.map[i] = NULL;
  3031. qdf_spin_unlock_bh(&pdev->local_peer_ids.lock);
  3032. }
  3033. #endif
  3034. /**
  3035. * dp_peer_rxtid_stats: Retried Rx TID (REO queue) stats from HW
  3036. * @peer: DP peer handle
  3037. * @dp_stats_cmd_cb: REO command callback function
  3038. * @cb_ctxt: Callback context
  3039. *
  3040. * Return: none
  3041. */
  3042. void dp_peer_rxtid_stats(struct dp_peer *peer, void (*dp_stats_cmd_cb),
  3043. void *cb_ctxt)
  3044. {
  3045. struct dp_soc *soc = peer->vdev->pdev->soc;
  3046. struct hal_reo_cmd_params params;
  3047. int i;
  3048. if (!dp_stats_cmd_cb)
  3049. return;
  3050. qdf_mem_zero(&params, sizeof(params));
  3051. for (i = 0; i < DP_MAX_TIDS; i++) {
  3052. struct dp_rx_tid *rx_tid = &peer->rx_tid[i];
  3053. if (rx_tid->hw_qdesc_vaddr_unaligned) {
  3054. params.std.need_status = 1;
  3055. params.std.addr_lo =
  3056. rx_tid->hw_qdesc_paddr & 0xffffffff;
  3057. params.std.addr_hi =
  3058. (uint64_t)(rx_tid->hw_qdesc_paddr) >> 32;
  3059. if (cb_ctxt) {
  3060. dp_reo_send_cmd(soc, CMD_GET_QUEUE_STATS,
  3061. &params, dp_stats_cmd_cb, cb_ctxt);
  3062. } else {
  3063. dp_reo_send_cmd(soc, CMD_GET_QUEUE_STATS,
  3064. &params, dp_stats_cmd_cb, rx_tid);
  3065. }
  3066. /* Flush REO descriptor from HW cache to update stats
  3067. * in descriptor memory. This is to help debugging */
  3068. qdf_mem_zero(&params, sizeof(params));
  3069. params.std.need_status = 0;
  3070. params.std.addr_lo =
  3071. rx_tid->hw_qdesc_paddr & 0xffffffff;
  3072. params.std.addr_hi =
  3073. (uint64_t)(rx_tid->hw_qdesc_paddr) >> 32;
  3074. params.u.fl_cache_params.flush_no_inval = 1;
  3075. dp_reo_send_cmd(soc, CMD_FLUSH_CACHE, &params, NULL,
  3076. NULL);
  3077. }
  3078. }
  3079. }
  3080. QDF_STATUS
  3081. dp_set_michael_key(struct cdp_soc_t *soc,
  3082. uint8_t vdev_id,
  3083. uint8_t *peer_mac,
  3084. bool is_unicast, uint32_t *key)
  3085. {
  3086. QDF_STATUS status = QDF_STATUS_SUCCESS;
  3087. uint8_t sec_index = is_unicast ? 1 : 0;
  3088. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  3089. peer_mac, 0, vdev_id);
  3090. if (!peer || peer->delete_in_progress) {
  3091. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3092. "peer not found ");
  3093. status = QDF_STATUS_E_FAILURE;
  3094. goto fail;
  3095. }
  3096. qdf_mem_copy(&peer->security[sec_index].michael_key[0],
  3097. key, IEEE80211_WEP_MICLEN);
  3098. fail:
  3099. if (peer)
  3100. dp_peer_unref_delete(peer);
  3101. return status;
  3102. }
  3103. bool dp_peer_find_by_id_valid(struct dp_soc *soc, uint16_t peer_id)
  3104. {
  3105. struct dp_peer *peer = dp_peer_find_by_id(soc, peer_id);
  3106. if (peer) {
  3107. /*
  3108. * Decrement the peer ref which is taken as part of
  3109. * dp_peer_find_by_id if PEER_LOCK_REF_PROTECT is enabled
  3110. */
  3111. dp_peer_unref_del_find_by_id(peer);
  3112. return true;
  3113. }
  3114. return false;
  3115. }