dp_peer.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  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. static 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. static 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. static 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. static 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. #ifdef notyet /* TBD: Enable this once REO command interface is available */
  526. /*
  527. * Rx TID deletion callback to free memory allocated for HW queue descriptor
  528. */
  529. static void dp_rx_tid_delete_cb(struct dp_pdev *pdev, void *cb_ctxt, int status)
  530. {
  531. struct dp_soc *soc = pdev->soc;
  532. struct dp_rx_tid *rx_tid = (struct dp_rx_tid *)cb_ctxt;
  533. if (status) {
  534. /* Should not happen normally. Just print error for now */
  535. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  536. "%s: Rx tid HW desc deletion failed: tid %d\n",
  537. __func__, rx_tid->tid);
  538. }
  539. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  540. rx_tid->hw_qdesc_alloc_size,
  541. rx_tid->hw_qdesc_vaddr_unaligned,
  542. rx_tid->hw_qdesc_paddr_unaligned, 0);
  543. rx_tid->hw_qdesc_vaddr_unaligned = NULL;
  544. rx_tid->hw_qdesc_alloc_size = 0;
  545. }
  546. /*
  547. * dp_rx_tid_delete_wifi3() – Delete receive TID queue
  548. * @peer: Datapath peer handle
  549. * @tid: TID
  550. *
  551. * Return: 0 on success, error code on failure
  552. */
  553. static int dp_rx_tid_delete_wifi3(struct dp_peer *peer, int tid)
  554. {
  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. return 0;
  559. }
  560. #else
  561. static int dp_rx_tid_delete_wifi3(struct dp_peer *peer, int tid)
  562. {
  563. return 0;
  564. }
  565. #endif
  566. /*
  567. * dp_peer_rx_init() – Initialize receive TID state
  568. * @pdev: Datapath pdev
  569. * @peer: Datapath peer
  570. *
  571. */
  572. void dp_peer_rx_init(struct dp_pdev *pdev, struct dp_peer *peer)
  573. {
  574. int tid;
  575. struct dp_rx_tid *rx_tid;
  576. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  577. rx_tid = &peer->rx_tid[tid];
  578. rx_tid->array = &rx_tid->base;
  579. rx_tid->base.head = rx_tid->base.tail = NULL;
  580. rx_tid->tid = tid;
  581. rx_tid->defrag_timeout_ms = 0;
  582. rx_tid->ba_win_size = 0;
  583. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  584. rx_tid->defrag_waitlist_elem.tqe_next = NULL;
  585. rx_tid->defrag_waitlist_elem.tqe_prev = NULL;
  586. #ifdef notyet /* TODO: See if this is required for exception handling */
  587. /* invalid sequence number */
  588. peer->tids_last_seq[tid] = 0xffff;
  589. #endif
  590. }
  591. /* Setup default (non-qos) rx tid queue */
  592. dp_rx_tid_setup_wifi3(peer, DP_NON_QOS_TID, 1, 0);
  593. /*
  594. * Set security defaults: no PN check, no security. The target may
  595. * send a HTT SEC_IND message to overwrite these defaults.
  596. */
  597. peer->security[dp_sec_ucast].sec_type =
  598. peer->security[dp_sec_mcast].sec_type = htt_sec_type_none;
  599. }
  600. /*
  601. * dp_peer_rx_cleanup() – Cleanup receive TID state
  602. * @vdev: Datapath vdev
  603. * @peer: Datapath peer
  604. *
  605. */
  606. void dp_peer_rx_cleanup(struct dp_vdev *vdev, struct dp_peer *peer)
  607. {
  608. int tid;
  609. struct dp_rx_tid *rx_tid;
  610. uint32_t tid_delete_mask = 0;
  611. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  612. if (rx_tid->hw_qdesc_vaddr_unaligned != NULL) {
  613. dp_rx_tid_delete_wifi3(peer, tid);
  614. tid_delete_mask |= (1 << tid);
  615. }
  616. }
  617. #ifdef notyet /* See if FW can remove queues as part of peer cleanup */
  618. if (soc->ol_ops->peer_rx_reorder_queue_remove) {
  619. soc->ol_ops->peer_rx_reorder_queue_remove(soc->osif_soc,
  620. peer->vdev->vdev_id, peer->mac_addr.raw,
  621. tid_delete_mask);
  622. }
  623. #endif
  624. }
  625. /*
  626. * dp_rx_addba_requestprocess_wifi3() – Process ADDBA request from peer
  627. *
  628. * @peer: Datapath peer handle
  629. * @dialogtoken: dialogtoken from ADDBA frame
  630. * @tid: TID number
  631. * @startseqnum: Start seq. number received in BA sequence control
  632. * in ADDBA frame
  633. *
  634. * Return: 0 on success, error code on failure
  635. */
  636. int dp_addba_requestprocess_wifi3(void *peer_handle,
  637. uint8_t dialogtoken, uint16_t tid, uint16_t batimeout,
  638. uint16_t buffersize, uint16_t startseqnum)
  639. {
  640. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  641. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  642. if ((rx_tid->ba_status == DP_RX_BA_ACTIVE) &&
  643. (rx_tid->hw_qdesc_vaddr_unaligned != NULL))
  644. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  645. if (dp_rx_tid_setup_wifi3(peer, tid, buffersize,
  646. startseqnum)) {
  647. /* TODO: Should we send addba reject in this case */
  648. return QDF_STATUS_E_FAILURE;
  649. }
  650. rx_tid->ba_win_size = buffersize;
  651. rx_tid->dialogtoken = dialogtoken;
  652. rx_tid->statuscode = QDF_STATUS_SUCCESS;
  653. rx_tid->ba_status = DP_RX_BA_ACTIVE;
  654. return 0;
  655. }
  656. /*
  657. * dp_rx_addba_responsesetup_wifi3() – Process ADDBA request from peer
  658. *
  659. * @peer: Datapath peer handle
  660. * @tid: TID number
  661. * @dialogtoken: output dialogtoken
  662. * @statuscode: output dialogtoken
  663. * @buffersize: Ouput BA window sizze
  664. * @batimeout: Ouput BA timeout
  665. */
  666. void dp_addba_responsesetup_wifi3(void *peer_handle, uint8_t tid,
  667. uint8_t *dialogtoken, uint16_t *statuscode,
  668. uint16_t *buffersize, uint16_t *batimeout)
  669. {
  670. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  671. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  672. /* setup ADDBA response paramters */
  673. *dialogtoken = rx_tid->dialogtoken;
  674. *statuscode = rx_tid->statuscode;
  675. *buffersize = rx_tid->ba_win_size;
  676. *batimeout = 0;
  677. }
  678. /*
  679. * dp_rx_delba_process_wifi3() – Process DELBA from peer
  680. * @peer: Datapath peer handle
  681. * @tid: TID number
  682. * @reasoncode: Reason code received in DELBA frame
  683. *
  684. * Return: 0 on success, error code on failure
  685. */
  686. int dp_delba_process_wifi3(void *peer_handle,
  687. int tid, uint16_t reasoncode)
  688. {
  689. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  690. struct dp_rx_tid *rx_tid = &peer->rx_tid[tid];
  691. if (rx_tid->ba_status != DP_RX_BA_ACTIVE)
  692. return QDF_STATUS_E_FAILURE;
  693. /* TODO: See if we can delete the existing REO queue descriptor and
  694. * replace with a new one without queue extenstion descript to save
  695. * memory
  696. */
  697. dp_rx_tid_update_wifi3(peer, tid, 0, 0);
  698. rx_tid->ba_status = DP_RX_BA_INACTIVE;
  699. return 0;
  700. }
  701. void dp_rx_discard(struct dp_vdev *vdev, struct dp_peer *peer, unsigned tid,
  702. qdf_nbuf_t msdu_list)
  703. {
  704. while (msdu_list) {
  705. qdf_nbuf_t msdu = msdu_list;
  706. msdu_list = qdf_nbuf_next(msdu_list);
  707. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  708. "discard rx %p from partly-deleted peer %p "
  709. "(%02x:%02x:%02x:%02x:%02x:%02x)\n",
  710. msdu, peer,
  711. peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  712. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  713. peer->mac_addr.raw[4], peer->mac_addr.raw[5]);
  714. qdf_nbuf_free(msdu);
  715. }
  716. }
  717. void
  718. dp_rx_sec_ind_handler(void *soc_handle, uint16_t peer_id,
  719. enum htt_sec_type sec_type, int is_unicast, u_int32_t *michael_key,
  720. u_int32_t *rx_pn)
  721. {
  722. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  723. struct dp_peer *peer;
  724. int sec_index;
  725. peer = dp_peer_find_by_id(soc, peer_id);
  726. if (!peer) {
  727. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  728. "Couldn't find peer from ID %d - skipping security inits\n",
  729. peer_id);
  730. return;
  731. }
  732. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  733. "sec spec for peer %p (%02x:%02x:%02x:%02x:%02x:%02x): "
  734. "%s key of type %d\n",
  735. peer,
  736. peer->mac_addr.raw[0], peer->mac_addr.raw[1],
  737. peer->mac_addr.raw[2], peer->mac_addr.raw[3],
  738. peer->mac_addr.raw[4], peer->mac_addr.raw[5],
  739. is_unicast ? "ucast" : "mcast",
  740. sec_type);
  741. sec_index = is_unicast ? dp_sec_ucast : dp_sec_mcast;
  742. peer->security[sec_index].sec_type = sec_type;
  743. #ifdef notyet /* TODO: See if this is required for defrag support */
  744. /* michael key only valid for TKIP, but for simplicity,
  745. * copy it anyway
  746. */
  747. qdf_mem_copy(
  748. &peer->security[sec_index].michael_key[0],
  749. michael_key,
  750. sizeof(peer->security[sec_index].michael_key));
  751. #ifdef BIG_ENDIAN_HOST
  752. OL_IF_SWAPBO(peer->security[sec_index].michael_key[0],
  753. sizeof(peer->security[sec_index].michael_key));
  754. #endif /* BIG_ENDIAN_HOST */
  755. #endif
  756. #ifdef notyet /* TODO: Check if this is required for wifi3.0 */
  757. if (sec_type != htt_sec_type_wapi) {
  758. qdf_mem_set(peer->tids_last_pn_valid, _EXT_TIDS, 0x00);
  759. } else {
  760. for (i = 0; i < DP_MAX_TIDS; i++) {
  761. /*
  762. * Setting PN valid bit for WAPI sec_type,
  763. * since WAPI PN has to be started with predefined value
  764. */
  765. peer->tids_last_pn_valid[i] = 1;
  766. qdf_mem_copy(
  767. (u_int8_t *) &peer->tids_last_pn[i],
  768. (u_int8_t *) rx_pn, sizeof(union htt_rx_pn_t));
  769. peer->tids_last_pn[i].pn128[1] =
  770. qdf_cpu_to_le64(peer->tids_last_pn[i].pn128[1]);
  771. peer->tids_last_pn[i].pn128[0] =
  772. qdf_cpu_to_le64(peer->tids_last_pn[i].pn128[0]);
  773. }
  774. }
  775. #endif
  776. /* TODO: Update HW TID queue with PN check parameters (pn type for
  777. * all security types and last pn for WAPI) once REO command API
  778. * is available
  779. */
  780. }
  781. #ifndef CONFIG_WIN
  782. /**
  783. * dp_register_peer() - Register peer into physical device
  784. * @pdev - data path device instance
  785. * @sta_desc - peer description
  786. *
  787. * Register peer into physical device
  788. *
  789. * Return: QDF_STATUS_SUCCESS registration success
  790. * QDF_STATUS_E_FAULT peer not found
  791. */
  792. QDF_STATUS dp_register_peer(void *pdev_handle,
  793. struct ol_txrx_desc_type *sta_desc)
  794. {
  795. struct dp_peer *peer;
  796. struct dp_pdev *pdev = pdev_handle;
  797. peer = dp_peer_find_by_local_id(pdev, sta_desc->sta_id);
  798. if (!peer)
  799. return QDF_STATUS_E_FAULT;
  800. qdf_spin_lock_bh(&peer->peer_info_lock);
  801. peer->state = OL_TXRX_PEER_STATE_CONN;
  802. qdf_spin_unlock_bh(&peer->peer_info_lock);
  803. return QDF_STATUS_SUCCESS;
  804. }
  805. /**
  806. * dp_clear_peer() - remove peer from physical device
  807. * @pdev - data path device instance
  808. * @sta_id - local peer id
  809. *
  810. * remove peer from physical device
  811. *
  812. * Return: QDF_STATUS_SUCCESS registration success
  813. * QDF_STATUS_E_FAULT peer not found
  814. */
  815. QDF_STATUS dp_clear_peer(void *pdev_handle, uint8_t local_id)
  816. {
  817. struct dp_peer *peer;
  818. struct dp_pdev *pdev = pdev_handle;
  819. peer = dp_peer_find_by_local_id(pdev, local_id);
  820. if (!peer)
  821. return QDF_STATUS_E_FAULT;
  822. qdf_spin_lock_bh(&peer->peer_info_lock);
  823. peer->state = OL_TXRX_PEER_STATE_DISC;
  824. qdf_spin_unlock_bh(&peer->peer_info_lock);
  825. return QDF_STATUS_SUCCESS;
  826. }
  827. /**
  828. * dp_find_peer_by_addr_and_vdev() - Find peer by peer mac address within vdev
  829. * @pdev - data path device instance
  830. * @vdev - virtual interface instance
  831. * @peer_addr - peer mac address
  832. * @peer_id - local peer id with target mac address
  833. *
  834. * Find peer by peer mac address within vdev
  835. *
  836. * Return: peer instance void pointer
  837. * NULL cannot find target peer
  838. */
  839. void *dp_find_peer_by_addr_and_vdev(void *pdev_handle, void *vdev,
  840. uint8_t *peer_addr, uint8_t *local_id)
  841. {
  842. struct dp_pdev *pdev = pdev_handle;
  843. struct dp_peer *peer;
  844. DP_TRACE(INFO, "vdev %p peer_addr %p", vdev, peer_addr);
  845. peer = dp_peer_find_hash_find(pdev->soc, peer_addr, 0);
  846. DP_TRACE(INFO, "peer %p vdev %p", peer, vdev);
  847. if (!peer)
  848. return NULL;
  849. if (peer->vdev != vdev)
  850. return NULL;
  851. *local_id = peer->local_id;
  852. DP_TRACE(INFO, "peer %p vdev %p lcoal id %d",
  853. peer, vdev, *local_id);
  854. return peer;
  855. }
  856. /**
  857. * dp_local_peer_id() - Find local peer id within peer instance
  858. * @peer - peer instance
  859. *
  860. * Find local peer id within peer instance
  861. *
  862. * Return: local peer id
  863. */
  864. uint16_t dp_local_peer_id(void *peer)
  865. {
  866. return ((struct dp_peer *)peer)->local_id;
  867. }
  868. /**
  869. * dp_peer_find_by_local_id() - Find peer by local peer id
  870. * @pdev - data path device instance
  871. * @local_peer_id - local peer id want to find
  872. *
  873. * Find peer by local peer id within physical device
  874. *
  875. * Return: peer instance void pointer
  876. * NULL cannot find target peer
  877. */
  878. void *dp_peer_find_by_local_id(void *pdev_handle, uint8_t local_id)
  879. {
  880. struct dp_peer *peer;
  881. struct dp_pdev *pdev = pdev_handle;
  882. qdf_spin_lock_bh(&pdev->local_peer_ids.lock);
  883. peer = pdev->local_peer_ids.map[local_id];
  884. qdf_spin_unlock_bh(&pdev->local_peer_ids.lock);
  885. DP_TRACE(INFO, "peer %p lcoal id %d",
  886. peer, local_id);
  887. return peer;
  888. }
  889. /**
  890. * dp_peer_state_update() - update peer local state
  891. * @pdev - data path device instance
  892. * @peer_addr - peer mac address
  893. * @state - new peer local state
  894. *
  895. * update peer local state
  896. *
  897. * Return: QDF_STATUS_SUCCESS registration success
  898. */
  899. QDF_STATUS dp_peer_state_update(void *pdev_handle, uint8_t *peer_mac,
  900. enum ol_txrx_peer_state state)
  901. {
  902. struct dp_peer *peer;
  903. struct dp_pdev *pdev = pdev_handle;
  904. peer = dp_peer_find_hash_find(pdev->soc, peer_mac, 0);
  905. if (NULL == peer) {
  906. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  907. "Failed to find peer for: [%pM]", peer_mac);
  908. return QDF_STATUS_E_FAILURE;
  909. }
  910. peer->state = state;
  911. DP_TRACE(INFO, "peer %p state %d",
  912. peer, peer->state);
  913. return QDF_STATUS_SUCCESS;
  914. }
  915. /**
  916. * dp_get_vdevid() - Get virtaul interface id which peer registered
  917. * @peer - peer instance
  918. * @vdev_id - virtaul interface id which peer registered
  919. *
  920. * Get virtaul interface id which peer registered
  921. *
  922. * Return: QDF_STATUS_SUCCESS registration success
  923. */
  924. QDF_STATUS dp_get_vdevid(void *peer_handle, uint8_t *vdev_id)
  925. {
  926. struct dp_peer *peer = peer_handle;
  927. DP_TRACE(INFO, "peer %p vdev %p vdev id %d",
  928. peer, peer->vdev, peer->vdev->vdev_id);
  929. *vdev_id = peer->vdev->vdev_id;
  930. return QDF_STATUS_SUCCESS;
  931. }
  932. /**
  933. * dp_get_vdev_for_peer() - Get virtual interface instance which peer belongs
  934. * @peer - peer instance
  935. *
  936. * Get virtual interface instance which peer belongs
  937. *
  938. * Return: virtual interface instance pointer
  939. * NULL in case cannot find
  940. */
  941. void *dp_get_vdev_for_peer(void *peer_handle)
  942. {
  943. struct dp_peer *peer = peer_handle;
  944. DP_TRACE(INFO, "peer %p vdev %p", peer, peer->vdev);
  945. return (void *)peer->vdev;
  946. }
  947. /**
  948. * dp_peer_get_peer_mac_addr() - Get peer mac address
  949. * @peer - peer instance
  950. *
  951. * Get peer mac address
  952. *
  953. * Return: peer mac address pointer
  954. * NULL in case cannot find
  955. */
  956. uint8_t *dp_peer_get_peer_mac_addr(void *peer_handle)
  957. {
  958. struct dp_peer *peer = peer_handle;
  959. uint8_t *mac;
  960. mac = peer->mac_addr.raw;
  961. DP_TRACE(INFO, "peer %p mac 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
  962. peer, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  963. return peer->mac_addr.raw;
  964. }
  965. /**
  966. * dp_get_peer_state() - Get local peer state
  967. * @peer - peer instance
  968. *
  969. * Get local peer state
  970. *
  971. * Return: peer status
  972. */
  973. int dp_get_peer_state(void *peer_handle)
  974. {
  975. struct dp_peer *peer = peer_handle;
  976. DP_TRACE(INFO, "peer %p stats %d", peer, peer->state);
  977. return peer->state;
  978. }
  979. /**
  980. * dp_local_peer_id_pool_init() - local peer id pool alloc for physical device
  981. * @pdev - data path device instance
  982. *
  983. * local peer id pool alloc for physical device
  984. *
  985. * Return: none
  986. */
  987. void dp_local_peer_id_pool_init(struct dp_pdev *pdev)
  988. {
  989. int i;
  990. /* point the freelist to the first ID */
  991. pdev->local_peer_ids.freelist = 0;
  992. /* link each ID to the next one */
  993. for (i = 0; i < OL_TXRX_NUM_LOCAL_PEER_IDS; i++) {
  994. pdev->local_peer_ids.pool[i] = i + 1;
  995. pdev->local_peer_ids.map[i] = NULL;
  996. }
  997. /* link the last ID to itself, to mark the end of the list */
  998. i = OL_TXRX_NUM_LOCAL_PEER_IDS;
  999. pdev->local_peer_ids.pool[i] = i;
  1000. qdf_spinlock_create(&pdev->local_peer_ids.lock);
  1001. DP_TRACE(INFO, "Peer pool init");
  1002. }
  1003. /**
  1004. * dp_local_peer_id_alloc() - allocate local peer id
  1005. * @pdev - data path device instance
  1006. * @peer - new peer instance
  1007. *
  1008. * allocate local peer id
  1009. *
  1010. * Return: none
  1011. */
  1012. void dp_local_peer_id_alloc(struct dp_pdev *pdev, struct dp_peer *peer)
  1013. {
  1014. int i;
  1015. qdf_spin_lock_bh(&pdev->local_peer_ids.lock);
  1016. i = pdev->local_peer_ids.freelist;
  1017. if (pdev->local_peer_ids.pool[i] == i) {
  1018. /* the list is empty, except for the list-end marker */
  1019. peer->local_id = OL_TXRX_INVALID_LOCAL_PEER_ID;
  1020. } else {
  1021. /* take the head ID and advance the freelist */
  1022. peer->local_id = i;
  1023. pdev->local_peer_ids.freelist = pdev->local_peer_ids.pool[i];
  1024. pdev->local_peer_ids.map[i] = peer;
  1025. }
  1026. qdf_spin_unlock_bh(&pdev->local_peer_ids.lock);
  1027. DP_TRACE(INFO, "peer %p, local id %d", peer, peer->local_id);
  1028. }
  1029. /**
  1030. * dp_local_peer_id_free() - remove local peer id
  1031. * @pdev - data path device instance
  1032. * @peer - peer instance should be removed
  1033. *
  1034. * remove local peer id
  1035. *
  1036. * Return: none
  1037. */
  1038. void dp_local_peer_id_free(struct dp_pdev *pdev, struct dp_peer *peer)
  1039. {
  1040. int i = peer->local_id;
  1041. if ((i == OL_TXRX_INVALID_LOCAL_PEER_ID) ||
  1042. (i >= OL_TXRX_NUM_LOCAL_PEER_IDS)) {
  1043. return;
  1044. }
  1045. /* put this ID on the head of the freelist */
  1046. qdf_spin_lock_bh(&pdev->local_peer_ids.lock);
  1047. pdev->local_peer_ids.pool[i] = pdev->local_peer_ids.freelist;
  1048. pdev->local_peer_ids.freelist = i;
  1049. pdev->local_peer_ids.map[i] = NULL;
  1050. qdf_spin_unlock_bh(&pdev->local_peer_ids.lock);
  1051. }
  1052. #endif