dp_rx.h 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  1. /*
  2. * Copyright (c) 2016-2021 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. #ifndef _DP_RX_H
  19. #define _DP_RX_H
  20. #include "hal_rx.h"
  21. #include "dp_peer.h"
  22. #include "dp_internal.h"
  23. #ifdef RXDMA_OPTIMIZATION
  24. #ifndef RX_DATA_BUFFER_ALIGNMENT
  25. #define RX_DATA_BUFFER_ALIGNMENT 128
  26. #endif
  27. #ifndef RX_MONITOR_BUFFER_ALIGNMENT
  28. #define RX_MONITOR_BUFFER_ALIGNMENT 128
  29. #endif
  30. #else /* RXDMA_OPTIMIZATION */
  31. #define RX_DATA_BUFFER_ALIGNMENT 4
  32. #define RX_MONITOR_BUFFER_ALIGNMENT 4
  33. #endif /* RXDMA_OPTIMIZATION */
  34. #ifdef QCA_HOST2FW_RXBUF_RING
  35. #define DP_WBM2SW_RBM(sw0_bm_id) HAL_RX_BUF_RBM_SW1_BM(sw0_bm_id)
  36. /* RBM value used for re-injecting defragmented packets into REO */
  37. #define DP_DEFRAG_RBM(sw0_bm_id) HAL_RX_BUF_RBM_SW3_BM(sw0_bm_id)
  38. #else
  39. #define DP_WBM2SW_RBM(sw0_bm_id) HAL_RX_BUF_RBM_SW3_BM(sw0_bm_id)
  40. #define DP_DEFRAG_RBM(sw0_bm_id) DP_WBM2SW_RBM(sw0_bm_id)
  41. #endif /* QCA_HOST2FW_RXBUF_RING */
  42. #define RX_BUFFER_RESERVATION 0
  43. #define DP_PEER_METADATA_PEER_ID_MASK 0x0000ffff
  44. #define DP_PEER_METADATA_PEER_ID_SHIFT 0
  45. #define DP_PEER_METADATA_VDEV_ID_MASK 0x003f0000
  46. #define DP_PEER_METADATA_VDEV_ID_SHIFT 16
  47. #define DP_PEER_METADATA_OFFLOAD_MASK 0x01000000
  48. #define DP_PEER_METADATA_OFFLOAD_SHIFT 24
  49. #define DP_DEFAULT_NOISEFLOOR (-96)
  50. #define DP_PEER_METADATA_PEER_ID_GET(_peer_metadata) \
  51. (((_peer_metadata) & DP_PEER_METADATA_PEER_ID_MASK) \
  52. >> DP_PEER_METADATA_PEER_ID_SHIFT)
  53. #define DP_PEER_METADATA_VDEV_ID_GET(_peer_metadata) \
  54. (((_peer_metadata) & DP_PEER_METADATA_VDEV_ID_MASK) \
  55. >> DP_PEER_METADATA_VDEV_ID_SHIFT)
  56. #define DP_PEER_METADATA_OFFLOAD_GET(_peer_metadata) \
  57. (((_peer_metadata) & DP_PEER_METADATA_OFFLOAD_MASK) \
  58. >> DP_PEER_METADATA_OFFLOAD_SHIFT)
  59. #define DP_RX_DESC_MAGIC 0xdec0de
  60. #define dp_rx_alert(params...) QDF_TRACE_FATAL(QDF_MODULE_ID_DP_RX, params)
  61. #define dp_rx_err(params...) QDF_TRACE_ERROR(QDF_MODULE_ID_DP_RX, params)
  62. #define dp_rx_warn(params...) QDF_TRACE_WARN(QDF_MODULE_ID_DP_RX, params)
  63. #define dp_rx_info(params...) \
  64. __QDF_TRACE_FL(QDF_TRACE_LEVEL_INFO_HIGH, QDF_MODULE_ID_DP_RX, ## params)
  65. #define dp_rx_info_rl(params...) \
  66. __QDF_TRACE_RL(QDF_TRACE_LEVEL_INFO_HIGH, QDF_MODULE_ID_DP_RX, ## params)
  67. #define dp_rx_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_DP_RX, params)
  68. /**
  69. * enum dp_rx_desc_state
  70. *
  71. * @RX_DESC_REPLENISH: rx desc replenished
  72. * @RX_DESC_FREELIST: rx desc in freelist
  73. */
  74. enum dp_rx_desc_state {
  75. RX_DESC_REPLENISHED,
  76. RX_DESC_IN_FREELIST,
  77. };
  78. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  79. /**
  80. * struct dp_rx_desc_dbg_info
  81. *
  82. * @freelist_caller: name of the function that put the
  83. * the rx desc in freelist
  84. * @freelist_ts: timestamp when the rx desc is put in
  85. * a freelist
  86. * @replenish_caller: name of the function that last
  87. * replenished the rx desc
  88. * @replenish_ts: last replenish timestamp
  89. * @prev_nbuf: previous nbuf info
  90. * @prev_nbuf_data_addr: previous nbuf data address
  91. */
  92. struct dp_rx_desc_dbg_info {
  93. char freelist_caller[QDF_MEM_FUNC_NAME_SIZE];
  94. uint64_t freelist_ts;
  95. char replenish_caller[QDF_MEM_FUNC_NAME_SIZE];
  96. uint64_t replenish_ts;
  97. qdf_nbuf_t prev_nbuf;
  98. uint8_t *prev_nbuf_data_addr;
  99. };
  100. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  101. /**
  102. * struct dp_rx_desc
  103. *
  104. * @nbuf : VA of the "skb" posted
  105. * @rx_buf_start : VA of the original Rx buffer, before
  106. * movement of any skb->data pointer
  107. * @paddr_buf_start : PA of the original Rx buffer, before
  108. * movement of any frag pointer
  109. * @cookie : index into the sw array which holds
  110. * the sw Rx descriptors
  111. * Cookie space is 21 bits:
  112. * lower 18 bits -- index
  113. * upper 3 bits -- pool_id
  114. * @pool_id : pool Id for which this allocated.
  115. * Can only be used if there is no flow
  116. * steering
  117. * @in_use rx_desc is in use
  118. * @unmapped used to mark rx_desc an unmapped if the corresponding
  119. * nbuf is already unmapped
  120. * @in_err_state : Nbuf sanity failed for this descriptor.
  121. * @nbuf_data_addr : VA of nbuf data posted
  122. */
  123. struct dp_rx_desc {
  124. qdf_nbuf_t nbuf;
  125. uint8_t *rx_buf_start;
  126. qdf_dma_addr_t paddr_buf_start;
  127. uint32_t cookie;
  128. uint8_t pool_id;
  129. #ifdef RX_DESC_DEBUG_CHECK
  130. uint32_t magic;
  131. uint8_t *nbuf_data_addr;
  132. struct dp_rx_desc_dbg_info *dbg_info;
  133. #endif
  134. uint8_t in_use:1,
  135. unmapped:1,
  136. in_err_state:1;
  137. };
  138. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  139. #ifdef ATH_RX_PRI_SAVE
  140. #define DP_RX_TID_SAVE(_nbuf, _tid) \
  141. (qdf_nbuf_set_priority(_nbuf, _tid))
  142. #else
  143. #define DP_RX_TID_SAVE(_nbuf, _tid)
  144. #endif
  145. /* RX Descriptor Multi Page memory alloc related */
  146. #define DP_RX_DESC_OFFSET_NUM_BITS 8
  147. #define DP_RX_DESC_PAGE_ID_NUM_BITS 8
  148. #define DP_RX_DESC_POOL_ID_NUM_BITS 4
  149. #define DP_RX_DESC_PAGE_ID_SHIFT DP_RX_DESC_OFFSET_NUM_BITS
  150. #define DP_RX_DESC_POOL_ID_SHIFT \
  151. (DP_RX_DESC_OFFSET_NUM_BITS + DP_RX_DESC_PAGE_ID_NUM_BITS)
  152. #define RX_DESC_MULTI_PAGE_COOKIE_POOL_ID_MASK \
  153. (((1 << DP_RX_DESC_POOL_ID_NUM_BITS) - 1) << DP_RX_DESC_POOL_ID_SHIFT)
  154. #define RX_DESC_MULTI_PAGE_COOKIE_PAGE_ID_MASK \
  155. (((1 << DP_RX_DESC_PAGE_ID_NUM_BITS) - 1) << \
  156. DP_RX_DESC_PAGE_ID_SHIFT)
  157. #define RX_DESC_MULTI_PAGE_COOKIE_OFFSET_MASK \
  158. ((1 << DP_RX_DESC_OFFSET_NUM_BITS) - 1)
  159. #define DP_RX_DESC_MULTI_PAGE_COOKIE_GET_POOL_ID(_cookie) \
  160. (((_cookie) & RX_DESC_MULTI_PAGE_COOKIE_POOL_ID_MASK) >> \
  161. DP_RX_DESC_POOL_ID_SHIFT)
  162. #define DP_RX_DESC_MULTI_PAGE_COOKIE_GET_PAGE_ID(_cookie) \
  163. (((_cookie) & RX_DESC_MULTI_PAGE_COOKIE_PAGE_ID_MASK) >> \
  164. DP_RX_DESC_PAGE_ID_SHIFT)
  165. #define DP_RX_DESC_MULTI_PAGE_COOKIE_GET_OFFSET(_cookie) \
  166. ((_cookie) & RX_DESC_MULTI_PAGE_COOKIE_OFFSET_MASK)
  167. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  168. #define RX_DESC_COOKIE_INDEX_SHIFT 0
  169. #define RX_DESC_COOKIE_INDEX_MASK 0x3ffff /* 18 bits */
  170. #define RX_DESC_COOKIE_POOL_ID_SHIFT 18
  171. #define RX_DESC_COOKIE_POOL_ID_MASK 0x1c0000
  172. #define DP_RX_DESC_COOKIE_MAX \
  173. (RX_DESC_COOKIE_INDEX_MASK | RX_DESC_COOKIE_POOL_ID_MASK)
  174. #define DP_RX_DESC_COOKIE_POOL_ID_GET(_cookie) \
  175. (((_cookie) & RX_DESC_COOKIE_POOL_ID_MASK) >> \
  176. RX_DESC_COOKIE_POOL_ID_SHIFT)
  177. #define DP_RX_DESC_COOKIE_INDEX_GET(_cookie) \
  178. (((_cookie) & RX_DESC_COOKIE_INDEX_MASK) >> \
  179. RX_DESC_COOKIE_INDEX_SHIFT)
  180. #define dp_rx_add_to_free_desc_list(head, tail, new) \
  181. __dp_rx_add_to_free_desc_list(head, tail, new, __func__)
  182. #define dp_rx_buffers_replenish(soc, mac_id, rxdma_srng, rx_desc_pool, \
  183. num_buffers, desc_list, tail) \
  184. __dp_rx_buffers_replenish(soc, mac_id, rxdma_srng, rx_desc_pool, \
  185. num_buffers, desc_list, tail, __func__)
  186. #ifdef DP_RX_SPECIAL_FRAME_NEED
  187. /**
  188. * dp_rx_is_special_frame() - check is RX frame special needed
  189. *
  190. * @nbuf: RX skb pointer
  191. * @frame_mask: the mask for speical frame needed
  192. *
  193. * Check is RX frame wanted matched with mask
  194. *
  195. * Return: true - special frame needed, false - no
  196. */
  197. static inline
  198. bool dp_rx_is_special_frame(qdf_nbuf_t nbuf, uint32_t frame_mask)
  199. {
  200. if (((frame_mask & FRAME_MASK_IPV4_ARP) &&
  201. qdf_nbuf_is_ipv4_arp_pkt(nbuf)) ||
  202. ((frame_mask & FRAME_MASK_IPV4_DHCP) &&
  203. qdf_nbuf_is_ipv4_dhcp_pkt(nbuf)) ||
  204. ((frame_mask & FRAME_MASK_IPV4_EAPOL) &&
  205. qdf_nbuf_is_ipv4_eapol_pkt(nbuf)) ||
  206. ((frame_mask & FRAME_MASK_IPV6_DHCP) &&
  207. qdf_nbuf_is_ipv6_dhcp_pkt(nbuf)))
  208. return true;
  209. return false;
  210. }
  211. /**
  212. * dp_rx_deliver_special_frame() - Deliver the RX special frame to stack
  213. * if matches mask
  214. *
  215. * @soc: Datapath soc handler
  216. * @peer: pointer to DP peer
  217. * @nbuf: pointer to the skb of RX frame
  218. * @frame_mask: the mask for speical frame needed
  219. * @rx_tlv_hdr: start of rx tlv header
  220. *
  221. * note: Msdu_len must have been stored in QDF_NBUF_CB_RX_PKT_LEN(nbuf) and
  222. * single nbuf is expected.
  223. *
  224. * return: true - nbuf has been delivered to stack, false - not.
  225. */
  226. bool dp_rx_deliver_special_frame(struct dp_soc *soc, struct dp_peer *peer,
  227. qdf_nbuf_t nbuf, uint32_t frame_mask,
  228. uint8_t *rx_tlv_hdr);
  229. #else
  230. static inline
  231. bool dp_rx_is_special_frame(qdf_nbuf_t nbuf, uint32_t frame_mask)
  232. {
  233. return false;
  234. }
  235. static inline
  236. bool dp_rx_deliver_special_frame(struct dp_soc *soc, struct dp_peer *peer,
  237. qdf_nbuf_t nbuf, uint32_t frame_mask,
  238. uint8_t *rx_tlv_hdr)
  239. {
  240. return false;
  241. }
  242. #endif
  243. /* DOC: Offset to obtain LLC hdr
  244. *
  245. * In the case of Wifi parse error
  246. * to reach LLC header from beginning
  247. * of VLAN tag we need to skip 8 bytes.
  248. * Vlan_tag(4)+length(2)+length added
  249. * by HW(2) = 8 bytes.
  250. */
  251. #define DP_SKIP_VLAN 8
  252. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  253. /**
  254. * struct dp_rx_cached_buf - rx cached buffer
  255. * @list: linked list node
  256. * @buf: skb buffer
  257. */
  258. struct dp_rx_cached_buf {
  259. qdf_list_node_t node;
  260. qdf_nbuf_t buf;
  261. };
  262. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  263. /*
  264. *dp_rx_xor_block() - xor block of data
  265. *@b: destination data block
  266. *@a: source data block
  267. *@len: length of the data to process
  268. *
  269. *Returns: None
  270. */
  271. static inline void dp_rx_xor_block(uint8_t *b, const uint8_t *a, qdf_size_t len)
  272. {
  273. qdf_size_t i;
  274. for (i = 0; i < len; i++)
  275. b[i] ^= a[i];
  276. }
  277. /*
  278. *dp_rx_rotl() - rotate the bits left
  279. *@val: unsigned integer input value
  280. *@bits: number of bits
  281. *
  282. *Returns: Integer with left rotated by number of 'bits'
  283. */
  284. static inline uint32_t dp_rx_rotl(uint32_t val, int bits)
  285. {
  286. return (val << bits) | (val >> (32 - bits));
  287. }
  288. /*
  289. *dp_rx_rotr() - rotate the bits right
  290. *@val: unsigned integer input value
  291. *@bits: number of bits
  292. *
  293. *Returns: Integer with right rotated by number of 'bits'
  294. */
  295. static inline uint32_t dp_rx_rotr(uint32_t val, int bits)
  296. {
  297. return (val >> bits) | (val << (32 - bits));
  298. }
  299. /*
  300. * dp_set_rx_queue() - set queue_mapping in skb
  301. * @nbuf: skb
  302. * @queue_id: rx queue_id
  303. *
  304. * Return: void
  305. */
  306. #ifdef QCA_OL_RX_MULTIQ_SUPPORT
  307. static inline void dp_set_rx_queue(qdf_nbuf_t nbuf, uint8_t queue_id)
  308. {
  309. qdf_nbuf_record_rx_queue(nbuf, queue_id);
  310. return;
  311. }
  312. #else
  313. static inline void dp_set_rx_queue(qdf_nbuf_t nbuf, uint8_t queue_id)
  314. {
  315. }
  316. #endif
  317. /*
  318. *dp_rx_xswap() - swap the bits left
  319. *@val: unsigned integer input value
  320. *
  321. *Returns: Integer with bits swapped
  322. */
  323. static inline uint32_t dp_rx_xswap(uint32_t val)
  324. {
  325. return ((val & 0x00ff00ff) << 8) | ((val & 0xff00ff00) >> 8);
  326. }
  327. /*
  328. *dp_rx_get_le32_split() - get little endian 32 bits split
  329. *@b0: byte 0
  330. *@b1: byte 1
  331. *@b2: byte 2
  332. *@b3: byte 3
  333. *
  334. *Returns: Integer with split little endian 32 bits
  335. */
  336. static inline uint32_t dp_rx_get_le32_split(uint8_t b0, uint8_t b1, uint8_t b2,
  337. uint8_t b3)
  338. {
  339. return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
  340. }
  341. /*
  342. *dp_rx_get_le32() - get little endian 32 bits
  343. *@b0: byte 0
  344. *@b1: byte 1
  345. *@b2: byte 2
  346. *@b3: byte 3
  347. *
  348. *Returns: Integer with little endian 32 bits
  349. */
  350. static inline uint32_t dp_rx_get_le32(const uint8_t *p)
  351. {
  352. return dp_rx_get_le32_split(p[0], p[1], p[2], p[3]);
  353. }
  354. /*
  355. * dp_rx_put_le32() - put little endian 32 bits
  356. * @p: destination char array
  357. * @v: source 32-bit integer
  358. *
  359. * Returns: None
  360. */
  361. static inline void dp_rx_put_le32(uint8_t *p, uint32_t v)
  362. {
  363. p[0] = (v) & 0xff;
  364. p[1] = (v >> 8) & 0xff;
  365. p[2] = (v >> 16) & 0xff;
  366. p[3] = (v >> 24) & 0xff;
  367. }
  368. /* Extract michal mic block of data */
  369. #define dp_rx_michael_block(l, r) \
  370. do { \
  371. r ^= dp_rx_rotl(l, 17); \
  372. l += r; \
  373. r ^= dp_rx_xswap(l); \
  374. l += r; \
  375. r ^= dp_rx_rotl(l, 3); \
  376. l += r; \
  377. r ^= dp_rx_rotr(l, 2); \
  378. l += r; \
  379. } while (0)
  380. /**
  381. * struct dp_rx_desc_list_elem_t
  382. *
  383. * @next : Next pointer to form free list
  384. * @rx_desc : DP Rx descriptor
  385. */
  386. union dp_rx_desc_list_elem_t {
  387. union dp_rx_desc_list_elem_t *next;
  388. struct dp_rx_desc rx_desc;
  389. };
  390. #ifdef RX_DESC_MULTI_PAGE_ALLOC
  391. /**
  392. * dp_rx_desc_find() - find dp rx descriptor from page ID and offset
  393. * @page_id: Page ID
  394. * @offset: Offset of the descriptor element
  395. *
  396. * Return: RX descriptor element
  397. */
  398. union dp_rx_desc_list_elem_t *dp_rx_desc_find(uint16_t page_id, uint16_t offset,
  399. struct rx_desc_pool *rx_pool);
  400. static inline
  401. struct dp_rx_desc *dp_get_rx_desc_from_cookie(struct dp_soc *soc,
  402. struct rx_desc_pool *pool,
  403. uint32_t cookie)
  404. {
  405. uint8_t pool_id = DP_RX_DESC_MULTI_PAGE_COOKIE_GET_POOL_ID(cookie);
  406. uint16_t page_id = DP_RX_DESC_MULTI_PAGE_COOKIE_GET_PAGE_ID(cookie);
  407. uint8_t offset = DP_RX_DESC_MULTI_PAGE_COOKIE_GET_OFFSET(cookie);
  408. struct rx_desc_pool *rx_desc_pool;
  409. union dp_rx_desc_list_elem_t *rx_desc_elem;
  410. if (qdf_unlikely(pool_id >= MAX_RXDESC_POOLS))
  411. return NULL;
  412. rx_desc_pool = &pool[pool_id];
  413. rx_desc_elem = (union dp_rx_desc_list_elem_t *)
  414. (rx_desc_pool->desc_pages.cacheable_pages[page_id] +
  415. rx_desc_pool->elem_size * offset);
  416. return &rx_desc_elem->rx_desc;
  417. }
  418. /**
  419. * dp_rx_cookie_2_va_rxdma_buf() - Converts cookie to a virtual address of
  420. * the Rx descriptor on Rx DMA source ring buffer
  421. * @soc: core txrx main context
  422. * @cookie: cookie used to lookup virtual address
  423. *
  424. * Return: Pointer to the Rx descriptor
  425. */
  426. static inline
  427. struct dp_rx_desc *dp_rx_cookie_2_va_rxdma_buf(struct dp_soc *soc,
  428. uint32_t cookie)
  429. {
  430. return dp_get_rx_desc_from_cookie(soc, &soc->rx_desc_buf[0], cookie);
  431. }
  432. /**
  433. * dp_rx_cookie_2_va_mon_buf() - Converts cookie to a virtual address of
  434. * the Rx descriptor on monitor ring buffer
  435. * @soc: core txrx main context
  436. * @cookie: cookie used to lookup virtual address
  437. *
  438. * Return: Pointer to the Rx descriptor
  439. */
  440. static inline
  441. struct dp_rx_desc *dp_rx_cookie_2_va_mon_buf(struct dp_soc *soc,
  442. uint32_t cookie)
  443. {
  444. return dp_get_rx_desc_from_cookie(soc, &soc->rx_desc_mon[0], cookie);
  445. }
  446. /**
  447. * dp_rx_cookie_2_va_mon_status() - Converts cookie to a virtual address of
  448. * the Rx descriptor on monitor status ring buffer
  449. * @soc: core txrx main context
  450. * @cookie: cookie used to lookup virtual address
  451. *
  452. * Return: Pointer to the Rx descriptor
  453. */
  454. static inline
  455. struct dp_rx_desc *dp_rx_cookie_2_va_mon_status(struct dp_soc *soc,
  456. uint32_t cookie)
  457. {
  458. return dp_get_rx_desc_from_cookie(soc, &soc->rx_desc_status[0], cookie);
  459. }
  460. #else
  461. void dp_rx_desc_pool_init(struct dp_soc *soc, uint32_t pool_id,
  462. uint32_t pool_size,
  463. struct rx_desc_pool *rx_desc_pool);
  464. /**
  465. * dp_rx_cookie_2_va_rxdma_buf() - Converts cookie to a virtual address of
  466. * the Rx descriptor on Rx DMA source ring buffer
  467. * @soc: core txrx main context
  468. * @cookie: cookie used to lookup virtual address
  469. *
  470. * Return: void *: Virtual Address of the Rx descriptor
  471. */
  472. static inline
  473. void *dp_rx_cookie_2_va_rxdma_buf(struct dp_soc *soc, uint32_t cookie)
  474. {
  475. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  476. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  477. struct rx_desc_pool *rx_desc_pool;
  478. if (qdf_unlikely(pool_id >= MAX_RXDESC_POOLS))
  479. return NULL;
  480. rx_desc_pool = &soc->rx_desc_buf[pool_id];
  481. if (qdf_unlikely(index >= rx_desc_pool->pool_size))
  482. return NULL;
  483. return &rx_desc_pool->array[index].rx_desc;
  484. }
  485. /**
  486. * dp_rx_cookie_2_va_mon_buf() - Converts cookie to a virtual address of
  487. * the Rx descriptor on monitor ring buffer
  488. * @soc: core txrx main context
  489. * @cookie: cookie used to lookup virtual address
  490. *
  491. * Return: void *: Virtual Address of the Rx descriptor
  492. */
  493. static inline
  494. void *dp_rx_cookie_2_va_mon_buf(struct dp_soc *soc, uint32_t cookie)
  495. {
  496. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  497. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  498. /* TODO */
  499. /* Add sanity for pool_id & index */
  500. return &(soc->rx_desc_mon[pool_id].array[index].rx_desc);
  501. }
  502. /**
  503. * dp_rx_cookie_2_va_mon_status() - Converts cookie to a virtual address of
  504. * the Rx descriptor on monitor status ring buffer
  505. * @soc: core txrx main context
  506. * @cookie: cookie used to lookup virtual address
  507. *
  508. * Return: void *: Virtual Address of the Rx descriptor
  509. */
  510. static inline
  511. void *dp_rx_cookie_2_va_mon_status(struct dp_soc *soc, uint32_t cookie)
  512. {
  513. uint8_t pool_id = DP_RX_DESC_COOKIE_POOL_ID_GET(cookie);
  514. uint16_t index = DP_RX_DESC_COOKIE_INDEX_GET(cookie);
  515. /* TODO */
  516. /* Add sanity for pool_id & index */
  517. return &(soc->rx_desc_status[pool_id].array[index].rx_desc);
  518. }
  519. #endif /* RX_DESC_MULTI_PAGE_ALLOC */
  520. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  521. static inline bool dp_rx_check_ap_bridge(struct dp_vdev *vdev)
  522. {
  523. return vdev->ap_bridge_enabled;
  524. }
  525. #ifdef DP_RX_DESC_COOKIE_INVALIDATE
  526. static inline QDF_STATUS
  527. dp_rx_cookie_check_and_invalidate(hal_ring_desc_t ring_desc)
  528. {
  529. if (qdf_unlikely(HAL_RX_REO_BUF_COOKIE_INVALID_GET(ring_desc)))
  530. return QDF_STATUS_E_FAILURE;
  531. HAL_RX_REO_BUF_COOKIE_INVALID_SET(ring_desc);
  532. return QDF_STATUS_SUCCESS;
  533. }
  534. /**
  535. * dp_rx_cookie_reset_invalid_bit() - Reset the invalid bit of the cookie
  536. * field in ring descriptor
  537. * @ring_desc: ring descriptor
  538. *
  539. * Return: None
  540. */
  541. static inline void
  542. dp_rx_cookie_reset_invalid_bit(hal_ring_desc_t ring_desc)
  543. {
  544. HAL_RX_REO_BUF_COOKIE_INVALID_RESET(ring_desc);
  545. }
  546. #else
  547. static inline QDF_STATUS
  548. dp_rx_cookie_check_and_invalidate(hal_ring_desc_t ring_desc)
  549. {
  550. return QDF_STATUS_SUCCESS;
  551. }
  552. static inline void
  553. dp_rx_cookie_reset_invalid_bit(hal_ring_desc_t ring_desc)
  554. {
  555. }
  556. #endif
  557. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  558. QDF_STATUS dp_rx_desc_pool_is_allocated(struct rx_desc_pool *rx_desc_pool);
  559. QDF_STATUS dp_rx_desc_pool_alloc(struct dp_soc *soc,
  560. uint32_t pool_size,
  561. struct rx_desc_pool *rx_desc_pool);
  562. void dp_rx_desc_pool_init(struct dp_soc *soc, uint32_t pool_id,
  563. uint32_t pool_size,
  564. struct rx_desc_pool *rx_desc_pool);
  565. void dp_rx_pdev_mon_buf_buffers_free(struct dp_pdev *pdev, uint32_t mac_id);
  566. void dp_rx_add_desc_list_to_free_list(struct dp_soc *soc,
  567. union dp_rx_desc_list_elem_t **local_desc_list,
  568. union dp_rx_desc_list_elem_t **tail,
  569. uint16_t pool_id,
  570. struct rx_desc_pool *rx_desc_pool);
  571. uint16_t dp_rx_get_free_desc_list(struct dp_soc *soc, uint32_t pool_id,
  572. struct rx_desc_pool *rx_desc_pool,
  573. uint16_t num_descs,
  574. union dp_rx_desc_list_elem_t **desc_list,
  575. union dp_rx_desc_list_elem_t **tail);
  576. QDF_STATUS dp_rx_pdev_desc_pool_alloc(struct dp_pdev *pdev);
  577. void dp_rx_pdev_desc_pool_free(struct dp_pdev *pdev);
  578. QDF_STATUS dp_rx_pdev_desc_pool_init(struct dp_pdev *pdev);
  579. void dp_rx_pdev_desc_pool_deinit(struct dp_pdev *pdev);
  580. void dp_rx_desc_pool_deinit(struct dp_soc *soc,
  581. struct rx_desc_pool *rx_desc_pool,
  582. uint32_t pool_id);
  583. QDF_STATUS dp_rx_pdev_attach(struct dp_pdev *pdev);
  584. QDF_STATUS dp_rx_pdev_buffers_alloc(struct dp_pdev *pdev);
  585. void dp_rx_pdev_buffers_free(struct dp_pdev *pdev);
  586. void dp_rx_pdev_detach(struct dp_pdev *pdev);
  587. void dp_print_napi_stats(struct dp_soc *soc);
  588. /**
  589. * dp_rx_vdev_detach() - detach vdev from dp rx
  590. * @vdev: virtual device instance
  591. *
  592. * Return: QDF_STATUS_SUCCESS: success
  593. * QDF_STATUS_E_RESOURCES: Error return
  594. */
  595. QDF_STATUS dp_rx_vdev_detach(struct dp_vdev *vdev);
  596. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  597. uint32_t
  598. dp_rx_process(struct dp_intr *int_ctx, hal_ring_handle_t hal_ring_hdl,
  599. uint8_t reo_ring_num,
  600. uint32_t quota);
  601. /**
  602. * dp_rx_err_process() - Processes error frames routed to REO error ring
  603. * @int_ctx: pointer to DP interrupt context
  604. * @soc: core txrx main context
  605. * @hal_ring: opaque pointer to the HAL Rx Error Ring, which will be serviced
  606. * @quota: No. of units (packets) that can be serviced in one shot.
  607. *
  608. * This function implements error processing and top level demultiplexer
  609. * for all the frames routed to REO error ring.
  610. *
  611. * Return: uint32_t: No. of elements processed
  612. */
  613. uint32_t dp_rx_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  614. hal_ring_handle_t hal_ring_hdl, uint32_t quota);
  615. /**
  616. * dp_rx_wbm_err_process() - Processes error frames routed to WBM release ring
  617. * @int_ctx: pointer to DP interrupt context
  618. * @soc: core txrx main context
  619. * @hal_ring: opaque pointer to the HAL Rx Error Ring, which will be serviced
  620. * @quota: No. of units (packets) that can be serviced in one shot.
  621. *
  622. * This function implements error processing and top level demultiplexer
  623. * for all the frames routed to WBM2HOST sw release ring.
  624. *
  625. * Return: uint32_t: No. of elements processed
  626. */
  627. uint32_t
  628. dp_rx_wbm_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  629. hal_ring_handle_t hal_ring_hdl, uint32_t quota);
  630. /**
  631. * dp_rx_sg_create() - create a frag_list for MSDUs which are spread across
  632. * multiple nbufs.
  633. * @soc: core txrx main context
  634. * @nbuf: pointer to the first msdu of an amsdu.
  635. *
  636. * This function implements the creation of RX frag_list for cases
  637. * where an MSDU is spread across multiple nbufs.
  638. *
  639. * Return: returns the head nbuf which contains complete frag_list.
  640. */
  641. qdf_nbuf_t dp_rx_sg_create(struct dp_soc *soc, qdf_nbuf_t nbuf);
  642. /*
  643. * dp_rx_desc_nbuf_and_pool_free() - free the sw rx desc pool called during
  644. * de-initialization of wifi module.
  645. *
  646. * @soc: core txrx main context
  647. * @pool_id: pool_id which is one of 3 mac_ids
  648. * @rx_desc_pool: rx descriptor pool pointer
  649. *
  650. * Return: None
  651. */
  652. void dp_rx_desc_nbuf_and_pool_free(struct dp_soc *soc, uint32_t pool_id,
  653. struct rx_desc_pool *rx_desc_pool);
  654. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  655. /*
  656. * dp_rx_desc_nbuf_free() - free the sw rx desc nbufs called during
  657. * de-initialization of wifi module.
  658. *
  659. * @soc: core txrx main context
  660. * @pool_id: pool_id which is one of 3 mac_ids
  661. * @rx_desc_pool: rx descriptor pool pointer
  662. *
  663. * Return: None
  664. */
  665. void dp_rx_desc_nbuf_free(struct dp_soc *soc,
  666. struct rx_desc_pool *rx_desc_pool);
  667. #ifdef DP_RX_MON_MEM_FRAG
  668. /*
  669. * dp_rx_desc_frag_free() - free the sw rx desc frag called during
  670. * de-initialization of wifi module.
  671. *
  672. * @soc: core txrx main context
  673. * @rx_desc_pool: rx descriptor pool pointer
  674. *
  675. * Return: None
  676. */
  677. void dp_rx_desc_frag_free(struct dp_soc *soc,
  678. struct rx_desc_pool *rx_desc_pool);
  679. #else
  680. static inline
  681. void dp_rx_desc_frag_free(struct dp_soc *soc,
  682. struct rx_desc_pool *rx_desc_pool)
  683. {
  684. }
  685. #endif
  686. /*
  687. * dp_rx_desc_pool_free() - free the sw rx desc array called during
  688. * de-initialization of wifi module.
  689. *
  690. * @soc: core txrx main context
  691. * @rx_desc_pool: rx descriptor pool pointer
  692. *
  693. * Return: None
  694. */
  695. void dp_rx_desc_pool_free(struct dp_soc *soc,
  696. struct rx_desc_pool *rx_desc_pool);
  697. void dp_rx_deliver_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf_list,
  698. struct dp_peer *peer);
  699. #ifdef RX_DESC_LOGGING
  700. /*
  701. * dp_rx_desc_alloc_dbg_info() - Alloc memory for rx descriptor debug
  702. * structure
  703. * @rx_desc: rx descriptor pointer
  704. *
  705. * Return: None
  706. */
  707. static inline
  708. void dp_rx_desc_alloc_dbg_info(struct dp_rx_desc *rx_desc)
  709. {
  710. rx_desc->dbg_info = qdf_mem_malloc(sizeof(struct dp_rx_desc_dbg_info));
  711. }
  712. /*
  713. * dp_rx_desc_free_dbg_info() - Free rx descriptor debug
  714. * structure memory
  715. * @rx_desc: rx descriptor pointer
  716. *
  717. * Return: None
  718. */
  719. static inline
  720. void dp_rx_desc_free_dbg_info(struct dp_rx_desc *rx_desc)
  721. {
  722. qdf_mem_free(rx_desc->dbg_info);
  723. }
  724. /*
  725. * dp_rx_desc_update_dbg_info() - Update rx descriptor debug info
  726. * structure memory
  727. * @rx_desc: rx descriptor pointer
  728. *
  729. * Return: None
  730. */
  731. static
  732. void dp_rx_desc_update_dbg_info(struct dp_rx_desc *rx_desc,
  733. const char *func_name, uint8_t flag)
  734. {
  735. struct dp_rx_desc_dbg_info *info = rx_desc->dbg_info;
  736. if (!info)
  737. return;
  738. if (flag == RX_DESC_REPLENISHED) {
  739. qdf_str_lcopy(info->replenish_caller, func_name,
  740. QDF_MEM_FUNC_NAME_SIZE);
  741. info->replenish_ts = qdf_get_log_timestamp();
  742. } else {
  743. qdf_str_lcopy(info->freelist_caller, func_name,
  744. QDF_MEM_FUNC_NAME_SIZE);
  745. info->freelist_ts = qdf_get_log_timestamp();
  746. info->prev_nbuf = rx_desc->nbuf;
  747. info->prev_nbuf_data_addr = rx_desc->nbuf_data_addr;
  748. rx_desc->nbuf_data_addr = NULL;
  749. }
  750. }
  751. #else
  752. static inline
  753. void dp_rx_desc_alloc_dbg_info(struct dp_rx_desc *rx_desc)
  754. {
  755. }
  756. static inline
  757. void dp_rx_desc_free_dbg_info(struct dp_rx_desc *rx_desc)
  758. {
  759. }
  760. static inline
  761. void dp_rx_desc_update_dbg_info(struct dp_rx_desc *rx_desc,
  762. const char *func_name, uint8_t flag)
  763. {
  764. }
  765. #endif /* RX_DESC_LOGGING */
  766. /**
  767. * dp_rx_add_to_free_desc_list() - Adds to a local free descriptor list
  768. *
  769. * @head: pointer to the head of local free list
  770. * @tail: pointer to the tail of local free list
  771. * @new: new descriptor that is added to the free list
  772. * @func_name: caller func name
  773. *
  774. * Return: void:
  775. */
  776. static inline
  777. void __dp_rx_add_to_free_desc_list(union dp_rx_desc_list_elem_t **head,
  778. union dp_rx_desc_list_elem_t **tail,
  779. struct dp_rx_desc *new, const char *func_name)
  780. {
  781. qdf_assert(head && new);
  782. dp_rx_desc_update_dbg_info(new, func_name, RX_DESC_IN_FREELIST);
  783. new->nbuf = NULL;
  784. new->in_use = 0;
  785. ((union dp_rx_desc_list_elem_t *)new)->next = *head;
  786. *head = (union dp_rx_desc_list_elem_t *)new;
  787. /* reset tail if head->next is NULL */
  788. if (!*tail || !(*head)->next)
  789. *tail = *head;
  790. }
  791. uint8_t dp_rx_process_invalid_peer(struct dp_soc *soc, qdf_nbuf_t nbuf,
  792. uint8_t mac_id);
  793. void dp_rx_process_invalid_peer_wrapper(struct dp_soc *soc,
  794. qdf_nbuf_t mpdu, bool mpdu_done, uint8_t mac_id);
  795. void dp_rx_process_mic_error(struct dp_soc *soc, qdf_nbuf_t nbuf,
  796. uint8_t *rx_tlv_hdr, struct dp_peer *peer);
  797. void dp_2k_jump_handle(struct dp_soc *soc, qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr,
  798. uint16_t peer_id, uint8_t tid);
  799. #define DP_RX_HEAD_APPEND(head, elem) \
  800. do { \
  801. qdf_nbuf_set_next((elem), (head)); \
  802. (head) = (elem); \
  803. } while (0)
  804. #define DP_RX_LIST_APPEND(head, tail, elem) \
  805. do { \
  806. if (!(head)) { \
  807. (head) = (elem); \
  808. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(head) = 1;\
  809. } else { \
  810. qdf_nbuf_set_next((tail), (elem)); \
  811. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(head)++; \
  812. } \
  813. (tail) = (elem); \
  814. qdf_nbuf_set_next((tail), NULL); \
  815. } while (0)
  816. #define DP_RX_MERGE_TWO_LIST(phead, ptail, chead, ctail) \
  817. do { \
  818. if (!(phead)) { \
  819. (phead) = (chead); \
  820. } else { \
  821. qdf_nbuf_set_next((ptail), (chead)); \
  822. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(phead) += \
  823. QDF_NBUF_CB_RX_NUM_ELEMENTS_IN_LIST(chead); \
  824. } \
  825. (ptail) = (ctail); \
  826. qdf_nbuf_set_next((ptail), NULL); \
  827. } while (0)
  828. #if defined(QCA_PADDR_CHECK_ON_3TH_PLATFORM)
  829. /*
  830. * on some third-party platform, the memory below 0x2000
  831. * is reserved for target use, so any memory allocated in this
  832. * region should not be used by host
  833. */
  834. #define MAX_RETRY 50
  835. #define DP_PHY_ADDR_RESERVED 0x2000
  836. #elif defined(BUILD_X86)
  837. /*
  838. * in M2M emulation platforms (x86) the memory below 0x50000000
  839. * is reserved for target use, so any memory allocated in this
  840. * region should not be used by host
  841. */
  842. #define MAX_RETRY 100
  843. #define DP_PHY_ADDR_RESERVED 0x50000000
  844. #endif
  845. #if defined(QCA_PADDR_CHECK_ON_3TH_PLATFORM) || defined(BUILD_X86)
  846. /**
  847. * dp_check_paddr() - check if current phy address is valid or not
  848. * @dp_soc: core txrx main context
  849. * @rx_netbuf: skb buffer
  850. * @paddr: physical address
  851. * @rx_desc_pool: struct of rx descriptor pool
  852. * check if the physical address of the nbuf->data is less
  853. * than DP_PHY_ADDR_RESERVED then free the nbuf and try
  854. * allocating new nbuf. We can try for 100 times.
  855. *
  856. * This is a temp WAR till we fix it properly.
  857. *
  858. * Return: success or failure.
  859. */
  860. static inline
  861. int dp_check_paddr(struct dp_soc *dp_soc,
  862. qdf_nbuf_t *rx_netbuf,
  863. qdf_dma_addr_t *paddr,
  864. struct rx_desc_pool *rx_desc_pool)
  865. {
  866. uint32_t nbuf_retry = 0;
  867. int32_t ret;
  868. if (qdf_likely(*paddr > DP_PHY_ADDR_RESERVED))
  869. return QDF_STATUS_SUCCESS;
  870. do {
  871. dp_debug("invalid phy addr 0x%llx, trying again",
  872. (uint64_t)(*paddr));
  873. nbuf_retry++;
  874. if ((*rx_netbuf)) {
  875. /* Not freeing buffer intentionally.
  876. * Observed that same buffer is getting
  877. * re-allocated resulting in longer load time
  878. * WMI init timeout.
  879. * This buffer is anyway not useful so skip it.
  880. *.Add such buffer to invalid list and free
  881. *.them when driver unload.
  882. **/
  883. qdf_nbuf_unmap_nbytes_single(dp_soc->osdev,
  884. *rx_netbuf,
  885. QDF_DMA_FROM_DEVICE,
  886. rx_desc_pool->buf_size);
  887. qdf_nbuf_queue_add(&dp_soc->invalid_buf_queue,
  888. *rx_netbuf);
  889. }
  890. *rx_netbuf = qdf_nbuf_alloc(dp_soc->osdev,
  891. rx_desc_pool->buf_size,
  892. RX_BUFFER_RESERVATION,
  893. rx_desc_pool->buf_alignment,
  894. FALSE);
  895. if (qdf_unlikely(!(*rx_netbuf)))
  896. return QDF_STATUS_E_FAILURE;
  897. ret = qdf_nbuf_map_nbytes_single(dp_soc->osdev,
  898. *rx_netbuf,
  899. QDF_DMA_FROM_DEVICE,
  900. rx_desc_pool->buf_size);
  901. if (qdf_unlikely(ret == QDF_STATUS_E_FAILURE)) {
  902. qdf_nbuf_free(*rx_netbuf);
  903. *rx_netbuf = NULL;
  904. continue;
  905. }
  906. *paddr = qdf_nbuf_get_frag_paddr(*rx_netbuf, 0);
  907. if (qdf_likely(*paddr > DP_PHY_ADDR_RESERVED))
  908. return QDF_STATUS_SUCCESS;
  909. } while (nbuf_retry < MAX_RETRY);
  910. if ((*rx_netbuf)) {
  911. qdf_nbuf_unmap_nbytes_single(dp_soc->osdev,
  912. *rx_netbuf,
  913. QDF_DMA_FROM_DEVICE,
  914. rx_desc_pool->buf_size);
  915. qdf_nbuf_queue_add(&dp_soc->invalid_buf_queue,
  916. *rx_netbuf);
  917. }
  918. return QDF_STATUS_E_FAILURE;
  919. }
  920. #else
  921. static inline
  922. int dp_check_paddr(struct dp_soc *dp_soc,
  923. qdf_nbuf_t *rx_netbuf,
  924. qdf_dma_addr_t *paddr,
  925. struct rx_desc_pool *rx_desc_pool)
  926. {
  927. return QDF_STATUS_SUCCESS;
  928. }
  929. #endif
  930. /**
  931. * dp_rx_cookie_2_link_desc_va() - Converts cookie to a virtual address of
  932. * the MSDU Link Descriptor
  933. * @soc: core txrx main context
  934. * @buf_info: buf_info includes cookie that is used to lookup
  935. * virtual address of link descriptor after deriving the page id
  936. * and the offset or index of the desc on the associatde page.
  937. *
  938. * This is the VA of the link descriptor, that HAL layer later uses to
  939. * retrieve the list of MSDU's for a given MPDU.
  940. *
  941. * Return: void *: Virtual Address of the Rx descriptor
  942. */
  943. static inline
  944. void *dp_rx_cookie_2_link_desc_va(struct dp_soc *soc,
  945. struct hal_buf_info *buf_info)
  946. {
  947. void *link_desc_va;
  948. struct qdf_mem_multi_page_t *pages;
  949. uint16_t page_id = LINK_DESC_COOKIE_PAGE_ID(buf_info->sw_cookie);
  950. pages = &soc->link_desc_pages;
  951. if (!pages)
  952. return NULL;
  953. if (qdf_unlikely(page_id >= pages->num_pages))
  954. return NULL;
  955. link_desc_va = pages->dma_pages[page_id].page_v_addr_start +
  956. (buf_info->paddr - pages->dma_pages[page_id].page_p_addr);
  957. return link_desc_va;
  958. }
  959. /**
  960. * dp_rx_cookie_2_mon_link_desc_va() - Converts cookie to a virtual address of
  961. * the MSDU Link Descriptor
  962. * @pdev: core txrx pdev context
  963. * @buf_info: buf_info includes cookie that used to lookup virtual address of
  964. * link descriptor. Normally this is just an index into a per pdev array.
  965. *
  966. * This is the VA of the link descriptor in monitor mode destination ring,
  967. * that HAL layer later uses to retrieve the list of MSDU's for a given MPDU.
  968. *
  969. * Return: void *: Virtual Address of the Rx descriptor
  970. */
  971. static inline
  972. void *dp_rx_cookie_2_mon_link_desc_va(struct dp_pdev *pdev,
  973. struct hal_buf_info *buf_info,
  974. int mac_id)
  975. {
  976. void *link_desc_va;
  977. struct qdf_mem_multi_page_t *pages;
  978. uint16_t page_id = LINK_DESC_COOKIE_PAGE_ID(buf_info->sw_cookie);
  979. pages = &pdev->soc->mon_link_desc_pages[mac_id];
  980. if (!pages)
  981. return NULL;
  982. if (qdf_unlikely(page_id >= pages->num_pages))
  983. return NULL;
  984. link_desc_va = pages->dma_pages[page_id].page_v_addr_start +
  985. (buf_info->paddr - pages->dma_pages[page_id].page_p_addr);
  986. return link_desc_va;
  987. }
  988. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  989. /*
  990. * dp_rx_intrabss_fwd() - API for intrabss fwd. For EAPOL
  991. * pkt with DA not equal to vdev mac addr, fwd is not allowed.
  992. * @soc: core txrx main context
  993. * @ta_peer: source peer entry
  994. * @rx_tlv_hdr: start address of rx tlvs
  995. * @nbuf: nbuf that has to be intrabss forwarded
  996. * @msdu_metadata: msdu metadata
  997. *
  998. * Return: true if it is forwarded else false
  999. */
  1000. bool dp_rx_intrabss_fwd(struct dp_soc *soc,
  1001. struct dp_peer *ta_peer,
  1002. uint8_t *rx_tlv_hdr,
  1003. qdf_nbuf_t nbuf,
  1004. struct hal_rx_msdu_metadata msdu_metadata);
  1005. #ifdef DISABLE_EAPOL_INTRABSS_FWD
  1006. /*
  1007. * dp_rx_intrabss_fwd_wrapper() - Wrapper API for intrabss fwd. For EAPOL
  1008. * pkt with DA not equal to vdev mac addr, fwd is not allowed.
  1009. * @soc: core txrx main context
  1010. * @ta_peer: source peer entry
  1011. * @rx_tlv_hdr: start address of rx tlvs
  1012. * @nbuf: nbuf that has to be intrabss forwarded
  1013. * @msdu_metadata: msdu metadata
  1014. *
  1015. * Return: true if it is forwarded else false
  1016. */
  1017. static inline
  1018. bool dp_rx_intrabss_fwd_wrapper(struct dp_soc *soc, struct dp_peer *ta_peer,
  1019. uint8_t *rx_tlv_hdr, qdf_nbuf_t nbuf,
  1020. struct hal_rx_msdu_metadata msdu_metadata)
  1021. {
  1022. if (qdf_unlikely(qdf_nbuf_is_ipv4_eapol_pkt(nbuf) &&
  1023. qdf_mem_cmp(qdf_nbuf_data(nbuf) +
  1024. QDF_NBUF_DEST_MAC_OFFSET,
  1025. ta_peer->vdev->mac_addr.raw,
  1026. QDF_MAC_ADDR_SIZE))) {
  1027. qdf_nbuf_free(nbuf);
  1028. DP_STATS_INC(soc, rx.err.intrabss_eapol_drop, 1);
  1029. return true;
  1030. }
  1031. return dp_rx_intrabss_fwd(soc, ta_peer, rx_tlv_hdr, nbuf,
  1032. msdu_metadata);
  1033. }
  1034. #define DP_RX_INTRABSS_FWD(soc, peer, rx_tlv_hdr, nbuf, msdu_metadata) \
  1035. dp_rx_intrabss_fwd_wrapper(soc, peer, rx_tlv_hdr, nbuf, \
  1036. msdu_metadata)
  1037. #else /* DISABLE_EAPOL_INTRABSS_FWD */
  1038. #define DP_RX_INTRABSS_FWD(soc, peer, rx_tlv_hdr, nbuf, msdu_metadata) \
  1039. dp_rx_intrabss_fwd(soc, peer, rx_tlv_hdr, nbuf, msdu_metadata)
  1040. #endif /* DISABLE_EAPOL_INTRABSS_FWD */
  1041. /**
  1042. * dp_rx_defrag_concat() - Concatenate the fragments
  1043. *
  1044. * @dst: destination pointer to the buffer
  1045. * @src: source pointer from where the fragment payload is to be copied
  1046. *
  1047. * Return: QDF_STATUS
  1048. */
  1049. static inline QDF_STATUS dp_rx_defrag_concat(qdf_nbuf_t dst, qdf_nbuf_t src)
  1050. {
  1051. /*
  1052. * Inside qdf_nbuf_cat, if it is necessary to reallocate dst
  1053. * to provide space for src, the headroom portion is copied from
  1054. * the original dst buffer to the larger new dst buffer.
  1055. * (This is needed, because the headroom of the dst buffer
  1056. * contains the rx desc.)
  1057. */
  1058. if (!qdf_nbuf_cat(dst, src)) {
  1059. /*
  1060. * qdf_nbuf_cat does not free the src memory.
  1061. * Free src nbuf before returning
  1062. * For failure case the caller takes of freeing the nbuf
  1063. */
  1064. qdf_nbuf_free(src);
  1065. return QDF_STATUS_SUCCESS;
  1066. }
  1067. return QDF_STATUS_E_DEFRAG_ERROR;
  1068. }
  1069. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1070. #ifndef FEATURE_WDS
  1071. void dp_rx_da_learn(struct dp_soc *soc, uint8_t *rx_tlv_hdr,
  1072. struct dp_peer *ta_peer, qdf_nbuf_t nbuf);
  1073. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc, uint16_t sa_idx, bool is_active)
  1074. {
  1075. return QDF_STATUS_SUCCESS;
  1076. }
  1077. static inline void
  1078. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  1079. uint8_t *rx_tlv_hdr,
  1080. struct dp_peer *ta_peer,
  1081. qdf_nbuf_t nbuf,
  1082. struct hal_rx_msdu_metadata msdu_metadata)
  1083. {
  1084. }
  1085. #endif
  1086. /*
  1087. * dp_rx_desc_dump() - dump the sw rx descriptor
  1088. *
  1089. * @rx_desc: sw rx descriptor
  1090. */
  1091. static inline void dp_rx_desc_dump(struct dp_rx_desc *rx_desc)
  1092. {
  1093. dp_info("rx_desc->nbuf: %pK, rx_desc->cookie: %d, rx_desc->pool_id: %d, rx_desc->in_use: %d, rx_desc->unmapped: %d",
  1094. rx_desc->nbuf, rx_desc->cookie, rx_desc->pool_id,
  1095. rx_desc->in_use, rx_desc->unmapped);
  1096. }
  1097. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1098. /*
  1099. * check_qwrap_multicast_loopback() - Check if rx packet is a loopback packet.
  1100. * In qwrap mode, packets originated from
  1101. * any vdev should not loopback and
  1102. * should be dropped.
  1103. * @vdev: vdev on which rx packet is received
  1104. * @nbuf: rx pkt
  1105. *
  1106. */
  1107. #if ATH_SUPPORT_WRAP
  1108. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  1109. qdf_nbuf_t nbuf)
  1110. {
  1111. struct dp_vdev *psta_vdev;
  1112. struct dp_pdev *pdev = vdev->pdev;
  1113. uint8_t *data = qdf_nbuf_data(nbuf);
  1114. if (qdf_unlikely(vdev->proxysta_vdev)) {
  1115. /* In qwrap isolation mode, allow loopback packets as all
  1116. * packets go to RootAP and Loopback on the mpsta.
  1117. */
  1118. if (vdev->isolation_vdev)
  1119. return false;
  1120. TAILQ_FOREACH(psta_vdev, &pdev->vdev_list, vdev_list_elem) {
  1121. if (qdf_unlikely(psta_vdev->proxysta_vdev &&
  1122. !qdf_mem_cmp(psta_vdev->mac_addr.raw,
  1123. &data[QDF_MAC_ADDR_SIZE],
  1124. QDF_MAC_ADDR_SIZE))) {
  1125. /* Drop packet if source address is equal to
  1126. * any of the vdev addresses.
  1127. */
  1128. return true;
  1129. }
  1130. }
  1131. }
  1132. return false;
  1133. }
  1134. #else
  1135. static inline bool check_qwrap_multicast_loopback(struct dp_vdev *vdev,
  1136. qdf_nbuf_t nbuf)
  1137. {
  1138. return false;
  1139. }
  1140. #endif
  1141. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1142. #if defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) ||\
  1143. defined(WLAN_SUPPORT_RX_TAG_STATISTICS) ||\
  1144. defined(WLAN_SUPPORT_RX_FLOW_TAG)
  1145. #include "dp_rx_tag.h"
  1146. #endif
  1147. #ifndef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  1148. /**
  1149. * dp_rx_update_protocol_tag() - Reads CCE metadata from the RX MSDU end TLV
  1150. * and set the corresponding tag in QDF packet
  1151. * @soc: core txrx main context
  1152. * @vdev: vdev on which the packet is received
  1153. * @nbuf: QDF pkt buffer on which the protocol tag should be set
  1154. * @rx_tlv_hdr: rBbase address where the RX TLVs starts
  1155. * @ring_index: REO ring number, not used for error & monitor ring
  1156. * @is_reo_exception: flag to indicate if rx from REO ring or exception ring
  1157. * @is_update_stats: flag to indicate whether to update stats or not
  1158. * Return: void
  1159. */
  1160. static inline void
  1161. dp_rx_update_protocol_tag(struct dp_soc *soc, struct dp_vdev *vdev,
  1162. qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr,
  1163. uint16_t ring_index,
  1164. bool is_reo_exception, bool is_update_stats)
  1165. {
  1166. }
  1167. /**
  1168. * dp_rx_err_cce_drop() - Reads CCE metadata from the RX MSDU end TLV
  1169. * and returns whether cce metadata matches
  1170. * @soc: core txrx main context
  1171. * @vdev: vdev on which the packet is received
  1172. * @nbuf: QDF pkt buffer on which the protocol tag should be set
  1173. * @rx_tlv_hdr: rBbase address where the RX TLVs starts
  1174. * Return: bool
  1175. */
  1176. static inline bool
  1177. dp_rx_err_cce_drop(struct dp_soc *soc, struct dp_vdev *vdev,
  1178. qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr)
  1179. {
  1180. return false;
  1181. }
  1182. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  1183. #ifndef WLAN_SUPPORT_RX_FLOW_TAG
  1184. /**
  1185. * dp_rx_update_flow_tag() - Reads FSE metadata from the RX MSDU end TLV
  1186. * and set the corresponding tag in QDF packet
  1187. * @soc: core txrx main context
  1188. * @vdev: vdev on which the packet is received
  1189. * @nbuf: QDF pkt buffer on which the protocol tag should be set
  1190. * @rx_tlv_hdr: base address where the RX TLVs starts
  1191. * @is_update_stats: flag to indicate whether to update stats or not
  1192. *
  1193. * Return: void
  1194. */
  1195. static inline void
  1196. dp_rx_update_flow_tag(struct dp_soc *soc, struct dp_vdev *vdev,
  1197. qdf_nbuf_t nbuf, uint8_t *rx_tlv_hdr, bool update_stats)
  1198. {
  1199. }
  1200. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  1201. #if !defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) &&\
  1202. !defined(WLAN_SUPPORT_RX_FLOW_TAG)
  1203. /**
  1204. * dp_rx_mon_update_protocol_flow_tag() - Performs necessary checks for monitor
  1205. * mode and then tags appropriate packets
  1206. * @soc: core txrx main context
  1207. * @vdev: pdev on which packet is received
  1208. * @msdu: QDF packet buffer on which the protocol tag should be set
  1209. * @rx_desc: base address where the RX TLVs start
  1210. * Return: void
  1211. */
  1212. static inline
  1213. void dp_rx_mon_update_protocol_flow_tag(struct dp_soc *soc,
  1214. struct dp_pdev *dp_pdev,
  1215. qdf_nbuf_t msdu, void *rx_desc)
  1216. {
  1217. }
  1218. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG || WLAN_SUPPORT_RX_FLOW_TAG */
  1219. /*
  1220. * dp_rx_buffers_replenish() - replenish rxdma ring with rx nbufs
  1221. * called during dp rx initialization
  1222. * and at the end of dp_rx_process.
  1223. *
  1224. * @soc: core txrx main context
  1225. * @mac_id: mac_id which is one of 3 mac_ids
  1226. * @dp_rxdma_srng: dp rxdma circular ring
  1227. * @rx_desc_pool: Pointer to free Rx descriptor pool
  1228. * @num_req_buffers: number of buffer to be replenished
  1229. * @desc_list: list of descs if called from dp_rx_process
  1230. * or NULL during dp rx initialization or out of buffer
  1231. * interrupt.
  1232. * @tail: tail of descs list
  1233. * @func_name: name of the caller function
  1234. * Return: return success or failure
  1235. */
  1236. QDF_STATUS __dp_rx_buffers_replenish(struct dp_soc *dp_soc, uint32_t mac_id,
  1237. struct dp_srng *dp_rxdma_srng,
  1238. struct rx_desc_pool *rx_desc_pool,
  1239. uint32_t num_req_buffers,
  1240. union dp_rx_desc_list_elem_t **desc_list,
  1241. union dp_rx_desc_list_elem_t **tail,
  1242. const char *func_name);
  1243. /*
  1244. * dp_pdev_rx_buffers_attach() - replenish rxdma ring with rx nbufs
  1245. * called during dp rx initialization
  1246. *
  1247. * @soc: core txrx main context
  1248. * @mac_id: mac_id which is one of 3 mac_ids
  1249. * @dp_rxdma_srng: dp rxdma circular ring
  1250. * @rx_desc_pool: Pointer to free Rx descriptor pool
  1251. * @num_req_buffers: number of buffer to be replenished
  1252. *
  1253. * Return: return success or failure
  1254. */
  1255. QDF_STATUS
  1256. dp_pdev_rx_buffers_attach(struct dp_soc *dp_soc, uint32_t mac_id,
  1257. struct dp_srng *dp_rxdma_srng,
  1258. struct rx_desc_pool *rx_desc_pool,
  1259. uint32_t num_req_buffers);
  1260. /**
  1261. * dp_rx_link_desc_return() - Return a MPDU link descriptor to HW
  1262. * (WBM), following error handling
  1263. *
  1264. * @soc: core DP main context
  1265. * @buf_addr_info: opaque pointer to the REO error ring descriptor
  1266. * @buf_addr_info: void pointer to the buffer_addr_info
  1267. * @bm_action: put to idle_list or release to msdu_list
  1268. *
  1269. * Return: QDF_STATUS_E_FAILURE for failure else QDF_STATUS_SUCCESS
  1270. */
  1271. QDF_STATUS
  1272. dp_rx_link_desc_return(struct dp_soc *soc, hal_ring_desc_t ring_desc,
  1273. uint8_t bm_action);
  1274. /**
  1275. * dp_rx_link_desc_return_by_addr - Return a MPDU link descriptor to
  1276. * (WBM) by address
  1277. *
  1278. * @soc: core DP main context
  1279. * @link_desc_addr: link descriptor addr
  1280. *
  1281. * Return: QDF_STATUS_E_FAILURE for failure else QDF_STATUS_SUCCESS
  1282. */
  1283. QDF_STATUS
  1284. dp_rx_link_desc_return_by_addr(struct dp_soc *soc,
  1285. hal_buff_addrinfo_t link_desc_addr,
  1286. uint8_t bm_action);
  1287. /**
  1288. * dp_rxdma_err_process() - RxDMA error processing functionality
  1289. * @soc: core txrx main contex
  1290. * @mac_id: mac id which is one of 3 mac_ids
  1291. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  1292. * @quota: No. of units (packets) that can be serviced in one shot.
  1293. *
  1294. * Return: num of buffers processed
  1295. */
  1296. uint32_t
  1297. dp_rxdma_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  1298. uint32_t mac_id, uint32_t quota);
  1299. void dp_rx_fill_mesh_stats(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1300. uint8_t *rx_tlv_hdr, struct dp_peer *peer);
  1301. QDF_STATUS dp_rx_filter_mesh_packets(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1302. uint8_t *rx_tlv_hdr);
  1303. int dp_wds_rx_policy_check(uint8_t *rx_tlv_hdr, struct dp_vdev *vdev,
  1304. struct dp_peer *peer);
  1305. /*
  1306. * dp_rx_dump_info_and_assert() - dump RX Ring info and Rx Desc info
  1307. *
  1308. * @soc: core txrx main context
  1309. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  1310. * @ring_desc: opaque pointer to the RX ring descriptor
  1311. * @rx_desc: host rx descriptor
  1312. *
  1313. * Return: void
  1314. */
  1315. void dp_rx_dump_info_and_assert(struct dp_soc *soc,
  1316. hal_ring_handle_t hal_ring_hdl,
  1317. hal_ring_desc_t ring_desc,
  1318. struct dp_rx_desc *rx_desc);
  1319. void dp_rx_compute_delay(struct dp_vdev *vdev, qdf_nbuf_t nbuf);
  1320. #ifdef QCA_PEER_EXT_STATS
  1321. void dp_rx_compute_tid_delay(struct cdp_delay_tid_stats *stats,
  1322. qdf_nbuf_t nbuf);
  1323. #endif /* QCA_PEER_EXT_STATS */
  1324. #ifdef RX_DESC_DEBUG_CHECK
  1325. /**
  1326. * dp_rx_desc_check_magic() - check the magic value in dp_rx_desc
  1327. * @rx_desc: rx descriptor pointer
  1328. *
  1329. * Return: true, if magic is correct, else false.
  1330. */
  1331. static inline bool dp_rx_desc_check_magic(struct dp_rx_desc *rx_desc)
  1332. {
  1333. if (qdf_unlikely(rx_desc->magic != DP_RX_DESC_MAGIC))
  1334. return false;
  1335. rx_desc->magic = 0;
  1336. return true;
  1337. }
  1338. /**
  1339. * dp_rx_desc_prep() - prepare rx desc
  1340. * @rx_desc: rx descriptor pointer to be prepared
  1341. * @nbuf_frag_info_t: struct dp_rx_nbuf_frag_info *
  1342. *
  1343. * Note: assumption is that we are associating a nbuf which is mapped
  1344. *
  1345. * Return: none
  1346. */
  1347. static inline
  1348. void dp_rx_desc_prep(struct dp_rx_desc *rx_desc,
  1349. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1350. {
  1351. rx_desc->magic = DP_RX_DESC_MAGIC;
  1352. rx_desc->nbuf = (nbuf_frag_info_t->virt_addr).nbuf;
  1353. rx_desc->unmapped = 0;
  1354. rx_desc->nbuf_data_addr = (uint8_t *)qdf_nbuf_data(rx_desc->nbuf);
  1355. }
  1356. /**
  1357. * dp_rx_desc_frag_prep() - prepare rx desc
  1358. * @rx_desc: rx descriptor pointer to be prepared
  1359. * @nbuf_frag_info_t: struct dp_rx_nbuf_frag_info *
  1360. *
  1361. * Note: assumption is that we frag address is mapped
  1362. *
  1363. * Return: none
  1364. */
  1365. #ifdef DP_RX_MON_MEM_FRAG
  1366. static inline
  1367. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1368. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1369. {
  1370. rx_desc->magic = DP_RX_DESC_MAGIC;
  1371. rx_desc->rx_buf_start =
  1372. (uint8_t *)((nbuf_frag_info_t->virt_addr).vaddr);
  1373. rx_desc->paddr_buf_start = nbuf_frag_info_t->paddr;
  1374. rx_desc->unmapped = 0;
  1375. }
  1376. #else
  1377. static inline
  1378. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1379. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1380. {
  1381. }
  1382. #endif /* DP_RX_MON_MEM_FRAG */
  1383. /**
  1384. * dp_rx_desc_paddr_sanity_check() - paddr sanity for ring desc vs rx_desc
  1385. * @rx_desc: rx descriptor
  1386. * @ring_paddr: paddr obatined from the ring
  1387. *
  1388. * Returns: QDF_STATUS
  1389. */
  1390. static inline
  1391. bool dp_rx_desc_paddr_sanity_check(struct dp_rx_desc *rx_desc,
  1392. uint64_t ring_paddr)
  1393. {
  1394. return (ring_paddr == qdf_nbuf_get_frag_paddr(rx_desc->nbuf, 0));
  1395. }
  1396. #else
  1397. static inline bool dp_rx_desc_check_magic(struct dp_rx_desc *rx_desc)
  1398. {
  1399. return true;
  1400. }
  1401. static inline
  1402. void dp_rx_desc_prep(struct dp_rx_desc *rx_desc,
  1403. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1404. {
  1405. rx_desc->nbuf = (nbuf_frag_info_t->virt_addr).nbuf;
  1406. rx_desc->unmapped = 0;
  1407. }
  1408. #ifdef DP_RX_MON_MEM_FRAG
  1409. static inline
  1410. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1411. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1412. {
  1413. rx_desc->rx_buf_start =
  1414. (uint8_t *)((nbuf_frag_info_t->virt_addr).vaddr);
  1415. rx_desc->paddr_buf_start = nbuf_frag_info_t->paddr;
  1416. rx_desc->unmapped = 0;
  1417. }
  1418. #else
  1419. static inline
  1420. void dp_rx_desc_frag_prep(struct dp_rx_desc *rx_desc,
  1421. struct dp_rx_nbuf_frag_info *nbuf_frag_info_t)
  1422. {
  1423. }
  1424. #endif /* DP_RX_MON_MEM_FRAG */
  1425. static inline
  1426. bool dp_rx_desc_paddr_sanity_check(struct dp_rx_desc *rx_desc,
  1427. uint64_t ring_paddr)
  1428. {
  1429. return true;
  1430. }
  1431. #endif /* RX_DESC_DEBUG_CHECK */
  1432. void dp_rx_enable_mon_dest_frag(struct rx_desc_pool *rx_desc_pool,
  1433. bool is_mon_dest_desc);
  1434. void dp_rx_process_rxdma_err(struct dp_soc *soc, qdf_nbuf_t nbuf,
  1435. uint8_t *rx_tlv_hdr, struct dp_peer *peer,
  1436. uint8_t err_code, uint8_t mac_id);
  1437. #ifndef QCA_MULTIPASS_SUPPORT
  1438. static inline
  1439. bool dp_rx_multipass_process(struct dp_peer *peer, qdf_nbuf_t nbuf, uint8_t tid)
  1440. {
  1441. return false;
  1442. }
  1443. #else
  1444. bool dp_rx_multipass_process(struct dp_peer *peer, qdf_nbuf_t nbuf,
  1445. uint8_t tid);
  1446. #endif
  1447. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1448. #ifndef WLAN_RX_PKT_CAPTURE_ENH
  1449. static inline
  1450. QDF_STATUS dp_peer_set_rx_capture_enabled(struct dp_pdev *pdev,
  1451. struct dp_peer *peer_handle,
  1452. bool value, uint8_t *mac_addr)
  1453. {
  1454. return QDF_STATUS_SUCCESS;
  1455. }
  1456. #endif
  1457. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1458. /**
  1459. * dp_rx_deliver_to_stack() - deliver pkts to network stack
  1460. * Caller to hold peer refcount and check for valid peer
  1461. * @soc: soc
  1462. * @vdev: vdev
  1463. * @peer: peer
  1464. * @nbuf_head: skb list head
  1465. * @nbuf_tail: skb list tail
  1466. *
  1467. * Return: None
  1468. */
  1469. void dp_rx_deliver_to_stack(struct dp_soc *soc,
  1470. struct dp_vdev *vdev,
  1471. struct dp_peer *peer,
  1472. qdf_nbuf_t nbuf_head,
  1473. qdf_nbuf_t nbuf_tail);
  1474. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1475. #ifdef QCA_OL_RX_LOCK_LESS_ACCESS
  1476. /*
  1477. * dp_rx_ring_access_start()- Wrapper function to log access start of a hal ring
  1478. * @int_ctx: pointer to DP interrupt context
  1479. * @dp_soc - DP soc structure pointer
  1480. * @hal_ring_hdl - HAL ring handle
  1481. *
  1482. * Return: 0 on success; error on failure
  1483. */
  1484. static inline int
  1485. dp_rx_srng_access_start(struct dp_intr *int_ctx, struct dp_soc *soc,
  1486. hal_ring_handle_t hal_ring_hdl)
  1487. {
  1488. return hal_srng_access_start_unlocked(soc->hal_soc, hal_ring_hdl);
  1489. }
  1490. /*
  1491. * dp_rx_ring_access_end()- Wrapper function to log access end of a hal ring
  1492. * @int_ctx: pointer to DP interrupt context
  1493. * @dp_soc - DP soc structure pointer
  1494. * @hal_ring_hdl - HAL ring handle
  1495. *
  1496. * Return - None
  1497. */
  1498. static inline void
  1499. dp_rx_srng_access_end(struct dp_intr *int_ctx, struct dp_soc *soc,
  1500. hal_ring_handle_t hal_ring_hdl)
  1501. {
  1502. hal_srng_access_end_unlocked(soc->hal_soc, hal_ring_hdl);
  1503. }
  1504. #else
  1505. static inline int
  1506. dp_rx_srng_access_start(struct dp_intr *int_ctx, struct dp_soc *soc,
  1507. hal_ring_handle_t hal_ring_hdl)
  1508. {
  1509. return dp_srng_access_start(int_ctx, soc, hal_ring_hdl);
  1510. }
  1511. static inline void
  1512. dp_rx_srng_access_end(struct dp_intr *int_ctx, struct dp_soc *soc,
  1513. hal_ring_handle_t hal_ring_hdl)
  1514. {
  1515. dp_srng_access_end(int_ctx, soc, hal_ring_hdl);
  1516. }
  1517. #endif
  1518. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1519. /*
  1520. * dp_rx_wbm_sg_list_reset() - Initialize sg list
  1521. *
  1522. * This api should be called at soc init and afterevery sg processing.
  1523. *@soc: DP SOC handle
  1524. */
  1525. static inline void dp_rx_wbm_sg_list_reset(struct dp_soc *soc)
  1526. {
  1527. if (soc) {
  1528. soc->wbm_sg_param.wbm_is_first_msdu_in_sg = false;
  1529. soc->wbm_sg_param.wbm_sg_nbuf_head = NULL;
  1530. soc->wbm_sg_param.wbm_sg_nbuf_tail = NULL;
  1531. soc->wbm_sg_param.wbm_sg_desc_msdu_len = 0;
  1532. }
  1533. }
  1534. /*
  1535. * dp_rx_wbm_sg_list_deinit() - De-initialize sg list
  1536. *
  1537. * This api should be called in down path, to avoid any leak.
  1538. *@soc: DP SOC handle
  1539. */
  1540. static inline void dp_rx_wbm_sg_list_deinit(struct dp_soc *soc)
  1541. {
  1542. if (soc) {
  1543. if (soc->wbm_sg_param.wbm_sg_nbuf_head)
  1544. qdf_nbuf_list_free(soc->wbm_sg_param.wbm_sg_nbuf_head);
  1545. dp_rx_wbm_sg_list_reset(soc);
  1546. }
  1547. }
  1548. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1549. #ifdef WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL
  1550. #define DP_RX_PROCESS_NBUF(soc, head, tail, ebuf_head, ebuf_tail, rx_desc) \
  1551. do { \
  1552. if (!soc->rx_buff_pool[rx_desc->pool_id].is_initialized) { \
  1553. DP_RX_LIST_APPEND(head, tail, rx_desc->nbuf); \
  1554. break; \
  1555. } \
  1556. DP_RX_LIST_APPEND(ebuf_head, ebuf_tail, rx_desc->nbuf); \
  1557. if (!qdf_nbuf_is_rx_chfrag_cont(rx_desc->nbuf)) { \
  1558. if (!dp_rx_buffer_pool_refill(soc, ebuf_head, \
  1559. rx_desc->pool_id)) \
  1560. DP_RX_MERGE_TWO_LIST(head, tail, \
  1561. ebuf_head, ebuf_tail);\
  1562. ebuf_head = NULL; \
  1563. ebuf_tail = NULL; \
  1564. } \
  1565. } while (0)
  1566. #else
  1567. #define DP_RX_PROCESS_NBUF(soc, head, tail, ebuf_head, ebuf_tail, rx_desc) \
  1568. DP_RX_LIST_APPEND(head, tail, rx_desc->nbuf)
  1569. #endif /* WLAN_FEATURE_RX_PREALLOC_BUFFER_POOL */
  1570. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1571. /*
  1572. * dp_rx_link_desc_refill_duplicate_check() - check if link desc duplicate
  1573. to refill
  1574. * @soc: DP SOC handle
  1575. * @buf_info: the last link desc buf info
  1576. * @ring_buf_info: current buf address pointor including link desc
  1577. *
  1578. * return: none.
  1579. */
  1580. void dp_rx_link_desc_refill_duplicate_check(
  1581. struct dp_soc *soc,
  1582. struct hal_buf_info *buf_info,
  1583. hal_buff_addrinfo_t ring_buf_info);
  1584. #ifdef WLAN_FEATURE_PKT_CAPTURE_V2
  1585. /**
  1586. * dp_rx_deliver_to_pkt_capture() - deliver rx packet to packet capture
  1587. * @soc : dp_soc handle
  1588. * @pdev: dp_pdev handle
  1589. * @peer_id: peer_id of the peer for which completion came
  1590. * @ppdu_id: ppdu_id
  1591. * @netbuf: Buffer pointer
  1592. *
  1593. * This function is used to deliver rx packet to packet capture
  1594. */
  1595. void dp_rx_deliver_to_pkt_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  1596. uint16_t peer_id, uint32_t is_offload,
  1597. qdf_nbuf_t netbuf);
  1598. void dp_rx_deliver_to_pkt_capture_no_peer(struct dp_soc *soc, qdf_nbuf_t nbuf,
  1599. uint32_t is_offload);
  1600. #else
  1601. static inline void
  1602. dp_rx_deliver_to_pkt_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  1603. uint16_t peer_id, uint32_t is_offload,
  1604. qdf_nbuf_t netbuf)
  1605. {
  1606. }
  1607. static inline void
  1608. dp_rx_deliver_to_pkt_capture_no_peer(struct dp_soc *soc, qdf_nbuf_t nbuf,
  1609. uint32_t is_offload)
  1610. {
  1611. }
  1612. #endif
  1613. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1614. #ifdef FEATURE_MEC
  1615. /**
  1616. * dp_rx_mcast_echo_check() - check if the mcast pkt is a loop
  1617. * back on same vap or a different vap.
  1618. * @soc: core DP main context
  1619. * @peer: dp peer handler
  1620. * @rx_tlv_hdr: start of the rx TLV header
  1621. * @nbuf: pkt buffer
  1622. *
  1623. * Return: bool (true if it is a looped back pkt else false)
  1624. *
  1625. */
  1626. bool dp_rx_mcast_echo_check(struct dp_soc *soc,
  1627. struct dp_peer *peer,
  1628. uint8_t *rx_tlv_hdr,
  1629. qdf_nbuf_t nbuf);
  1630. #else
  1631. static inline bool dp_rx_mcast_echo_check(struct dp_soc *soc,
  1632. struct dp_peer *peer,
  1633. uint8_t *rx_tlv_hdr,
  1634. qdf_nbuf_t nbuf)
  1635. {
  1636. return false;
  1637. }
  1638. #endif /* FEATURE_MEC */
  1639. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1640. #ifdef RECEIVE_OFFLOAD
  1641. void dp_rx_fill_gro_info(struct dp_soc *soc, uint8_t *rx_tlv,
  1642. qdf_nbuf_t msdu, uint32_t *rx_ol_pkt_cnt);
  1643. #else
  1644. static inline
  1645. void dp_rx_fill_gro_info(struct dp_soc *soc, uint8_t *rx_tlv,
  1646. qdf_nbuf_t msdu, uint32_t *rx_ol_pkt_cnt)
  1647. {
  1648. }
  1649. #endif
  1650. void dp_rx_msdu_stats_update(struct dp_soc *soc, qdf_nbuf_t nbuf,
  1651. uint8_t *rx_tlv_hdr, struct dp_peer *peer,
  1652. uint8_t ring_id,
  1653. struct cdp_tid_rx_stats *tid_stats);
  1654. void dp_rx_deliver_to_stack_no_peer(struct dp_soc *soc, qdf_nbuf_t nbuf);
  1655. uint32_t dp_rx_srng_get_num_pending(hal_soc_handle_t hal_soc,
  1656. hal_ring_handle_t hal_ring_hdl,
  1657. uint32_t num_entries,
  1658. bool *near_full);
  1659. #ifdef WLAN_FEATURE_DP_RX_RING_HISTORY
  1660. void dp_rx_ring_record_entry(struct dp_soc *soc, uint8_t ring_num,
  1661. hal_ring_desc_t ring_desc);
  1662. #else
  1663. static inline void
  1664. dp_rx_ring_record_entry(struct dp_soc *soc, uint8_t ring_num,
  1665. hal_ring_desc_t ring_desc)
  1666. {
  1667. }
  1668. #endif
  1669. #ifndef QCA_HOST_MODE_WIFI_DISABLED
  1670. #ifdef RX_DESC_SANITY_WAR
  1671. QDF_STATUS dp_rx_desc_sanity(struct dp_soc *soc, hal_soc_handle_t hal_soc,
  1672. hal_ring_handle_t hal_ring_hdl,
  1673. hal_ring_desc_t ring_desc,
  1674. struct dp_rx_desc *rx_desc);
  1675. #else
  1676. static inline
  1677. QDF_STATUS dp_rx_desc_sanity(struct dp_soc *soc, hal_soc_handle_t hal_soc,
  1678. hal_ring_handle_t hal_ring_hdl,
  1679. hal_ring_desc_t ring_desc,
  1680. struct dp_rx_desc *rx_desc)
  1681. {
  1682. return QDF_STATUS_SUCCESS;
  1683. }
  1684. #endif
  1685. #ifdef DP_RX_DROP_RAW_FRM
  1686. bool dp_rx_is_raw_frame_dropped(qdf_nbuf_t nbuf);
  1687. #else
  1688. static inline
  1689. bool dp_rx_is_raw_frame_dropped(qdf_nbuf_t nbuf)
  1690. {
  1691. return false;
  1692. }
  1693. #endif
  1694. #ifdef RX_DESC_DEBUG_CHECK
  1695. QDF_STATUS dp_rx_desc_nbuf_sanity_check(struct dp_soc *soc,
  1696. hal_ring_desc_t ring_desc,
  1697. struct dp_rx_desc *rx_desc);
  1698. #else
  1699. static inline
  1700. QDF_STATUS dp_rx_desc_nbuf_sanity_check(struct dp_soc *soc,
  1701. hal_ring_desc_t ring_desc,
  1702. struct dp_rx_desc *rx_desc)
  1703. {
  1704. return QDF_STATUS_SUCCESS;
  1705. }
  1706. #endif
  1707. #ifdef WLAN_DP_FEATURE_SW_LATENCY_MGR
  1708. void dp_rx_update_stats(struct dp_soc *soc, qdf_nbuf_t nbuf);
  1709. #else
  1710. static inline
  1711. void dp_rx_update_stats(struct dp_soc *soc, qdf_nbuf_t nbuf)
  1712. {
  1713. }
  1714. #endif
  1715. /**
  1716. * dp_rx_cksum_offload() - set the nbuf checksum as defined by hardware.
  1717. * @nbuf: pointer to the first msdu of an amsdu.
  1718. * @rx_tlv_hdr: pointer to the start of RX TLV headers.
  1719. *
  1720. * The ipsumed field of the skb is set based on whether HW validated the
  1721. * IP/TCP/UDP checksum.
  1722. *
  1723. * Return: void
  1724. */
  1725. static inline
  1726. void dp_rx_cksum_offload(struct dp_pdev *pdev,
  1727. qdf_nbuf_t nbuf,
  1728. uint8_t *rx_tlv_hdr)
  1729. {
  1730. qdf_nbuf_rx_cksum_t cksum = {0};
  1731. //TODO - Move this to ring desc api
  1732. //HAL_RX_MSDU_DESC_IP_CHKSUM_FAIL_GET
  1733. //HAL_RX_MSDU_DESC_TCP_UDP_CHKSUM_FAIL_GET
  1734. uint32_t ip_csum_err, tcp_udp_csum_er;
  1735. hal_rx_tlv_csum_err_get(pdev->soc->hal_soc, rx_tlv_hdr, &ip_csum_err,
  1736. &tcp_udp_csum_er);
  1737. if (qdf_likely(!ip_csum_err && !tcp_udp_csum_er)) {
  1738. cksum.l4_result = QDF_NBUF_RX_CKSUM_TCP_UDP_UNNECESSARY;
  1739. qdf_nbuf_set_rx_cksum(nbuf, &cksum);
  1740. } else {
  1741. DP_STATS_INCC(pdev, err.ip_csum_err, 1, ip_csum_err);
  1742. DP_STATS_INCC(pdev, err.tcp_udp_csum_err, 1, tcp_udp_csum_er);
  1743. }
  1744. }
  1745. #endif /* QCA_HOST_MODE_WIFI_DISABLED */
  1746. #ifdef WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT
  1747. static inline
  1748. bool dp_rx_reap_loop_pkt_limit_hit(struct dp_soc *soc, int num_reaped,
  1749. int max_reap_limit)
  1750. {
  1751. bool limit_hit = false;
  1752. limit_hit =
  1753. (num_reaped >= max_reap_limit) ? true : false;
  1754. if (limit_hit)
  1755. DP_STATS_INC(soc, rx.reap_loop_pkt_limit_hit, 1)
  1756. return limit_hit;
  1757. }
  1758. static inline
  1759. bool dp_rx_enable_eol_data_check(struct dp_soc *soc)
  1760. {
  1761. return soc->wlan_cfg_ctx->rx_enable_eol_data_check;
  1762. }
  1763. static inline int dp_rx_get_loop_pkt_limit(struct dp_soc *soc)
  1764. {
  1765. struct wlan_cfg_dp_soc_ctxt *cfg = soc->wlan_cfg_ctx;
  1766. return cfg->rx_reap_loop_pkt_limit;
  1767. }
  1768. #else
  1769. static inline
  1770. bool dp_rx_reap_loop_pkt_limit_hit(struct dp_soc *soc, int num_reaped,
  1771. int max_reap_limit)
  1772. {
  1773. return false;
  1774. }
  1775. static inline
  1776. bool dp_rx_enable_eol_data_check(struct dp_soc *soc)
  1777. {
  1778. return false;
  1779. }
  1780. static inline int dp_rx_get_loop_pkt_limit(struct dp_soc *soc)
  1781. {
  1782. return 0;
  1783. }
  1784. #endif /* WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT */
  1785. void dp_rx_update_stats(struct dp_soc *soc, qdf_nbuf_t nbuf);
  1786. #ifdef QCA_SUPPORT_WDS_EXTENDED
  1787. /**
  1788. * dp_rx_is_list_ready() - Make different lists for 4-address
  1789. and 3-address frames
  1790. * @nbuf_head: skb list head
  1791. * @vdev: vdev
  1792. * @peer: peer
  1793. * @peer_id: peer id of new received frame
  1794. * @vdev_id: vdev_id of new received frame
  1795. *
  1796. * Return: true if peer_ids are different.
  1797. */
  1798. static inline bool
  1799. dp_rx_is_list_ready(qdf_nbuf_t nbuf_head,
  1800. struct dp_vdev *vdev,
  1801. struct dp_peer *peer,
  1802. uint16_t peer_id,
  1803. uint8_t vdev_id)
  1804. {
  1805. if (nbuf_head && peer && (peer->peer_id != peer_id))
  1806. return true;
  1807. return false;
  1808. }
  1809. #else
  1810. static inline bool
  1811. dp_rx_is_list_ready(qdf_nbuf_t nbuf_head,
  1812. struct dp_vdev *vdev,
  1813. struct dp_peer *peer,
  1814. uint16_t peer_id,
  1815. uint8_t vdev_id)
  1816. {
  1817. if (nbuf_head && vdev && (vdev->vdev_id != vdev_id))
  1818. return true;
  1819. return false;
  1820. }
  1821. #endif
  1822. /**
  1823. * dp_rx_desc_pool_init_generic() - Generic Rx descriptors initialization
  1824. * @soc: SOC handle
  1825. * @rx_desc_pool: pointer to RX descriptor pool
  1826. * @pool_id: pool ID
  1827. *
  1828. * Return: None
  1829. */
  1830. QDF_STATUS dp_rx_desc_pool_init_generic(struct dp_soc *soc,
  1831. struct rx_desc_pool *rx_desc_pool,
  1832. uint32_t pool_id);
  1833. void dp_rx_desc_pool_deinit_generic(struct dp_soc *soc,
  1834. struct rx_desc_pool *rx_desc_pool,
  1835. uint32_t pool_id);
  1836. #endif /* _DP_RX_H */