dp_peer.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. /*
  2. * Copyright (c) 2016-2017 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 "dp_htt.h"
  21. #include "dp_types.h"
  22. #include "dp_internal.h"
  23. #include "dp_peer.h"
  24. #include <hal_api.h>
  25. /* Temporary definitions to be moved to wlan_cfg */
  26. static inline uint32_t wlan_cfg_max_peer_id(void *wlan_cfg_ctx)
  27. {
  28. /* TODO: This should be calculated based on target capabilities */
  29. return 2048;
  30. }
  31. static inline int dp_peer_find_mac_addr_cmp(
  32. union dp_align_mac_addr *mac_addr1,
  33. union dp_align_mac_addr *mac_addr2)
  34. {
  35. return !((mac_addr1->align4.bytes_abcd == mac_addr2->align4.bytes_abcd)
  36. /*
  37. * Intentionally use & rather than &&.
  38. * because the operands are binary rather than generic boolean,
  39. * the functionality is equivalent.
  40. * Using && has the advantage of short-circuited evaluation,
  41. * but using & has the advantage of no conditional branching,
  42. * which is a more significant benefit.
  43. */
  44. &
  45. (mac_addr1->align4.bytes_ef == mac_addr2->align4.bytes_ef));
  46. }
  47. static int dp_peer_find_map_attach(struct dp_soc *soc)
  48. {
  49. uint32_t max_peers, peer_map_size;
  50. /* allocate the peer ID -> peer object map */
  51. max_peers = wlan_cfg_max_peer_id(soc->wlan_cfg_ctx) + 1;
  52. soc->max_peers = max_peers;
  53. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  54. "\n<=== cfg max peer id %d ====>\n", max_peers);
  55. peer_map_size = max_peers * sizeof(soc->peer_id_to_obj_map[0]);
  56. soc->peer_id_to_obj_map = qdf_mem_malloc(peer_map_size);
  57. if (!soc->peer_id_to_obj_map) {
  58. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  59. "%s: peer map memory allocation failed\n", __func__);
  60. return QDF_STATUS_E_NOMEM;
  61. }
  62. /*
  63. * The peer_id_to_obj_map doesn't really need to be initialized,
  64. * since elements are only used after they have been individually
  65. * initialized.
  66. * However, it is convenient for debugging to have all elements
  67. * that are not in use set to 0.
  68. */
  69. qdf_mem_zero(soc->peer_id_to_obj_map, peer_map_size);
  70. #ifdef notyet /* ATH_BAND_STEERING */
  71. OS_INIT_TIMER(soc->osdev, &(soc->bs_inact_timer),
  72. dp_peer_find_inact_timeout_handler, (void *)soc,
  73. QDF_TIMER_TYPE_WAKE_APPS);
  74. #endif
  75. return 0; /* success */
  76. }
  77. static int dp_log2_ceil(unsigned value)
  78. {
  79. unsigned tmp = value;
  80. int log2 = -1;
  81. while (tmp) {
  82. log2++;
  83. tmp >>= 1;
  84. }
  85. if (1 << log2 != value)
  86. log2++;
  87. return log2;
  88. }
  89. static int dp_peer_find_add_id_to_obj(
  90. struct dp_peer *peer,
  91. uint16_t peer_id)
  92. {
  93. int i;
  94. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++) {
  95. if (peer->peer_ids[i] == HTT_INVALID_PEER) {
  96. peer->peer_ids[i] = peer_id;
  97. return 0; /* success */
  98. }
  99. }
  100. return QDF_STATUS_E_FAILURE; /* failure */
  101. }
  102. #define DP_PEER_HASH_LOAD_MULT 2
  103. #define DP_PEER_HASH_LOAD_SHIFT 0
  104. static int dp_peer_find_hash_attach(struct dp_soc *soc)
  105. {
  106. int i, hash_elems, log2;
  107. /* allocate the peer MAC address -> peer object hash table */
  108. hash_elems = wlan_cfg_max_peer_id(soc->wlan_cfg_ctx) + 1;
  109. hash_elems *= DP_PEER_HASH_LOAD_MULT;
  110. hash_elems >>= DP_PEER_HASH_LOAD_SHIFT;
  111. log2 = dp_log2_ceil(hash_elems);
  112. hash_elems = 1 << log2;
  113. soc->peer_hash.mask = hash_elems - 1;
  114. soc->peer_hash.idx_bits = log2;
  115. /* allocate an array of TAILQ peer object lists */
  116. soc->peer_hash.bins = qdf_mem_malloc(
  117. hash_elems * sizeof(TAILQ_HEAD(anonymous_tail_q, dp_peer)));
  118. if (!soc->peer_hash.bins)
  119. return QDF_STATUS_E_NOMEM;
  120. for (i = 0; i < hash_elems; i++)
  121. TAILQ_INIT(&soc->peer_hash.bins[i]);
  122. return 0;
  123. }
  124. static void dp_peer_find_hash_detach(struct dp_soc *soc)
  125. {
  126. qdf_mem_free(soc->peer_hash.bins);
  127. }
  128. static inline unsigned dp_peer_find_hash_index(struct dp_soc *soc,
  129. union dp_align_mac_addr *mac_addr)
  130. {
  131. unsigned index;
  132. index =
  133. mac_addr->align2.bytes_ab ^
  134. mac_addr->align2.bytes_cd ^
  135. mac_addr->align2.bytes_ef;
  136. index ^= index >> soc->peer_hash.idx_bits;
  137. index &= soc->peer_hash.mask;
  138. return index;
  139. }
  140. void dp_peer_find_hash_add(struct dp_soc *soc, struct dp_peer *peer)
  141. {
  142. unsigned index;
  143. index = dp_peer_find_hash_index(soc, &peer->mac_addr);
  144. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  145. /*
  146. * It is important to add the new peer at the tail of the peer list
  147. * with the bin index. Together with having the hash_find function
  148. * search from head to tail, this ensures that if two entries with
  149. * the same MAC address are stored, the one added first will be
  150. * found first.
  151. */
  152. TAILQ_INSERT_TAIL(&soc->peer_hash.bins[index], peer, hash_list_elem);
  153. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  154. }
  155. #if ATH_SUPPORT_WRAP
  156. struct dp_peer *dp_peer_find_hash_find(struct dp_soc *soc,
  157. uint8_t *peer_mac_addr, int mac_addr_is_aligned, uint8_t vdev_id)
  158. #else
  159. struct dp_peer *dp_peer_find_hash_find(struct dp_soc *soc,
  160. uint8_t *peer_mac_addr, int mac_addr_is_aligned)
  161. #endif
  162. {
  163. union dp_align_mac_addr local_mac_addr_aligned, *mac_addr;
  164. unsigned index;
  165. struct dp_peer *peer;
  166. if (mac_addr_is_aligned) {
  167. mac_addr = (union dp_align_mac_addr *) peer_mac_addr;
  168. } else {
  169. qdf_mem_copy(
  170. &local_mac_addr_aligned.raw[0],
  171. peer_mac_addr, DP_MAC_ADDR_LEN);
  172. mac_addr = &local_mac_addr_aligned;
  173. }
  174. index = dp_peer_find_hash_index(soc, mac_addr);
  175. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  176. TAILQ_FOREACH(peer, &soc->peer_hash.bins[index], hash_list_elem) {
  177. #if ATH_SUPPORT_WRAP
  178. /* ProxySTA may have multiple BSS peer with same MAC address,
  179. * modified find will take care of finding the correct BSS peer.
  180. */
  181. if (dp_peer_find_mac_addr_cmp(mac_addr, &peer->mac_addr) == 0 &&
  182. (peer->vdev->vdev_id == vdev_id)) {
  183. #else
  184. if (dp_peer_find_mac_addr_cmp(mac_addr, &peer->mac_addr) == 0) {
  185. #endif
  186. /* found it - increment the ref count before releasing
  187. * the lock
  188. */
  189. qdf_atomic_inc(&peer->ref_cnt);
  190. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  191. return peer;
  192. }
  193. }
  194. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  195. return NULL; /* failure */
  196. }
  197. void dp_peer_find_hash_remove(struct dp_soc *soc, struct dp_peer *peer)
  198. {
  199. unsigned index;
  200. struct dp_peer *tmppeer = NULL;
  201. int found = 0;
  202. index = dp_peer_find_hash_index(soc, &peer->mac_addr);
  203. /* Check if tail is not empty before delete*/
  204. QDF_ASSERT(!TAILQ_EMPTY(&soc->peer_hash.bins[index]));
  205. /*
  206. * DO NOT take the peer_ref_mutex lock here - it needs to be taken
  207. * by the caller.
  208. * The caller needs to hold the lock from the time the peer object's
  209. * reference count is decremented and tested up through the time the
  210. * reference to the peer object is removed from the hash table, by
  211. * this function.
  212. * Holding the lock only while removing the peer object reference
  213. * from the hash table keeps the hash table consistent, but does not
  214. * protect against a new HL tx context starting to use the peer object
  215. * if it looks up the peer object from its MAC address just after the
  216. * peer ref count is decremented to zero, but just before the peer
  217. * object reference is removed from the hash table.
  218. */
  219. TAILQ_FOREACH(tmppeer, &soc->peer_hash.bins[index], hash_list_elem) {
  220. if (tmppeer == peer) {
  221. found = 1;
  222. break;
  223. }
  224. }
  225. QDF_ASSERT(found);
  226. TAILQ_REMOVE(&soc->peer_hash.bins[index], peer, hash_list_elem);
  227. }
  228. void dp_peer_find_hash_erase(struct dp_soc *soc)
  229. {
  230. int i;
  231. /*
  232. * Not really necessary to take peer_ref_mutex lock - by this point,
  233. * it's known that the soc is no longer in use.
  234. */
  235. for (i = 0; i <= soc->peer_hash.mask; i++) {
  236. if (!TAILQ_EMPTY(&soc->peer_hash.bins[i])) {
  237. struct dp_peer *peer, *peer_next;
  238. /*
  239. * TAILQ_FOREACH_SAFE must be used here to avoid any
  240. * memory access violation after peer is freed
  241. */
  242. TAILQ_FOREACH_SAFE(peer, &soc->peer_hash.bins[i],
  243. hash_list_elem, peer_next) {
  244. /*
  245. * Don't remove the peer from the hash table -
  246. * that would modify the list we are currently
  247. * traversing, and it's not necessary anyway.
  248. */
  249. /*
  250. * Artificially adjust the peer's ref count to
  251. * 1, so it will get deleted by
  252. * dp_peer_unref_delete.
  253. */
  254. /* set to zero */
  255. qdf_atomic_init(&peer->ref_cnt);
  256. /* incr to one */
  257. qdf_atomic_inc(&peer->ref_cnt);
  258. dp_peer_unref_delete(peer);
  259. }
  260. }
  261. }
  262. }
  263. static void dp_peer_find_map_detach(struct dp_soc *soc)
  264. {
  265. #ifdef notyet /* ATH_BAND_STEERING */
  266. OS_FREE_TIMER(&(soc->bs_inact_timer));
  267. #endif
  268. qdf_mem_free(soc->peer_id_to_obj_map);
  269. }
  270. int dp_peer_find_attach(struct dp_soc *soc)
  271. {
  272. if (dp_peer_find_map_attach(soc))
  273. return 1;
  274. if (dp_peer_find_hash_attach(soc)) {
  275. dp_peer_find_map_detach(soc);
  276. return 1;
  277. }
  278. return 0; /* success */
  279. }
  280. static inline void dp_peer_find_add_id(struct dp_soc *soc,
  281. uint8_t *peer_mac_addr, uint16_t peer_id, uint8_t vdev_id)
  282. {
  283. struct dp_peer *peer;
  284. QDF_ASSERT(peer_id <= wlan_cfg_max_peer_id(soc->wlan_cfg_ctx) + 1);
  285. /* check if there's already a peer object with this MAC address */
  286. #if ATH_SUPPORT_WRAP
  287. peer = dp_peer_find_hash_find(soc, peer_mac_addr,
  288. 0 /* is aligned */, vdev_id);
  289. #else
  290. peer = dp_peer_find_hash_find(soc, peer_mac_addr, 0 /* is aligned */);
  291. #endif
  292. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  293. "%s: peer %p ID %d vid %d mac %02x:%02x:%02x:%02x:%02x:%02x\n",
  294. __func__, peer, peer_id, vdev_id, peer_mac_addr[0],
  295. peer_mac_addr[1], peer_mac_addr[2], peer_mac_addr[3],
  296. peer_mac_addr[4], peer_mac_addr[5]);
  297. if (peer) {
  298. /* peer's ref count was already incremented by
  299. * peer_find_hash_find
  300. */
  301. soc->peer_id_to_obj_map[peer_id] = peer;
  302. if (dp_peer_find_add_id_to_obj(peer, peer_id)) {
  303. /* TBDXXX: assert for now */
  304. QDF_ASSERT(0);
  305. }
  306. return;
  307. }
  308. }
  309. void
  310. dp_rx_peer_map_handler(void *soc_handle, uint16_t peer_id, uint8_t vdev_id,
  311. uint8_t *peer_mac_addr)
  312. {
  313. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  314. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  315. "peer_map_event (soc:%p): peer_id %d, peer_mac "
  316. "%02x:%02x:%02x:%02x:%02x:%02x, vdev_id %d\n", soc, peer_id,
  317. peer_mac_addr[0], peer_mac_addr[1], peer_mac_addr[2],
  318. peer_mac_addr[3], peer_mac_addr[4], peer_mac_addr[5], vdev_id);
  319. dp_peer_find_add_id(soc, peer_mac_addr, peer_id, vdev_id);
  320. }
  321. void
  322. dp_rx_peer_unmap_handler(void *soc_handle, uint16_t peer_id)
  323. {
  324. struct dp_peer *peer;
  325. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  326. uint8_t i;
  327. peer = dp_peer_find_by_id(soc, peer_id);
  328. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  329. "peer_unmap_event (soc:%p) peer_id %d peer %p\n",
  330. soc, peer_id, peer);
  331. /*
  332. * Currently peer IDs are assigned for vdevs as well as peers.
  333. * If the peer ID is for a vdev, then the peer pointer stored
  334. * in peer_id_to_obj_map will be NULL.
  335. */
  336. if (!peer)
  337. return;
  338. soc->peer_id_to_obj_map[peer_id] = NULL;
  339. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++) {
  340. if (peer->peer_ids[i] == peer_id) {
  341. peer->peer_ids[i] = HTT_INVALID_PEER;
  342. break;
  343. }
  344. }
  345. /*
  346. * Remove a reference to the peer.
  347. * If there are no more references, delete the peer object.
  348. */
  349. dp_peer_unref_delete(peer);
  350. }
  351. void
  352. dp_peer_find_detach(struct dp_soc *soc)
  353. {
  354. dp_peer_find_map_detach(soc);
  355. dp_peer_find_hash_detach(soc);
  356. }
  357. /*
  358. * dp_find_peer_by_addr - find peer instance by mac address
  359. * @dev: physical device instance
  360. * @peer_mac_addr: peer mac address
  361. * @local_id: local id for the peer
  362. *
  363. * Return: peer instance pointer
  364. */
  365. void *dp_find_peer_by_addr(void *dev, uint8_t *peer_mac_addr,
  366. uint8_t *local_id)
  367. {
  368. struct dp_pdev *pdev = dev;
  369. struct dp_peer *peer;
  370. #if ATH_SUPPORT_WRAP
  371. peer = dp_peer_find_hash_find(pdev->soc, peer_mac_addr, 0, 0);
  372. /* WAR, VDEV ID? TEMP 0 */
  373. #else
  374. peer = dp_peer_find_hash_find(pdev->soc, peer_mac_addr, 0);
  375. #endif
  376. if (!peer)
  377. return NULL;
  378. /* Multiple peer ids? How can know peer id? */
  379. *local_id = peer->local_id;
  380. DP_TRACE(INFO, "%s: peer %p id %d", __func__, peer, *local_id);
  381. return peer;
  382. }
  383. /*
  384. * dp_rx_tid_update_wifi3() – Update receive TID state
  385. * @peer: Datapath peer handle
  386. * @tid: TID
  387. * @ba_window_size: BlockAck window size
  388. * @start_seq: Starting sequence number
  389. *
  390. * Return: 0 on success, error code on failure
  391. */
  392. int dp_rx_tid_update_wifi3(struct dp_peer *peer, int tid, uint32_t
  393. ba_window_size, uint32_t start_seq)
  394. {
  395. /* TODO: Implement this once REO command API is available */
  396. return 0;
  397. }
  398. /*
  399. * dp_rx_tid_setup_wifi3() – Setup receive TID state
  400. * @peer: Datapath peer handle
  401. * @tid: TID
  402. * @ba_window_size: BlockAck window size
  403. * @start_seq: Starting sequence number
  404. *
  405. * Return: 0 on success, error code on failure
  406. */
  407. int dp_rx_tid_setup_wifi3(struct dp_peer *peer, int tid,
  408. uint32_t ba_window_size, uint32_t start_seq)
  409. {
  410. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  411. struct dp_vdev *vdev = peer->vdev;
  412. struct dp_soc *soc = vdev->pdev->soc;
  413. uint32_t hw_qdesc_size;
  414. uint32_t hw_qdesc_align;
  415. int hal_pn_type;
  416. void *hw_qdesc_vaddr;
  417. if (rx_tid->hw_qdesc_vaddr_unaligned != NULL)
  418. return dp_rx_tid_update_wifi3(peer, tid, ba_window_size,
  419. start_seq);
  420. #ifdef notyet
  421. hw_qdesc_size = hal_get_reo_qdesc_size(soc->hal_soc, ba_window_size);
  422. #else
  423. /* TODO: Allocating HW queue descriptors based on max BA window size
  424. * for all QOS TIDs so that same descriptor can be used later when
  425. * ADDBA request is recevied. This should be changed to allocate HW
  426. * queue descriptors based on BA window size being negotiated (0 for
  427. * non BA cases), and reallocate when BA window size changes and also
  428. * send WMI message to FW to change the REO queue descriptor in Rx
  429. * peer entry as part of dp_rx_tid_update.
  430. */
  431. if (tid != DP_NON_QOS_TID)
  432. hw_qdesc_size = hal_get_reo_qdesc_size(soc->hal_soc,
  433. HAL_RX_MAX_BA_WINDOW);
  434. else
  435. hw_qdesc_size = hal_get_reo_qdesc_size(soc->hal_soc,
  436. ba_window_size);
  437. #endif
  438. hw_qdesc_align = hal_get_reo_qdesc_align(soc->hal_soc);
  439. /* To avoid unnecessary extra allocation for alignment, try allocating
  440. * exact size and see if we already have aligned address.
  441. */
  442. rx_tid->hw_qdesc_alloc_size = hw_qdesc_size;
  443. rx_tid->hw_qdesc_vaddr_unaligned = qdf_mem_alloc_consistent(
  444. soc->osdev, soc->osdev->dev, rx_tid->hw_qdesc_alloc_size,
  445. &(rx_tid->hw_qdesc_paddr_unaligned));
  446. if (!rx_tid->hw_qdesc_vaddr_unaligned) {
  447. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  448. "%s: Rx tid HW desc alloc failed: tid %d\n",
  449. __func__, tid);
  450. return QDF_STATUS_E_NOMEM;
  451. }
  452. if ((unsigned long)(rx_tid->hw_qdesc_vaddr_unaligned) %
  453. hw_qdesc_align) {
  454. /* Address allocated above is not alinged. Allocate extra
  455. * memory for alignment
  456. */
  457. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  458. rx_tid->hw_qdesc_alloc_size,
  459. rx_tid->hw_qdesc_vaddr_unaligned,
  460. rx_tid->hw_qdesc_paddr_unaligned, 0);
  461. rx_tid->hw_qdesc_alloc_size =
  462. hw_qdesc_size + hw_qdesc_align - 1;
  463. rx_tid->hw_qdesc_vaddr_unaligned = qdf_mem_alloc_consistent(
  464. soc->osdev, soc->osdev->dev, rx_tid->hw_qdesc_alloc_size,
  465. &(rx_tid->hw_qdesc_paddr_unaligned));
  466. if (!rx_tid->hw_qdesc_vaddr_unaligned) {
  467. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  468. "%s: Rx tid HW desc alloc failed: tid %d\n",
  469. __func__, tid);
  470. return QDF_STATUS_E_NOMEM;
  471. }
  472. hw_qdesc_vaddr = rx_tid->hw_qdesc_vaddr_unaligned +
  473. ((unsigned long)(rx_tid->hw_qdesc_vaddr_unaligned) %
  474. hw_qdesc_align);
  475. rx_tid->hw_qdesc_paddr = rx_tid->hw_qdesc_paddr_unaligned +
  476. ((unsigned long)hw_qdesc_vaddr -
  477. (unsigned long)(rx_tid->hw_qdesc_vaddr_unaligned));
  478. } else {
  479. hw_qdesc_vaddr = rx_tid->hw_qdesc_vaddr_unaligned;
  480. rx_tid->hw_qdesc_paddr = rx_tid->hw_qdesc_paddr_unaligned;
  481. }
  482. /* TODO: Ensure that sec_type is set before ADDBA is received.
  483. * Currently this is set based on htt indication
  484. * HTT_T2H_MSG_TYPE_SEC_IND from target
  485. */
  486. switch (peer->security[dp_sec_ucast].sec_type) {
  487. case htt_sec_type_tkip_nomic:
  488. case htt_sec_type_aes_ccmp:
  489. case htt_sec_type_aes_ccmp_256:
  490. case htt_sec_type_aes_gcmp:
  491. case htt_sec_type_aes_gcmp_256:
  492. hal_pn_type = HAL_PN_WPA;
  493. break;
  494. case htt_sec_type_wapi:
  495. if (vdev->opmode == wlan_op_mode_ap)
  496. hal_pn_type = HAL_PN_WAPI_EVEN;
  497. else
  498. hal_pn_type = HAL_PN_WAPI_UNEVEN;
  499. break;
  500. default:
  501. hal_pn_type = HAL_PN_NONE;
  502. break;
  503. }
  504. hal_reo_qdesc_setup(soc->hal_soc, tid, ba_window_size, start_seq,
  505. hw_qdesc_vaddr, rx_tid->hw_qdesc_paddr, hal_pn_type);
  506. if (soc->cdp_soc.ol_ops->peer_rx_reorder_queue_setup) {
  507. soc->cdp_soc.ol_ops->peer_rx_reorder_queue_setup(soc->osif_soc,
  508. peer->vdev->vdev_id, peer->mac_addr.raw,
  509. rx_tid->hw_qdesc_paddr, tid, tid);
  510. if (tid == DP_NON_QOS_TID) {
  511. /* TODO: Setting up default queue - currently using
  512. * same queue for BE and non-qos traffic till BA
  513. * session is setup. Check if there are any HW
  514. * restrictions and also if this can be done for
  515. * all other TIDs
  516. */
  517. soc->cdp_soc.ol_ops->
  518. peer_rx_reorder_queue_setup(soc->osif_soc,
  519. peer->vdev->vdev_id, peer->mac_addr.raw,
  520. rx_tid->hw_qdesc_paddr, 0, tid);
  521. }
  522. }
  523. return 0;
  524. }
  525. /*
  526. * Rx TID deletion callback to free memory allocated for HW queue descriptor
  527. */
  528. void dp_rx_tid_delete_cb(struct dp_pdev *pdev, void *cb_ctxt, int status)
  529. {
  530. struct dp_soc *soc = pdev->soc;
  531. struct dp_rx_tid *rx_tid = (struct dp_rx_tid *)cb_ctxt;
  532. if (status) {
  533. /* Should not happen normally. Just print error for now */
  534. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  535. "%s: Rx tid HW desc deletion failed: tid %d\n",
  536. __func__, rx_tid->tid);
  537. }
  538. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  539. rx_tid->hw_qdesc_alloc_size,
  540. rx_tid->hw_qdesc_vaddr_unaligned,
  541. rx_tid->hw_qdesc_paddr_unaligned, 0);
  542. rx_tid->hw_qdesc_vaddr_unaligned = NULL;
  543. rx_tid->hw_qdesc_alloc_size = 0;
  544. }
  545. /*
  546. * dp_rx_tid_delete_wifi3() – Delete receive TID queue
  547. * @peer: Datapath peer handle
  548. * @tid: TID
  549. *
  550. * Return: 0 on success, error code on failure
  551. */
  552. int dp_rx_tid_delete_wifi3(struct dp_peer *peer, int tid)
  553. {
  554. #ifdef notyet /* TBD: Enable this once REO command interface is available */
  555. struct dp_rx_tid *rx_tid = peer->rx_tid[tid];
  556. dp_rx_tid_hw_update_valid(rx_tid->hw_qdesc_paddr, 0,
  557. dp_rx_tid_delete_cb, (void *)rx_tid);
  558. #endif
  559. return 0;
  560. }
  561. /*
  562. * dp_peer_rx_init() – Initialize receive TID state
  563. * @pdev: Datapath pdev
  564. * @peer: Datapath peer
  565. *
  566. */
  567. void dp_peer_rx_init(struct dp_pdev *pdev, struct dp_peer *peer)
  568. {
  569. int tid;
  570. struct dp_rx_tid *rx_tid;
  571. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  572. rx_tid = &peer->rx_tid[tid];
  573. rx_tid->array = &rx_tid->base;
  574. rx_tid->base.head = rx_tid->base.tail = NULL;
  575. rx_tid->tid = tid;
  576. rx_tid->defrag_timeout_ms = 0;
  577. rx_tid->ba_win_size = 0;
  578. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  579. rx_tid->defrag_waitlist_elem.tqe_next = NULL;
  580. rx_tid->defrag_waitlist_elem.tqe_prev = NULL;
  581. #ifdef notyet /* TODO: See if this is required for exception handling */
  582. /* invalid sequence number */
  583. peer->tids_last_seq[tid] = 0xffff;
  584. #endif
  585. }
  586. /* Setup default (non-qos) rx tid queue */
  587. dp_rx_tid_setup_wifi3(peer, DP_NON_QOS_TID, 1, 0);
  588. /*
  589. * Set security defaults: no PN check, no security. The target may
  590. * send a HTT SEC_IND message to overwrite these defaults.
  591. */
  592. peer->security[dp_sec_ucast].sec_type =
  593. peer->security[dp_sec_mcast].sec_type = htt_sec_type_none;
  594. }
  595. /*
  596. * dp_peer_rx_cleanup() – Cleanup receive TID state
  597. * @vdev: Datapath vdev
  598. * @peer: Datapath peer
  599. *
  600. */
  601. void dp_peer_rx_cleanup(struct dp_vdev *vdev, struct dp_peer *peer)
  602. {
  603. int tid;
  604. struct dp_rx_tid *rx_tid;
  605. uint32_t tid_delete_mask = 0;
  606. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  607. if (rx_tid->hw_qdesc_vaddr_unaligned != NULL) {
  608. dp_rx_tid_delete_wifi3(peer, tid);
  609. tid_delete_mask |= (1 << tid);
  610. }
  611. }
  612. #ifdef notyet /* See if FW can remove queues as part of peer cleanup */
  613. if (soc->ol_ops->peer_rx_reorder_queue_remove) {
  614. soc->ol_ops->peer_rx_reorder_queue_remove(soc->osif_soc,
  615. peer->vdev->vdev_id, peer->mac_addr.raw,
  616. tid_delete_mask);
  617. }
  618. #endif
  619. }
  620. /*
  621. * dp_rx_addba_requestprocess_wifi3() – Process ADDBA request from peer
  622. *
  623. * @peer: Datapath peer handle
  624. * @dialogtoken: dialogtoken from ADDBA frame
  625. * @tid: TID number
  626. * @startseqnum: Start seq. number received in BA sequence control
  627. * in ADDBA frame
  628. *
  629. * Return: 0 on success, error code on failure
  630. */
  631. int dp_addba_requestprocess_wifi3(void *peer_handle,
  632. uint8_t dialogtoken, uint16_t tid, uint16_t batimeout,
  633. uint16_t buffersize, uint16_t startseqnum)
  634. {
  635. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  636. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  637. if ((rx_tid->ba_status == DP_RX_BA_ACTIVE) &&
  638. (rx_tid->hw_qdesc_vaddr_unaligned != NULL))
  639. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  640. if (dp_rx_tid_setup_wifi3(peer, tid, buffersize,
  641. startseqnum)) {
  642. /* TODO: Should we send addba reject in this case */
  643. return QDF_STATUS_E_FAILURE;
  644. }
  645. rx_tid->ba_win_size = buffersize;
  646. rx_tid->dialogtoken = dialogtoken;
  647. rx_tid->statuscode = QDF_STATUS_SUCCESS;
  648. rx_tid->ba_status = DP_RX_BA_ACTIVE;
  649. return 0;
  650. }
  651. /*
  652. * dp_rx_addba_responsesetup_wifi3() – Process ADDBA request from peer
  653. *
  654. * @peer: Datapath peer handle
  655. * @tid: TID number
  656. * @dialogtoken: output dialogtoken
  657. * @statuscode: output dialogtoken
  658. * @buffersize: Ouput BA window sizze
  659. * @batimeout: Ouput BA timeout
  660. */
  661. void dp_addba_responsesetup_wifi3(void *peer_handle, uint8_t tid,
  662. uint8_t *dialogtoken, uint16_t *statuscode,
  663. uint16_t *buffersize, uint16_t *batimeout)
  664. {
  665. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  666. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  667. /* setup ADDBA response paramters */
  668. *dialogtoken = rx_tid->dialogtoken;
  669. *statuscode = rx_tid->statuscode;
  670. *buffersize = rx_tid->ba_win_size;
  671. *batimeout = 0;
  672. }
  673. /*
  674. * dp_rx_delba_process_wifi3() – Process DELBA from peer
  675. * @peer: Datapath peer handle
  676. * @tid: TID number
  677. * @reasoncode: Reason code received in DELBA frame
  678. *
  679. * Return: 0 on success, error code on failure
  680. */
  681. int dp_delba_process_wifi3(void *peer_handle,
  682. int tid, uint16_t reasoncode)
  683. {
  684. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  685. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  686. if (rx_tid->ba_status != DP_RX_BA_ACTIVE)
  687. return QDF_STATUS_E_FAILURE;
  688. /* TODO: See if we can delete the existing REO queue descriptor and
  689. * replace with a new one without queue extenstion descript to save
  690. * memory
  691. */
  692. dp_rx_tid_update_wifi3(peer, tid, 0, 0);
  693. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  694. return 0;
  695. }
  696. void dp_rx_discard(struct dp_vdev *vdev, struct dp_peer *peer, unsigned tid,
  697. qdf_nbuf_t msdu_list)
  698. {
  699. while (msdu_list) {
  700. qdf_nbuf_t msdu = msdu_list;
  701. msdu_list = qdf_nbuf_next(msdu_list);
  702. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  703. "discard rx %p from partly-deleted peer %p "
  704. "(%02x:%02x:%02x:%02x:%02x:%02x)\n",
  705. msdu, peer,
  706. peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  707. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  708. peer->mac_addr.raw[4], peer->mac_addr.raw[5]);
  709. qdf_nbuf_free(msdu);
  710. }
  711. }
  712. void
  713. dp_rx_sec_ind_handler(void *soc_handle, uint16_t peer_id,
  714. enum htt_sec_type sec_type, int is_unicast, u_int32_t *michael_key,
  715. u_int32_t *rx_pn)
  716. {
  717. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  718. struct dp_peer *peer;
  719. int sec_index;
  720. peer = dp_peer_find_by_id(soc, peer_id);
  721. if (!peer) {
  722. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  723. "Couldn't find peer from ID %d - skipping security inits\n",
  724. peer_id);
  725. return;
  726. }
  727. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  728. "sec spec for peer %p (%02x:%02x:%02x:%02x:%02x:%02x): "
  729. "%s key of type %d\n",
  730. peer,
  731. peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  732. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  733. peer->mac_addr.raw[4], peer->mac_addr.raw[5],
  734. is_unicast ? "ucast" : "mcast",
  735. sec_type);
  736. sec_index = is_unicast ? dp_sec_ucast : dp_sec_mcast;
  737. peer->security[sec_index].sec_type = sec_type;
  738. #ifdef notyet /* TODO: See if this is required for defrag support */
  739. /* michael key only valid for TKIP, but for simplicity,
  740. * copy it anyway
  741. */
  742. qdf_mem_copy(
  743. &peer->security[sec_index].michael_key[0],
  744. michael_key,
  745. sizeof(peer->security[sec_index].michael_key));
  746. #ifdef BIG_ENDIAN_HOST
  747. OL_IF_SWAPBO(peer->security[sec_index].michael_key[0],
  748. sizeof(peer->security[sec_index].michael_key));
  749. #endif /* BIG_ENDIAN_HOST */
  750. #endif
  751. #ifdef notyet /* TODO: Check if this is required for wifi3.0 */
  752. if (sec_type != htt_sec_type_wapi) {
  753. qdf_mem_set(peer->tids_last_pn_valid, _EXT_TIDS, 0x00);
  754. } else {
  755. for (i = 0; i < DP_MAX_TIDS; i++) {
  756. /*
  757. * Setting PN valid bit for WAPI sec_type,
  758. * since WAPI PN has to be started with predefined value
  759. */
  760. peer->tids_last_pn_valid[i] = 1;
  761. qdf_mem_copy(
  762. (u_int8_t *) &peer->tids_last_pn[i],
  763. (u_int8_t *) rx_pn, sizeof(union htt_rx_pn_t));
  764. peer->tids_last_pn[i].pn128[1] =
  765. qdf_cpu_to_le64(peer->tids_last_pn[i].pn128[1]);
  766. peer->tids_last_pn[i].pn128[0] =
  767. qdf_cpu_to_le64(peer->tids_last_pn[i].pn128[0]);
  768. }
  769. }
  770. #endif
  771. /* TODO: Update HW TID queue with PN check parameters (pn type for
  772. * all security types and last pn for WAPI) once REO command API
  773. * is available
  774. */
  775. }
  776. #ifndef CONFIG_WIN
  777. /**
  778. * dp_register_peer() - Register peer into physical device
  779. * @pdev - data path device instance
  780. * @sta_desc - peer description
  781. *
  782. * Register peer into physical device
  783. *
  784. * Return: QDF_STATUS_SUCCESS registration success
  785. * QDF_STATUS_E_FAULT peer not found
  786. */
  787. QDF_STATUS dp_register_peer(void *pdev_handle,
  788. struct ol_txrx_desc_type *sta_desc)
  789. {
  790. struct dp_peer *peer;
  791. struct dp_pdev *pdev = pdev_handle;
  792. peer = dp_peer_find_by_local_id(pdev, sta_desc->sta_id);
  793. if (!peer)
  794. return QDF_STATUS_E_FAULT;
  795. qdf_spin_lock_bh(&peer->peer_info_lock);
  796. peer->state = OL_TXRX_PEER_STATE_CONN;
  797. qdf_spin_unlock_bh(&peer->peer_info_lock);
  798. return QDF_STATUS_SUCCESS;
  799. }
  800. /**
  801. * dp_clear_peer() - remove peer from physical device
  802. * @pdev - data path device instance
  803. * @sta_id - local peer id
  804. *
  805. * remove peer from physical device
  806. *
  807. * Return: QDF_STATUS_SUCCESS registration success
  808. * QDF_STATUS_E_FAULT peer not found
  809. */
  810. QDF_STATUS dp_clear_peer(void *pdev_handle, uint8_t local_id)
  811. {
  812. struct dp_peer *peer;
  813. struct dp_pdev *pdev = pdev_handle;
  814. peer = dp_peer_find_by_local_id(pdev, local_id);
  815. if (!peer)
  816. return QDF_STATUS_E_FAULT;
  817. qdf_spin_lock_bh(&peer->peer_info_lock);
  818. peer->state = OL_TXRX_PEER_STATE_DISC;
  819. qdf_spin_unlock_bh(&peer->peer_info_lock);
  820. return QDF_STATUS_SUCCESS;
  821. }
  822. /**
  823. * dp_find_peer_by_addr_and_vdev() - Find peer by peer mac address within vdev
  824. * @pdev - data path device instance
  825. * @vdev - virtual interface instance
  826. * @peer_addr - peer mac address
  827. * @peer_id - local peer id with target mac address
  828. *
  829. * Find peer by peer mac address within vdev
  830. *
  831. * Return: peer instance void pointer
  832. * NULL cannot find target peer
  833. */
  834. void *dp_find_peer_by_addr_and_vdev(void *pdev_handle, void *vdev,
  835. uint8_t *peer_addr, uint8_t *local_id)
  836. {
  837. struct dp_pdev *pdev = pdev_handle;
  838. struct dp_peer *peer;
  839. DP_TRACE(INFO, "vdev %p peer_addr %p", vdev, peer_addr);
  840. peer = dp_peer_find_hash_find(pdev->soc, peer_addr, 0);
  841. DP_TRACE(INFO, "peer %p vdev %p", peer, vdev);
  842. if (!peer)
  843. return NULL;
  844. if (peer->vdev != vdev)
  845. return NULL;
  846. *local_id = peer->local_id;
  847. DP_TRACE(INFO, "peer %p vdev %p lcoal id %d",
  848. peer, vdev, *local_id);
  849. return peer;
  850. }
  851. /**
  852. * dp_local_peer_id() - Find local peer id within peer instance
  853. * @peer - peer instance
  854. *
  855. * Find local peer id within peer instance
  856. *
  857. * Return: local peer id
  858. */
  859. uint16_t dp_local_peer_id(void *peer)
  860. {
  861. return ((struct dp_peer *)peer)->local_id;
  862. }
  863. /**
  864. * dp_peer_find_by_local_id() - Find peer by local peer id
  865. * @pdev - data path device instance
  866. * @local_peer_id - local peer id want to find
  867. *
  868. * Find peer by local peer id within physical device
  869. *
  870. * Return: peer instance void pointer
  871. * NULL cannot find target peer
  872. */
  873. void *dp_peer_find_by_local_id(void *pdev_handle, uint8_t local_id)
  874. {
  875. struct dp_peer *peer;
  876. struct dp_pdev *pdev = pdev_handle;
  877. qdf_spin_lock_bh(&pdev->local_peer_ids.lock);
  878. peer = pdev->local_peer_ids.map[local_id];
  879. qdf_spin_unlock_bh(&pdev->local_peer_ids.lock);
  880. DP_TRACE(INFO, "peer %p lcoal id %d",
  881. peer, local_id);
  882. return peer;
  883. }
  884. /**
  885. * dp_peer_state_update() - update peer local state
  886. * @pdev - data path device instance
  887. * @peer_addr - peer mac address
  888. * @state - new peer local state
  889. *
  890. * update peer local state
  891. *
  892. * Return: QDF_STATUS_SUCCESS registration success
  893. */
  894. QDF_STATUS dp_peer_state_update(void *pdev_handle, uint8_t *peer_mac,
  895. enum ol_txrx_peer_state state)
  896. {
  897. struct dp_peer *peer;
  898. struct dp_pdev *pdev = pdev_handle;
  899. peer = dp_peer_find_hash_find(pdev->soc, peer_mac, 0);
  900. if (NULL == peer) {
  901. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  902. "Failed to find peer for: [%pM]", peer_mac);
  903. return QDF_STATUS_E_FAILURE;
  904. }
  905. peer->state = state;
  906. DP_TRACE(INFO, "peer %p state %d",
  907. peer, peer->state);
  908. return QDF_STATUS_SUCCESS;
  909. }
  910. /**
  911. * dp_get_vdevid() - Get virtaul interface id which peer registered
  912. * @peer - peer instance
  913. * @vdev_id - virtaul interface id which peer registered
  914. *
  915. * Get virtaul interface id which peer registered
  916. *
  917. * Return: QDF_STATUS_SUCCESS registration success
  918. */
  919. QDF_STATUS dp_get_vdevid(void *peer_handle, uint8_t *vdev_id)
  920. {
  921. struct dp_peer *peer = peer_handle;
  922. DP_TRACE(INFO, "peer %p vdev %p vdev id %d",
  923. peer, peer->vdev, peer->vdev->vdev_id);
  924. *vdev_id = peer->vdev->vdev_id;
  925. return QDF_STATUS_SUCCESS;
  926. }
  927. /**
  928. * dp_get_vdev_for_peer() - Get virtual interface instance which peer belongs
  929. * @peer - peer instance
  930. *
  931. * Get virtual interface instance which peer belongs
  932. *
  933. * Return: virtual interface instance pointer
  934. * NULL in case cannot find
  935. */
  936. void *dp_get_vdev_for_peer(void *peer_handle)
  937. {
  938. struct dp_peer *peer = peer_handle;
  939. DP_TRACE(INFO, "peer %p vdev %p", peer, peer->vdev);
  940. return (void *)peer->vdev;
  941. }
  942. /**
  943. * dp_peer_get_peer_mac_addr() - Get peer mac address
  944. * @peer - peer instance
  945. *
  946. * Get peer mac address
  947. *
  948. * Return: peer mac address pointer
  949. * NULL in case cannot find
  950. */
  951. uint8_t *dp_peer_get_peer_mac_addr(void *peer_handle)
  952. {
  953. struct dp_peer *peer = peer_handle;
  954. uint8_t *mac;
  955. mac = peer->mac_addr.raw;
  956. DP_TRACE(INFO, "peer %p mac 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
  957. peer, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  958. return peer->mac_addr.raw;
  959. }
  960. /**
  961. * dp_get_peer_state() - Get local peer state
  962. * @peer - peer instance
  963. *
  964. * Get local peer state
  965. *
  966. * Return: peer status
  967. */
  968. int dp_get_peer_state(void *peer_handle)
  969. {
  970. struct dp_peer *peer = peer_handle;
  971. DP_TRACE(INFO, "peer %p stats %d", peer, peer->state);
  972. return peer->state;
  973. }
  974. /**
  975. * dp_local_peer_id_pool_init() - local peer id pool alloc for physical device
  976. * @pdev - data path device instance
  977. *
  978. * local peer id pool alloc for physical device
  979. *
  980. * Return: none
  981. */
  982. void dp_local_peer_id_pool_init(struct dp_pdev *pdev)
  983. {
  984. int i;
  985. /* point the freelist to the first ID */
  986. pdev->local_peer_ids.freelist = 0;
  987. /* link each ID to the next one */
  988. for (i = 0; i < OL_TXRX_NUM_LOCAL_PEER_IDS; i++) {
  989. pdev->local_peer_ids.pool[i] = i + 1;
  990. pdev->local_peer_ids.map[i] = NULL;
  991. }
  992. /* link the last ID to itself, to mark the end of the list */
  993. i = OL_TXRX_NUM_LOCAL_PEER_IDS;
  994. pdev->local_peer_ids.pool[i] = i;
  995. qdf_spinlock_create(&pdev->local_peer_ids.lock);
  996. DP_TRACE(INFO, "Peer pool init");
  997. }
  998. /**
  999. * dp_local_peer_id_alloc() - allocate local peer id
  1000. * @pdev - data path device instance
  1001. * @peer - new peer instance
  1002. *
  1003. * allocate local peer id
  1004. *
  1005. * Return: none
  1006. */
  1007. void dp_local_peer_id_alloc(struct dp_pdev *pdev, struct dp_peer *peer)
  1008. {
  1009. int i;
  1010. qdf_spin_lock_bh(&pdev->local_peer_ids.lock);
  1011. i = pdev->local_peer_ids.freelist;
  1012. if (pdev->local_peer_ids.pool[i] == i) {
  1013. /* the list is empty, except for the list-end marker */
  1014. peer->local_id = OL_TXRX_INVALID_LOCAL_PEER_ID;
  1015. } else {
  1016. /* take the head ID and advance the freelist */
  1017. peer->local_id = i;
  1018. pdev->local_peer_ids.freelist = pdev->local_peer_ids.pool[i];
  1019. pdev->local_peer_ids.map[i] = peer;
  1020. }
  1021. qdf_spin_unlock_bh(&pdev->local_peer_ids.lock);
  1022. DP_TRACE(INFO, "peer %p, local id %d", peer, peer->local_id);
  1023. }
  1024. /**
  1025. * dp_local_peer_id_free() - remove local peer id
  1026. * @pdev - data path device instance
  1027. * @peer - peer instance should be removed
  1028. *
  1029. * remove local peer id
  1030. *
  1031. * Return: none
  1032. */
  1033. void dp_local_peer_id_free(struct dp_pdev *pdev, struct dp_peer *peer)
  1034. {
  1035. int i = peer->local_id;
  1036. if ((i == OL_TXRX_INVALID_LOCAL_PEER_ID) ||
  1037. (i >= OL_TXRX_NUM_LOCAL_PEER_IDS)) {
  1038. return;
  1039. }
  1040. /* put this ID on the head of the freelist */
  1041. qdf_spin_lock_bh(&pdev->local_peer_ids.lock);
  1042. pdev->local_peer_ids.pool[i] = pdev->local_peer_ids.freelist;
  1043. pdev->local_peer_ids.freelist = i;
  1044. pdev->local_peer_ids.map[i] = NULL;
  1045. qdf_spin_unlock_bh(&pdev->local_peer_ids.lock);
  1046. }
  1047. #endif