dp_peer.c 82 KB

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