wifi_fw.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* Firmware/driver-layer dispatch: see wifi_fw.h. */
  2. #include "wifi_fw.h"
  3. #include "iwl_dvm.h"
  4. #include "iwl_mvm.h"
  5. #include "iwl_trans.h"
  6. #include "rtl8821au.h"
  7. enum { BE_NONE, BE_MVM, BE_DVM, BE_RTL };
  8. static int be; /* backend of the radio that is up (or last up) */
  9. /* Which backend would come up now. */
  10. static int pick(void)
  11. {
  12. if (rtl8821au_present())
  13. return BE_RTL;
  14. if (iwl_probe() == 0)
  15. return iwl_is_dvm() ? BE_DVM : BE_MVM;
  16. return BE_NONE;
  17. }
  18. /* The backend for calls that need a device: the active one, else the one
  19. * that would be picked. */
  20. static int cur(void)
  21. {
  22. return be != BE_NONE ? be : pick();
  23. }
  24. int wififw_probe(void)
  25. {
  26. return pick() == BE_NONE ? -1 : 0;
  27. }
  28. int wififw_present(void)
  29. {
  30. return cur() == BE_RTL ? rtl8821au_present() : iwl_present();
  31. }
  32. /* No probing here: SYS_NET_INFO asks once a second, and iwl_probe() scans
  33. * the whole PCI bus when no Intel card exists. */
  34. const char *wififw_chip_name(void)
  35. {
  36. int b = be;
  37. if (b == BE_NONE)
  38. b = rtl8821au_present() ? BE_RTL :
  39. iwl_present() ? BE_MVM : BE_NONE;
  40. switch (b) {
  41. case BE_RTL:
  42. return rtl8821au_chip_name();
  43. case BE_MVM:
  44. case BE_DVM:
  45. return iwl_chip_name();
  46. }
  47. return "none";
  48. }
  49. const char *wififw_fw_name(void)
  50. {
  51. const struct iwl_fw_info *fw;
  52. if (cur() == BE_RTL)
  53. return rtl8821au_fw_name();
  54. fw = iwl_fw();
  55. return fw && fw->present ? fw->human : "";
  56. }
  57. int wififw_fatal(void)
  58. {
  59. switch (be) {
  60. case BE_RTL:
  61. return rtl8821au_fatal();
  62. case BE_MVM:
  63. case BE_DVM:
  64. return iwl_fatal();
  65. }
  66. return 0;
  67. }
  68. int wififw_up(unsigned char mac[6])
  69. {
  70. be = pick();
  71. switch (be) {
  72. case BE_RTL:
  73. return rtl8821au_up(mac);
  74. case BE_DVM:
  75. return iwl_dvm_up(mac);
  76. case BE_MVM:
  77. return iwl_mvm_up(mac);
  78. }
  79. return -1;
  80. }
  81. void wififw_down(void)
  82. {
  83. switch (be) {
  84. case BE_RTL:
  85. rtl8821au_down();
  86. break;
  87. case BE_DVM:
  88. iwl_dvm_down();
  89. break;
  90. case BE_MVM:
  91. iwl_mvm_down();
  92. break;
  93. }
  94. be = BE_NONE;
  95. }
  96. void wififw_shutdown(void)
  97. {
  98. int was = be;
  99. wififw_down();
  100. /* The Intel card may have run before the stick was plugged in: its
  101. * RX ring must stop writing into pages the next kernel reuses. */
  102. if (was != BE_MVM && was != BE_DVM && iwl_present()) {
  103. if (iwl_is_dvm())
  104. iwl_dvm_down();
  105. else
  106. iwl_mvm_down();
  107. }
  108. }
  109. const char *wififw_state(void)
  110. {
  111. switch (cur()) {
  112. case BE_RTL:
  113. return rtl8821au_state();
  114. case BE_DVM:
  115. return iwl_dvm_state();
  116. case BE_MVM:
  117. return iwl_mvm_state();
  118. }
  119. return "no WiFi device";
  120. }
  121. int wififw_poll(void)
  122. {
  123. switch (be) {
  124. case BE_RTL:
  125. return rtl8821au_poll();
  126. case BE_DVM:
  127. return iwl_dvm_poll();
  128. case BE_MVM:
  129. return iwl_mvm_poll();
  130. }
  131. return -1;
  132. }
  133. int wififw_scan_start(void)
  134. {
  135. switch (be) {
  136. case BE_RTL:
  137. return rtl8821au_scan_start();
  138. case BE_DVM:
  139. return iwl_dvm_scan_start();
  140. case BE_MVM:
  141. return iwl_mvm_scan_start();
  142. }
  143. return -1;
  144. }
  145. int wififw_scan_running(void)
  146. {
  147. switch (be) {
  148. case BE_RTL:
  149. return rtl8821au_scan_running();
  150. case BE_DVM:
  151. return iwl_dvm_scan_running();
  152. case BE_MVM:
  153. return iwl_mvm_scan_running();
  154. }
  155. return 0;
  156. }
  157. int wififw_prepare_connect(const unsigned char bssid[6], unsigned int chan,
  158. unsigned int beacon_int)
  159. {
  160. switch (be) {
  161. case BE_RTL:
  162. return rtl8821au_prepare_connect(bssid, chan, beacon_int);
  163. case BE_DVM:
  164. return iwl_dvm_prepare_connect(bssid, chan, beacon_int);
  165. case BE_MVM:
  166. return iwl_mvm_prepare_connect(bssid, chan, beacon_int);
  167. }
  168. return -1;
  169. }
  170. int wififw_set_assoc(unsigned short aid, unsigned int beacon_int,
  171. unsigned int dtim)
  172. {
  173. switch (be) {
  174. case BE_RTL:
  175. return rtl8821au_set_assoc(aid, beacon_int, dtim);
  176. case BE_DVM:
  177. return iwl_dvm_set_assoc(aid, beacon_int, dtim);
  178. case BE_MVM:
  179. return iwl_mvm_set_assoc(aid, beacon_int, dtim);
  180. }
  181. return -1;
  182. }
  183. void wififw_disconnect(void)
  184. {
  185. switch (be) {
  186. case BE_RTL:
  187. rtl8821au_disconnect();
  188. break;
  189. case BE_DVM:
  190. iwl_dvm_disconnect();
  191. break;
  192. case BE_MVM:
  193. iwl_mvm_disconnect();
  194. break;
  195. }
  196. }
  197. int wififw_tx_mgmt(const unsigned char *frame, unsigned int len)
  198. {
  199. switch (be) {
  200. case BE_RTL:
  201. return rtl8821au_tx_mgmt(frame, len);
  202. case BE_DVM:
  203. return iwl_dvm_tx_mgmt(frame, len);
  204. case BE_MVM:
  205. return iwl_mvm_tx_mgmt(frame, len);
  206. }
  207. return -1;
  208. }
  209. int wififw_tx_data(const unsigned char *frame, unsigned int len, int protect)
  210. {
  211. switch (be) {
  212. case BE_RTL:
  213. return rtl8821au_tx_data(frame, len, protect);
  214. case BE_DVM:
  215. return iwl_dvm_tx_data(frame, len, protect);
  216. case BE_MVM:
  217. return iwl_mvm_tx_data(frame, len, protect);
  218. }
  219. return -1;
  220. }
  221. int wififw_set_key(int pairwise, int keyidx, const unsigned char key[16],
  222. const unsigned char rsc[6])
  223. {
  224. switch (be) {
  225. case BE_RTL:
  226. return rtl8821au_set_key(pairwise, keyidx, key, rsc);
  227. case BE_DVM:
  228. return iwl_dvm_set_key(pairwise, keyidx, key, rsc);
  229. case BE_MVM:
  230. return iwl_mvm_set_key(pairwise, keyidx, key, rsc);
  231. }
  232. return -1;
  233. }
  234. void wififw_clear_keys(void)
  235. {
  236. switch (be) {
  237. case BE_RTL:
  238. rtl8821au_clear_keys();
  239. break;
  240. case BE_DVM:
  241. iwl_dvm_clear_keys();
  242. break;
  243. case BE_MVM:
  244. iwl_mvm_clear_keys();
  245. break;
  246. }
  247. }