wfx.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Common private data for Silicon Labs WFx chips.
  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 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 hwbus_ops *hwbus_ops;
  32. void *hwbus_priv;
  33. u8 keyset;
  34. struct completion firmware_ready;
  35. struct 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 conf_mutex;
  41. struct wfx_hif_cmd hif_cmd;
  42. struct sk_buff_head tx_pending;
  43. wait_queue_head_t tx_dequeue;
  44. atomic_t tx_lock;
  45. atomic_t packet_id;
  46. u32 key_map;
  47. struct hif_rx_stats rx_stats;
  48. struct mutex rx_stats_lock;
  49. struct hif_tx_power_loop_info tx_power_loop_info;
  50. struct mutex tx_power_loop_info_lock;
  51. int force_ps_timeout;
  52. };
  53. struct wfx_vif {
  54. struct wfx_dev *wdev;
  55. struct ieee80211_vif *vif;
  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 delayed_work beacon_loss_work;
  62. struct wfx_queue tx_queue[4];
  63. struct tx_policy_cache tx_policy_cache;
  64. struct work_struct tx_policy_upload_work;
  65. struct work_struct update_tim_work;
  66. unsigned long uapsd_mask;
  67. /* avoid some operations in parallel with scan */
  68. struct mutex scan_lock;
  69. struct work_struct scan_work;
  70. struct completion scan_complete;
  71. bool scan_abort;
  72. struct ieee80211_scan_request *scan_req;
  73. struct completion set_pm_mode_complete;
  74. };
  75. static inline struct wfx_vif *wdev_to_wvif(struct wfx_dev *wdev, int vif_id)
  76. {
  77. if (vif_id >= ARRAY_SIZE(wdev->vif)) {
  78. dev_dbg(wdev->dev, "requesting non-existent vif: %d\n", vif_id);
  79. return NULL;
  80. }
  81. vif_id = array_index_nospec(vif_id, ARRAY_SIZE(wdev->vif));
  82. if (!wdev->vif[vif_id]) {
  83. dev_dbg(wdev->dev, "requesting non-allocated vif: %d\n",
  84. vif_id);
  85. return NULL;
  86. }
  87. return (struct wfx_vif *) wdev->vif[vif_id]->drv_priv;
  88. }
  89. static inline struct wfx_vif *wvif_iterate(struct wfx_dev *wdev,
  90. struct wfx_vif *cur)
  91. {
  92. int i;
  93. int mark = 0;
  94. struct wfx_vif *tmp;
  95. if (!cur)
  96. mark = 1;
  97. for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
  98. tmp = wdev_to_wvif(wdev, i);
  99. if (mark && tmp)
  100. return tmp;
  101. if (tmp == cur)
  102. mark = 1;
  103. }
  104. return NULL;
  105. }
  106. static inline int wvif_count(struct wfx_dev *wdev)
  107. {
  108. int i;
  109. int ret = 0;
  110. struct wfx_vif *wvif;
  111. for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
  112. wvif = wdev_to_wvif(wdev, i);
  113. if (wvif)
  114. ret++;
  115. }
  116. return ret;
  117. }
  118. static inline void memreverse(u8 *src, u8 length)
  119. {
  120. u8 *lo = src;
  121. u8 *hi = src + length - 1;
  122. u8 swap;
  123. while (lo < hi) {
  124. swap = *lo;
  125. *lo++ = *hi;
  126. *hi-- = swap;
  127. }
  128. }
  129. static inline int memzcmp(void *src, unsigned int size)
  130. {
  131. u8 *buf = src;
  132. if (!size)
  133. return 0;
  134. if (*buf)
  135. return 1;
  136. return memcmp(buf, buf + 1, size - 1);
  137. }
  138. #endif /* WFX_H */