dp_peer.c 90 KB

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