dp_peer.c 33 KB

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