dp_peer.c 94 KB

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