wfx.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Common private data.
  4. *
  5. * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
  6. * Copyright (c) 2010, ST-Ericsson
  7. * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
  8. * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
  9. */
  10. #ifndef WFX_H
  11. #define WFX_H
  12. #include <linux/completion.h>
  13. #include <linux/workqueue.h>
  14. #include <linux/mutex.h>
  15. #include <linux/nospec.h>
  16. #include <net/mac80211.h>
  17. #include "bh.h"
  18. #include "data_tx.h"
  19. #include "main.h"
  20. #include "queue.h"
  21. #include "hif_tx.h"
  22. #define USEC_PER_TXOP 32 /* see struct ieee80211_tx_queue_params */
  23. #define USEC_PER_TU 1024
  24. struct wfx_hwbus_ops;
  25. struct wfx_dev {
  26. struct wfx_platform_data pdata;
  27. struct device *dev;
  28. struct ieee80211_hw *hw;
  29. struct ieee80211_vif *vif[2];
  30. struct mac_address addresses[2];
  31. const struct wfx_hwbus_ops *hwbus_ops;
  32. void *hwbus_priv;
  33. u8 keyset;
  34. struct completion firmware_ready;
  35. struct wfx_hif_ind_startup hw_caps;
  36. struct wfx_hif hif;
  37. struct delayed_work cooling_timeout_work;
  38. bool poll_irq;
  39. bool chip_frozen;
  40. struct mutex scan_lock;
  41. struct mutex conf_mutex;
  42. struct wfx_hif_cmd hif_cmd;
  43. struct sk_buff_head tx_pending;
  44. wait_queue_head_t tx_dequeue;
  45. atomic_t tx_lock;
  46. atomic_t packet_id;
  47. u32 key_map;
  48. struct wfx_hif_rx_stats rx_stats;
  49. struct mutex rx_stats_lock;
  50. struct wfx_hif_tx_power_loop_info tx_power_loop_info;
  51. struct mutex tx_power_loop_info_lock;
  52. struct workqueue_struct *bh_wq;
  53. };
  54. struct wfx_vif {
  55. struct wfx_dev *wdev;
  56. struct ieee80211_channel *channel;
  57. int id;
  58. u32 link_id_map;
  59. bool after_dtim_tx_allowed;
  60. bool join_in_progress;
  61. struct completion set_pm_mode_complete;
  62. struct delayed_work beacon_loss_work;
  63. struct wfx_queue tx_queue[4];
  64. struct wfx_tx_policy_cache tx_policy_cache;
  65. struct work_struct tx_policy_upload_work;
  66. struct work_struct update_tim_work;
  67. unsigned long uapsd_mask;
  68. struct work_struct scan_work;
  69. struct completion scan_complete;
  70. int scan_nb_chan_done;
  71. bool scan_abort;
  72. struct ieee80211_scan_request *scan_req;
  73. struct ieee80211_channel *remain_on_channel_chan;
  74. int remain_on_channel_duration;
  75. struct work_struct remain_on_channel_work;
  76. };
  77. static inline struct ieee80211_vif *wvif_to_vif(struct wfx_vif *wvif)
  78. {
  79. return container_of((void *)wvif, struct ieee80211_vif, drv_priv);
  80. }
  81. static inline struct wfx_vif *wdev_to_wvif(struct wfx_dev *wdev, int vif_id)
  82. {
  83. if (vif_id >= ARRAY_SIZE(wdev->vif)) {
  84. dev_dbg(wdev->dev, "requesting non-existent vif: %d\n", vif_id);
  85. return NULL;
  86. }
  87. vif_id = array_index_nospec(vif_id, ARRAY_SIZE(wdev->vif));
  88. if (!wdev->vif[vif_id])
  89. return NULL;
  90. return (struct wfx_vif *)wdev->vif[vif_id]->drv_priv;
  91. }
  92. static inline struct wfx_vif *wvif_iterate(struct wfx_dev *wdev, struct wfx_vif *cur)
  93. {
  94. int i;
  95. int mark = 0;
  96. struct wfx_vif *tmp;
  97. if (!cur)
  98. mark = 1;
  99. for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
  100. tmp = wdev_to_wvif(wdev, i);
  101. if (mark && tmp)
  102. return tmp;
  103. if (tmp == cur)
  104. mark = 1;
  105. }
  106. return NULL;
  107. }
  108. static inline int wvif_count(struct wfx_dev *wdev)
  109. {
  110. int i;
  111. int ret = 0;
  112. struct wfx_vif *wvif;
  113. for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
  114. wvif = wdev_to_wvif(wdev, i);
  115. if (wvif)
  116. ret++;
  117. }
  118. return ret;
  119. }
  120. static inline void memreverse(u8 *src, u8 length)
  121. {
  122. u8 *lo = src;
  123. u8 *hi = src + length - 1;
  124. u8 swap;
  125. while (lo < hi) {
  126. swap = *lo;
  127. *lo++ = *hi;
  128. *hi-- = swap;
  129. }
  130. }
  131. static inline int memzcmp(void *src, unsigned int size)
  132. {
  133. u8 *buf = src;
  134. if (!size)
  135. return 0;
  136. if (*buf)
  137. return 1;
  138. return memcmp(buf, buf + 1, size - 1);
  139. }
  140. #endif