rsi_91x_mac80211.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028
  1. /**
  2. * Copyright (c) 2014 Redpine Signals Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/etherdevice.h>
  17. #include "rsi_debugfs.h"
  18. #include "rsi_mgmt.h"
  19. #include "rsi_sdio.h"
  20. #include "rsi_common.h"
  21. #include "rsi_ps.h"
  22. static const struct ieee80211_channel rsi_2ghz_channels[] = {
  23. { .band = NL80211_BAND_2GHZ, .center_freq = 2412,
  24. .hw_value = 1 }, /* Channel 1 */
  25. { .band = NL80211_BAND_2GHZ, .center_freq = 2417,
  26. .hw_value = 2 }, /* Channel 2 */
  27. { .band = NL80211_BAND_2GHZ, .center_freq = 2422,
  28. .hw_value = 3 }, /* Channel 3 */
  29. { .band = NL80211_BAND_2GHZ, .center_freq = 2427,
  30. .hw_value = 4 }, /* Channel 4 */
  31. { .band = NL80211_BAND_2GHZ, .center_freq = 2432,
  32. .hw_value = 5 }, /* Channel 5 */
  33. { .band = NL80211_BAND_2GHZ, .center_freq = 2437,
  34. .hw_value = 6 }, /* Channel 6 */
  35. { .band = NL80211_BAND_2GHZ, .center_freq = 2442,
  36. .hw_value = 7 }, /* Channel 7 */
  37. { .band = NL80211_BAND_2GHZ, .center_freq = 2447,
  38. .hw_value = 8 }, /* Channel 8 */
  39. { .band = NL80211_BAND_2GHZ, .center_freq = 2452,
  40. .hw_value = 9 }, /* Channel 9 */
  41. { .band = NL80211_BAND_2GHZ, .center_freq = 2457,
  42. .hw_value = 10 }, /* Channel 10 */
  43. { .band = NL80211_BAND_2GHZ, .center_freq = 2462,
  44. .hw_value = 11 }, /* Channel 11 */
  45. { .band = NL80211_BAND_2GHZ, .center_freq = 2467,
  46. .hw_value = 12 }, /* Channel 12 */
  47. { .band = NL80211_BAND_2GHZ, .center_freq = 2472,
  48. .hw_value = 13 }, /* Channel 13 */
  49. { .band = NL80211_BAND_2GHZ, .center_freq = 2484,
  50. .hw_value = 14 }, /* Channel 14 */
  51. };
  52. static const struct ieee80211_channel rsi_5ghz_channels[] = {
  53. { .band = NL80211_BAND_5GHZ, .center_freq = 5180,
  54. .hw_value = 36, }, /* Channel 36 */
  55. { .band = NL80211_BAND_5GHZ, .center_freq = 5200,
  56. .hw_value = 40, }, /* Channel 40 */
  57. { .band = NL80211_BAND_5GHZ, .center_freq = 5220,
  58. .hw_value = 44, }, /* Channel 44 */
  59. { .band = NL80211_BAND_5GHZ, .center_freq = 5240,
  60. .hw_value = 48, }, /* Channel 48 */
  61. { .band = NL80211_BAND_5GHZ, .center_freq = 5260,
  62. .hw_value = 52, }, /* Channel 52 */
  63. { .band = NL80211_BAND_5GHZ, .center_freq = 5280,
  64. .hw_value = 56, }, /* Channel 56 */
  65. { .band = NL80211_BAND_5GHZ, .center_freq = 5300,
  66. .hw_value = 60, }, /* Channel 60 */
  67. { .band = NL80211_BAND_5GHZ, .center_freq = 5320,
  68. .hw_value = 64, }, /* Channel 64 */
  69. { .band = NL80211_BAND_5GHZ, .center_freq = 5500,
  70. .hw_value = 100, }, /* Channel 100 */
  71. { .band = NL80211_BAND_5GHZ, .center_freq = 5520,
  72. .hw_value = 104, }, /* Channel 104 */
  73. { .band = NL80211_BAND_5GHZ, .center_freq = 5540,
  74. .hw_value = 108, }, /* Channel 108 */
  75. { .band = NL80211_BAND_5GHZ, .center_freq = 5560,
  76. .hw_value = 112, }, /* Channel 112 */
  77. { .band = NL80211_BAND_5GHZ, .center_freq = 5580,
  78. .hw_value = 116, }, /* Channel 116 */
  79. { .band = NL80211_BAND_5GHZ, .center_freq = 5600,
  80. .hw_value = 120, }, /* Channel 120 */
  81. { .band = NL80211_BAND_5GHZ, .center_freq = 5620,
  82. .hw_value = 124, }, /* Channel 124 */
  83. { .band = NL80211_BAND_5GHZ, .center_freq = 5640,
  84. .hw_value = 128, }, /* Channel 128 */
  85. { .band = NL80211_BAND_5GHZ, .center_freq = 5660,
  86. .hw_value = 132, }, /* Channel 132 */
  87. { .band = NL80211_BAND_5GHZ, .center_freq = 5680,
  88. .hw_value = 136, }, /* Channel 136 */
  89. { .band = NL80211_BAND_5GHZ, .center_freq = 5700,
  90. .hw_value = 140, }, /* Channel 140 */
  91. { .band = NL80211_BAND_5GHZ, .center_freq = 5745,
  92. .hw_value = 149, }, /* Channel 149 */
  93. { .band = NL80211_BAND_5GHZ, .center_freq = 5765,
  94. .hw_value = 153, }, /* Channel 153 */
  95. { .band = NL80211_BAND_5GHZ, .center_freq = 5785,
  96. .hw_value = 157, }, /* Channel 157 */
  97. { .band = NL80211_BAND_5GHZ, .center_freq = 5805,
  98. .hw_value = 161, }, /* Channel 161 */
  99. { .band = NL80211_BAND_5GHZ, .center_freq = 5825,
  100. .hw_value = 165, }, /* Channel 165 */
  101. };
  102. struct ieee80211_rate rsi_rates[12] = {
  103. { .bitrate = STD_RATE_01 * 5, .hw_value = RSI_RATE_1 },
  104. { .bitrate = STD_RATE_02 * 5, .hw_value = RSI_RATE_2 },
  105. { .bitrate = STD_RATE_5_5 * 5, .hw_value = RSI_RATE_5_5 },
  106. { .bitrate = STD_RATE_11 * 5, .hw_value = RSI_RATE_11 },
  107. { .bitrate = STD_RATE_06 * 5, .hw_value = RSI_RATE_6 },
  108. { .bitrate = STD_RATE_09 * 5, .hw_value = RSI_RATE_9 },
  109. { .bitrate = STD_RATE_12 * 5, .hw_value = RSI_RATE_12 },
  110. { .bitrate = STD_RATE_18 * 5, .hw_value = RSI_RATE_18 },
  111. { .bitrate = STD_RATE_24 * 5, .hw_value = RSI_RATE_24 },
  112. { .bitrate = STD_RATE_36 * 5, .hw_value = RSI_RATE_36 },
  113. { .bitrate = STD_RATE_48 * 5, .hw_value = RSI_RATE_48 },
  114. { .bitrate = STD_RATE_54 * 5, .hw_value = RSI_RATE_54 },
  115. };
  116. const u16 rsi_mcsrates[8] = {
  117. RSI_RATE_MCS0, RSI_RATE_MCS1, RSI_RATE_MCS2, RSI_RATE_MCS3,
  118. RSI_RATE_MCS4, RSI_RATE_MCS5, RSI_RATE_MCS6, RSI_RATE_MCS7
  119. };
  120. static const u32 rsi_max_ap_stas[16] = {
  121. 32, /* 1 - Wi-Fi alone */
  122. 0, /* 2 */
  123. 0, /* 3 */
  124. 0, /* 4 - BT EDR alone */
  125. 4, /* 5 - STA + BT EDR */
  126. 32, /* 6 - AP + BT EDR */
  127. 0, /* 7 */
  128. 0, /* 8 - BT LE alone */
  129. 4, /* 9 - STA + BE LE */
  130. 0, /* 10 */
  131. 0, /* 11 */
  132. 0, /* 12 */
  133. 1, /* 13 - STA + BT Dual */
  134. 4, /* 14 - AP + BT Dual */
  135. };
  136. static const struct ieee80211_iface_limit rsi_iface_limits[] = {
  137. {
  138. .max = 1,
  139. .types = BIT(NL80211_IFTYPE_STATION),
  140. },
  141. {
  142. .max = 1,
  143. .types = BIT(NL80211_IFTYPE_AP) |
  144. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  145. BIT(NL80211_IFTYPE_P2P_GO),
  146. },
  147. {
  148. .max = 1,
  149. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  150. },
  151. };
  152. static const struct ieee80211_iface_combination rsi_iface_combinations[] = {
  153. {
  154. .num_different_channels = 1,
  155. .max_interfaces = 3,
  156. .limits = rsi_iface_limits,
  157. .n_limits = ARRAY_SIZE(rsi_iface_limits),
  158. },
  159. };
  160. /**
  161. * rsi_is_cipher_wep() - This function determines if the cipher is WEP or not.
  162. * @common: Pointer to the driver private structure.
  163. *
  164. * Return: If cipher type is WEP, a value of 1 is returned, else 0.
  165. */
  166. bool rsi_is_cipher_wep(struct rsi_common *common)
  167. {
  168. if (((common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP104) ||
  169. (common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP40)) &&
  170. (!common->secinfo.ptk_cipher))
  171. return true;
  172. else
  173. return false;
  174. }
  175. /**
  176. * rsi_register_rates_channels() - This function registers channels and rates.
  177. * @adapter: Pointer to the adapter structure.
  178. * @band: Operating band to be set.
  179. *
  180. * Return: None.
  181. */
  182. static void rsi_register_rates_channels(struct rsi_hw *adapter, int band)
  183. {
  184. struct ieee80211_supported_band *sbands = &adapter->sbands[band];
  185. void *channels = NULL;
  186. if (band == NL80211_BAND_2GHZ) {
  187. channels = kmalloc(sizeof(rsi_2ghz_channels), GFP_KERNEL);
  188. memcpy(channels,
  189. rsi_2ghz_channels,
  190. sizeof(rsi_2ghz_channels));
  191. sbands->band = NL80211_BAND_2GHZ;
  192. sbands->n_channels = ARRAY_SIZE(rsi_2ghz_channels);
  193. sbands->bitrates = rsi_rates;
  194. sbands->n_bitrates = ARRAY_SIZE(rsi_rates);
  195. } else {
  196. channels = kmalloc(sizeof(rsi_5ghz_channels), GFP_KERNEL);
  197. memcpy(channels,
  198. rsi_5ghz_channels,
  199. sizeof(rsi_5ghz_channels));
  200. sbands->band = NL80211_BAND_5GHZ;
  201. sbands->n_channels = ARRAY_SIZE(rsi_5ghz_channels);
  202. sbands->bitrates = &rsi_rates[4];
  203. sbands->n_bitrates = ARRAY_SIZE(rsi_rates) - 4;
  204. }
  205. sbands->channels = channels;
  206. memset(&sbands->ht_cap, 0, sizeof(struct ieee80211_sta_ht_cap));
  207. sbands->ht_cap.ht_supported = true;
  208. sbands->ht_cap.cap = (IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  209. IEEE80211_HT_CAP_SGI_20 |
  210. IEEE80211_HT_CAP_SGI_40);
  211. sbands->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K;
  212. sbands->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  213. sbands->ht_cap.mcs.rx_mask[0] = 0xff;
  214. sbands->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  215. /* sbands->ht_cap.mcs.rx_highest = 0x82; */
  216. }
  217. /**
  218. * rsi_mac80211_detach() - This function is used to de-initialize the
  219. * Mac80211 stack.
  220. * @adapter: Pointer to the adapter structure.
  221. *
  222. * Return: None.
  223. */
  224. void rsi_mac80211_detach(struct rsi_hw *adapter)
  225. {
  226. struct ieee80211_hw *hw = adapter->hw;
  227. enum nl80211_band band;
  228. if (hw) {
  229. ieee80211_stop_queues(hw);
  230. ieee80211_unregister_hw(hw);
  231. ieee80211_free_hw(hw);
  232. adapter->hw = NULL;
  233. }
  234. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  235. struct ieee80211_supported_band *sband =
  236. &adapter->sbands[band];
  237. kfree(sband->channels);
  238. }
  239. #ifdef CONFIG_RSI_DEBUGFS
  240. rsi_remove_dbgfs(adapter);
  241. kfree(adapter->dfsentry);
  242. #endif
  243. }
  244. EXPORT_SYMBOL_GPL(rsi_mac80211_detach);
  245. /**
  246. * rsi_indicate_tx_status() - This function indicates the transmit status.
  247. * @adapter: Pointer to the adapter structure.
  248. * @skb: Pointer to the socket buffer structure.
  249. * @status: Status
  250. *
  251. * Return: None.
  252. */
  253. void rsi_indicate_tx_status(struct rsi_hw *adapter,
  254. struct sk_buff *skb,
  255. int status)
  256. {
  257. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  258. struct skb_info *tx_params;
  259. if (!adapter->hw) {
  260. rsi_dbg(ERR_ZONE, "##### No MAC #####\n");
  261. return;
  262. }
  263. if (!status)
  264. info->flags |= IEEE80211_TX_STAT_ACK;
  265. tx_params = (struct skb_info *)info->driver_data;
  266. skb_pull(skb, tx_params->internal_hdr_size);
  267. memset(info->driver_data, 0, IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
  268. ieee80211_tx_status_irqsafe(adapter->hw, skb);
  269. }
  270. /**
  271. * rsi_mac80211_tx() - This is the handler that 802.11 module calls for each
  272. * transmitted frame.SKB contains the buffer starting
  273. * from the IEEE 802.11 header.
  274. * @hw: Pointer to the ieee80211_hw structure.
  275. * @control: Pointer to the ieee80211_tx_control structure
  276. * @skb: Pointer to the socket buffer structure.
  277. *
  278. * Return: None
  279. */
  280. static void rsi_mac80211_tx(struct ieee80211_hw *hw,
  281. struct ieee80211_tx_control *control,
  282. struct sk_buff *skb)
  283. {
  284. struct rsi_hw *adapter = hw->priv;
  285. struct rsi_common *common = adapter->priv;
  286. rsi_core_xmit(common, skb);
  287. }
  288. /**
  289. * rsi_mac80211_start() - This is first handler that 802.11 module calls, since
  290. * the driver init is complete by then, just
  291. * returns success.
  292. * @hw: Pointer to the ieee80211_hw structure.
  293. *
  294. * Return: 0 as success.
  295. */
  296. static int rsi_mac80211_start(struct ieee80211_hw *hw)
  297. {
  298. struct rsi_hw *adapter = hw->priv;
  299. struct rsi_common *common = adapter->priv;
  300. rsi_dbg(ERR_ZONE, "===> Interface UP <===\n");
  301. mutex_lock(&common->mutex);
  302. if (common->hibernate_resume) {
  303. common->reinit_hw = true;
  304. adapter->host_intf_ops->reinit_device(adapter);
  305. wait_for_completion(&adapter->priv->wlan_init_completion);
  306. }
  307. common->iface_down = false;
  308. wiphy_rfkill_start_polling(hw->wiphy);
  309. rsi_send_rx_filter_frame(common, 0);
  310. mutex_unlock(&common->mutex);
  311. return 0;
  312. }
  313. /**
  314. * rsi_mac80211_stop() - This is the last handler that 802.11 module calls.
  315. * @hw: Pointer to the ieee80211_hw structure.
  316. *
  317. * Return: None.
  318. */
  319. static void rsi_mac80211_stop(struct ieee80211_hw *hw)
  320. {
  321. struct rsi_hw *adapter = hw->priv;
  322. struct rsi_common *common = adapter->priv;
  323. rsi_dbg(ERR_ZONE, "===> Interface DOWN <===\n");
  324. mutex_lock(&common->mutex);
  325. common->iface_down = true;
  326. wiphy_rfkill_stop_polling(hw->wiphy);
  327. /* Block all rx frames */
  328. rsi_send_rx_filter_frame(common, 0xffff);
  329. mutex_unlock(&common->mutex);
  330. }
  331. static int rsi_map_intf_mode(enum nl80211_iftype vif_type)
  332. {
  333. switch (vif_type) {
  334. case NL80211_IFTYPE_STATION:
  335. return RSI_OPMODE_STA;
  336. case NL80211_IFTYPE_AP:
  337. return RSI_OPMODE_AP;
  338. case NL80211_IFTYPE_P2P_DEVICE:
  339. return RSI_OPMODE_P2P_CLIENT;
  340. case NL80211_IFTYPE_P2P_CLIENT:
  341. return RSI_OPMODE_P2P_CLIENT;
  342. case NL80211_IFTYPE_P2P_GO:
  343. return RSI_OPMODE_P2P_GO;
  344. default:
  345. return RSI_OPMODE_UNSUPPORTED;
  346. }
  347. }
  348. /**
  349. * rsi_mac80211_add_interface() - This function is called when a netdevice
  350. * attached to the hardware is enabled.
  351. * @hw: Pointer to the ieee80211_hw structure.
  352. * @vif: Pointer to the ieee80211_vif structure.
  353. *
  354. * Return: ret: 0 on success, negative error code on failure.
  355. */
  356. static int rsi_mac80211_add_interface(struct ieee80211_hw *hw,
  357. struct ieee80211_vif *vif)
  358. {
  359. struct rsi_hw *adapter = hw->priv;
  360. struct rsi_common *common = adapter->priv;
  361. struct vif_priv *vif_info = (struct vif_priv *)vif->drv_priv;
  362. enum opmode intf_mode;
  363. enum vap_status vap_status;
  364. int vap_idx = -1, i;
  365. vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
  366. mutex_lock(&common->mutex);
  367. intf_mode = rsi_map_intf_mode(vif->type);
  368. if (intf_mode == RSI_OPMODE_UNSUPPORTED) {
  369. rsi_dbg(ERR_ZONE,
  370. "%s: Interface type %d not supported\n", __func__,
  371. vif->type);
  372. mutex_unlock(&common->mutex);
  373. return -EOPNOTSUPP;
  374. }
  375. if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) ||
  376. (vif->type == NL80211_IFTYPE_P2P_CLIENT) ||
  377. (vif->type == NL80211_IFTYPE_P2P_GO))
  378. common->p2p_enabled = true;
  379. /* Get free vap index */
  380. for (i = 0; i < RSI_MAX_VIFS; i++) {
  381. if (!adapter->vifs[i]) {
  382. vap_idx = i;
  383. break;
  384. }
  385. }
  386. if (vap_idx < 0) {
  387. rsi_dbg(ERR_ZONE, "Reject: Max VAPs reached\n");
  388. mutex_unlock(&common->mutex);
  389. return -EOPNOTSUPP;
  390. }
  391. vif_info->vap_id = vap_idx;
  392. adapter->vifs[vap_idx] = vif;
  393. adapter->sc_nvifs++;
  394. vap_status = VAP_ADD;
  395. if (rsi_set_vap_capabilities(common, intf_mode, vif->addr,
  396. vif_info->vap_id, vap_status)) {
  397. rsi_dbg(ERR_ZONE, "Failed to set VAP capabilities\n");
  398. mutex_unlock(&common->mutex);
  399. return -EINVAL;
  400. }
  401. if ((vif->type == NL80211_IFTYPE_AP) ||
  402. (vif->type == NL80211_IFTYPE_P2P_GO)) {
  403. rsi_send_rx_filter_frame(common, DISALLOW_BEACONS);
  404. common->min_rate = RSI_RATE_AUTO;
  405. for (i = 0; i < common->max_stations; i++)
  406. common->stations[i].sta = NULL;
  407. }
  408. mutex_unlock(&common->mutex);
  409. return 0;
  410. }
  411. /**
  412. * rsi_mac80211_remove_interface() - This function notifies driver that an
  413. * interface is going down.
  414. * @hw: Pointer to the ieee80211_hw structure.
  415. * @vif: Pointer to the ieee80211_vif structure.
  416. *
  417. * Return: None.
  418. */
  419. static void rsi_mac80211_remove_interface(struct ieee80211_hw *hw,
  420. struct ieee80211_vif *vif)
  421. {
  422. struct rsi_hw *adapter = hw->priv;
  423. struct rsi_common *common = adapter->priv;
  424. enum opmode opmode;
  425. int i;
  426. rsi_dbg(INFO_ZONE, "Remove Interface Called\n");
  427. mutex_lock(&common->mutex);
  428. if (adapter->sc_nvifs <= 0) {
  429. mutex_unlock(&common->mutex);
  430. return;
  431. }
  432. opmode = rsi_map_intf_mode(vif->type);
  433. if (opmode == RSI_OPMODE_UNSUPPORTED) {
  434. rsi_dbg(ERR_ZONE, "Opmode error : %d\n", opmode);
  435. mutex_unlock(&common->mutex);
  436. return;
  437. }
  438. for (i = 0; i < RSI_MAX_VIFS; i++) {
  439. if (!adapter->vifs[i])
  440. continue;
  441. if (vif == adapter->vifs[i]) {
  442. rsi_set_vap_capabilities(common, opmode, vif->addr,
  443. i, VAP_DELETE);
  444. adapter->sc_nvifs--;
  445. adapter->vifs[i] = NULL;
  446. }
  447. }
  448. mutex_unlock(&common->mutex);
  449. }
  450. /**
  451. * rsi_channel_change() - This function is a performs the checks
  452. * required for changing a channel and sets
  453. * the channel accordingly.
  454. * @hw: Pointer to the ieee80211_hw structure.
  455. *
  456. * Return: 0 on success, negative error code on failure.
  457. */
  458. static int rsi_channel_change(struct ieee80211_hw *hw)
  459. {
  460. struct rsi_hw *adapter = hw->priv;
  461. struct rsi_common *common = adapter->priv;
  462. int status = -EOPNOTSUPP;
  463. struct ieee80211_channel *curchan = hw->conf.chandef.chan;
  464. u16 channel = curchan->hw_value;
  465. struct ieee80211_vif *vif;
  466. struct ieee80211_bss_conf *bss;
  467. bool assoc = false;
  468. int i;
  469. rsi_dbg(INFO_ZONE,
  470. "%s: Set channel: %d MHz type: %d channel_no %d\n",
  471. __func__, curchan->center_freq,
  472. curchan->flags, channel);
  473. for (i = 0; i < RSI_MAX_VIFS; i++) {
  474. vif = adapter->vifs[i];
  475. if (!vif)
  476. continue;
  477. if (vif->type == NL80211_IFTYPE_STATION) {
  478. bss = &vif->bss_conf;
  479. if (bss->assoc) {
  480. assoc = true;
  481. break;
  482. }
  483. }
  484. }
  485. if (assoc) {
  486. if (!common->hw_data_qs_blocked &&
  487. (rsi_get_connected_channel(vif) != channel)) {
  488. rsi_dbg(INFO_ZONE, "blk data q %d\n", channel);
  489. if (!rsi_send_block_unblock_frame(common, true))
  490. common->hw_data_qs_blocked = true;
  491. }
  492. }
  493. status = rsi_band_check(common, curchan);
  494. if (!status)
  495. status = rsi_set_channel(adapter->priv, curchan);
  496. if (assoc) {
  497. if (common->hw_data_qs_blocked &&
  498. (rsi_get_connected_channel(vif) == channel)) {
  499. rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel);
  500. if (!rsi_send_block_unblock_frame(common, false))
  501. common->hw_data_qs_blocked = false;
  502. }
  503. }
  504. return status;
  505. }
  506. /**
  507. * rsi_config_power() - This function configures tx power to device
  508. * @hw: Pointer to the ieee80211_hw structure.
  509. *
  510. * Return: 0 on success, negative error code on failure.
  511. */
  512. static int rsi_config_power(struct ieee80211_hw *hw)
  513. {
  514. struct rsi_hw *adapter = hw->priv;
  515. struct rsi_common *common = adapter->priv;
  516. struct ieee80211_conf *conf = &hw->conf;
  517. if (adapter->sc_nvifs <= 0) {
  518. rsi_dbg(ERR_ZONE, "%s: No virtual interface found\n", __func__);
  519. return -EINVAL;
  520. }
  521. rsi_dbg(INFO_ZONE,
  522. "%s: Set tx power: %d dBM\n", __func__, conf->power_level);
  523. if (conf->power_level == common->tx_power)
  524. return 0;
  525. common->tx_power = conf->power_level;
  526. return rsi_send_radio_params_update(common);
  527. }
  528. /**
  529. * rsi_mac80211_config() - This function is a handler for configuration
  530. * requests. The stack calls this function to
  531. * change hardware configuration, e.g., channel.
  532. * @hw: Pointer to the ieee80211_hw structure.
  533. * @changed: Changed flags set.
  534. *
  535. * Return: 0 on success, negative error code on failure.
  536. */
  537. static int rsi_mac80211_config(struct ieee80211_hw *hw,
  538. u32 changed)
  539. {
  540. struct rsi_hw *adapter = hw->priv;
  541. struct rsi_common *common = adapter->priv;
  542. struct ieee80211_conf *conf = &hw->conf;
  543. int status = -EOPNOTSUPP;
  544. mutex_lock(&common->mutex);
  545. if (changed & IEEE80211_CONF_CHANGE_CHANNEL)
  546. status = rsi_channel_change(hw);
  547. /* tx power */
  548. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  549. rsi_dbg(INFO_ZONE, "%s: Configuring Power\n", __func__);
  550. status = rsi_config_power(hw);
  551. }
  552. /* Power save parameters */
  553. if (changed & IEEE80211_CONF_CHANGE_PS) {
  554. struct ieee80211_vif *vif, *sta_vif = NULL;
  555. unsigned long flags;
  556. int i, set_ps = 1;
  557. for (i = 0; i < RSI_MAX_VIFS; i++) {
  558. vif = adapter->vifs[i];
  559. if (!vif)
  560. continue;
  561. /* Don't go to power save if AP vap exists */
  562. if ((vif->type == NL80211_IFTYPE_AP) ||
  563. (vif->type == NL80211_IFTYPE_P2P_GO)) {
  564. set_ps = 0;
  565. break;
  566. }
  567. if ((vif->type == NL80211_IFTYPE_STATION ||
  568. vif->type == NL80211_IFTYPE_P2P_CLIENT) &&
  569. (!sta_vif || vif->bss_conf.assoc))
  570. sta_vif = vif;
  571. }
  572. if (set_ps && sta_vif) {
  573. spin_lock_irqsave(&adapter->ps_lock, flags);
  574. if (conf->flags & IEEE80211_CONF_PS)
  575. rsi_enable_ps(adapter, sta_vif);
  576. else
  577. rsi_disable_ps(adapter, sta_vif);
  578. spin_unlock_irqrestore(&adapter->ps_lock, flags);
  579. }
  580. }
  581. /* RTS threshold */
  582. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  583. rsi_dbg(INFO_ZONE, "RTS threshold\n");
  584. if ((common->rts_threshold) <= IEEE80211_MAX_RTS_THRESHOLD) {
  585. rsi_dbg(INFO_ZONE,
  586. "%s: Sending vap updates....\n", __func__);
  587. status = rsi_send_vap_dynamic_update(common);
  588. }
  589. }
  590. mutex_unlock(&common->mutex);
  591. return status;
  592. }
  593. /**
  594. * rsi_get_connected_channel() - This function is used to get the current
  595. * connected channel number.
  596. * @adapter: Pointer to the adapter structure.
  597. *
  598. * Return: Current connected AP's channel number is returned.
  599. */
  600. u16 rsi_get_connected_channel(struct ieee80211_vif *vif)
  601. {
  602. struct ieee80211_bss_conf *bss;
  603. struct ieee80211_channel *channel;
  604. if (!vif)
  605. return 0;
  606. bss = &vif->bss_conf;
  607. channel = bss->chandef.chan;
  608. if (!channel)
  609. return 0;
  610. return channel->hw_value;
  611. }
  612. static void rsi_switch_channel(struct rsi_hw *adapter,
  613. struct ieee80211_vif *vif)
  614. {
  615. struct rsi_common *common = adapter->priv;
  616. struct ieee80211_channel *channel;
  617. if (common->iface_down)
  618. return;
  619. if (!vif)
  620. return;
  621. channel = vif->bss_conf.chandef.chan;
  622. if (!channel)
  623. return;
  624. rsi_band_check(common, channel);
  625. rsi_set_channel(common, channel);
  626. rsi_dbg(INFO_ZONE, "Switched to channel - %d\n", channel->hw_value);
  627. }
  628. /**
  629. * rsi_mac80211_bss_info_changed() - This function is a handler for config
  630. * requests related to BSS parameters that
  631. * may vary during BSS's lifespan.
  632. * @hw: Pointer to the ieee80211_hw structure.
  633. * @vif: Pointer to the ieee80211_vif structure.
  634. * @bss_conf: Pointer to the ieee80211_bss_conf structure.
  635. * @changed: Changed flags set.
  636. *
  637. * Return: None.
  638. */
  639. static void rsi_mac80211_bss_info_changed(struct ieee80211_hw *hw,
  640. struct ieee80211_vif *vif,
  641. struct ieee80211_bss_conf *bss_conf,
  642. u32 changed)
  643. {
  644. struct rsi_hw *adapter = hw->priv;
  645. struct rsi_common *common = adapter->priv;
  646. struct ieee80211_bss_conf *bss = &vif->bss_conf;
  647. struct ieee80211_conf *conf = &hw->conf;
  648. u16 rx_filter_word = 0;
  649. mutex_lock(&common->mutex);
  650. if (changed & BSS_CHANGED_ASSOC) {
  651. rsi_dbg(INFO_ZONE, "%s: Changed Association status: %d\n",
  652. __func__, bss_conf->assoc);
  653. if (bss_conf->assoc) {
  654. /* Send the RX filter frame */
  655. rx_filter_word = (ALLOW_DATA_ASSOC_PEER |
  656. ALLOW_CTRL_ASSOC_PEER |
  657. ALLOW_MGMT_ASSOC_PEER);
  658. rsi_send_rx_filter_frame(common, rx_filter_word);
  659. }
  660. rsi_inform_bss_status(common,
  661. RSI_OPMODE_STA,
  662. bss_conf->assoc,
  663. bss_conf->bssid,
  664. bss_conf->qos,
  665. bss_conf->aid,
  666. NULL, 0,
  667. bss_conf->assoc_capability, vif);
  668. adapter->ps_info.dtim_interval_duration = bss->dtim_period;
  669. adapter->ps_info.listen_interval = conf->listen_interval;
  670. /* If U-APSD is updated, send ps parameters to firmware */
  671. if (bss->assoc) {
  672. if (common->uapsd_bitmap) {
  673. rsi_dbg(INFO_ZONE, "Configuring UAPSD\n");
  674. rsi_conf_uapsd(adapter, vif);
  675. }
  676. } else {
  677. common->uapsd_bitmap = 0;
  678. }
  679. }
  680. if (changed & BSS_CHANGED_CQM) {
  681. common->cqm_info.last_cqm_event_rssi = 0;
  682. common->cqm_info.rssi_thold = bss_conf->cqm_rssi_thold;
  683. common->cqm_info.rssi_hyst = bss_conf->cqm_rssi_hyst;
  684. rsi_dbg(INFO_ZONE, "RSSI throld & hysteresis are: %d %d\n",
  685. common->cqm_info.rssi_thold,
  686. common->cqm_info.rssi_hyst);
  687. }
  688. if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
  689. ((vif->type == NL80211_IFTYPE_AP) ||
  690. (vif->type == NL80211_IFTYPE_P2P_GO))) {
  691. if (bss->enable_beacon) {
  692. rsi_dbg(INFO_ZONE, "===> BEACON ENABLED <===\n");
  693. common->beacon_enabled = 1;
  694. } else {
  695. rsi_dbg(INFO_ZONE, "===> BEACON DISABLED <===\n");
  696. common->beacon_enabled = 0;
  697. }
  698. }
  699. mutex_unlock(&common->mutex);
  700. }
  701. /**
  702. * rsi_mac80211_conf_filter() - This function configure the device's RX filter.
  703. * @hw: Pointer to the ieee80211_hw structure.
  704. * @changed: Changed flags set.
  705. * @total_flags: Total initial flags set.
  706. * @multicast: Multicast.
  707. *
  708. * Return: None.
  709. */
  710. static void rsi_mac80211_conf_filter(struct ieee80211_hw *hw,
  711. u32 changed_flags,
  712. u32 *total_flags,
  713. u64 multicast)
  714. {
  715. /* Not doing much here as of now */
  716. *total_flags &= RSI_SUPP_FILTERS;
  717. }
  718. /**
  719. * rsi_mac80211_conf_tx() - This function configures TX queue parameters
  720. * (EDCF (aifs, cw_min, cw_max), bursting)
  721. * for a hardware TX queue.
  722. * @hw: Pointer to the ieee80211_hw structure
  723. * @vif: Pointer to the ieee80211_vif structure.
  724. * @queue: Queue number.
  725. * @params: Pointer to ieee80211_tx_queue_params structure.
  726. *
  727. * Return: 0 on success, negative error code on failure.
  728. */
  729. static int rsi_mac80211_conf_tx(struct ieee80211_hw *hw,
  730. struct ieee80211_vif *vif, u16 queue,
  731. const struct ieee80211_tx_queue_params *params)
  732. {
  733. struct rsi_hw *adapter = hw->priv;
  734. struct rsi_common *common = adapter->priv;
  735. u8 idx = 0;
  736. if (queue >= IEEE80211_NUM_ACS)
  737. return 0;
  738. rsi_dbg(INFO_ZONE,
  739. "%s: Conf queue %d, aifs: %d, cwmin: %d cwmax: %d, txop: %d\n",
  740. __func__, queue, params->aifs,
  741. params->cw_min, params->cw_max, params->txop);
  742. mutex_lock(&common->mutex);
  743. /* Map into the way the f/w expects */
  744. switch (queue) {
  745. case IEEE80211_AC_VO:
  746. idx = VO_Q;
  747. break;
  748. case IEEE80211_AC_VI:
  749. idx = VI_Q;
  750. break;
  751. case IEEE80211_AC_BE:
  752. idx = BE_Q;
  753. break;
  754. case IEEE80211_AC_BK:
  755. idx = BK_Q;
  756. break;
  757. default:
  758. idx = BE_Q;
  759. break;
  760. }
  761. memcpy(&common->edca_params[idx],
  762. params,
  763. sizeof(struct ieee80211_tx_queue_params));
  764. if (params->uapsd)
  765. common->uapsd_bitmap |= idx;
  766. else
  767. common->uapsd_bitmap &= (~idx);
  768. mutex_unlock(&common->mutex);
  769. return 0;
  770. }
  771. /**
  772. * rsi_hal_key_config() - This function loads the keys into the firmware.
  773. * @hw: Pointer to the ieee80211_hw structure.
  774. * @vif: Pointer to the ieee80211_vif structure.
  775. * @key: Pointer to the ieee80211_key_conf structure.
  776. *
  777. * Return: status: 0 on success, negative error codes on failure.
  778. */
  779. static int rsi_hal_key_config(struct ieee80211_hw *hw,
  780. struct ieee80211_vif *vif,
  781. struct ieee80211_key_conf *key,
  782. struct ieee80211_sta *sta)
  783. {
  784. struct rsi_hw *adapter = hw->priv;
  785. struct rsi_sta *rsta = NULL;
  786. int status;
  787. u8 key_type;
  788. s16 sta_id = 0;
  789. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  790. key_type = RSI_PAIRWISE_KEY;
  791. else
  792. key_type = RSI_GROUP_KEY;
  793. rsi_dbg(ERR_ZONE, "%s: Cipher 0x%x key_type: %d key_len: %d\n",
  794. __func__, key->cipher, key_type, key->keylen);
  795. if ((vif->type == NL80211_IFTYPE_AP) ||
  796. (vif->type == NL80211_IFTYPE_P2P_GO)) {
  797. if (sta) {
  798. rsta = rsi_find_sta(adapter->priv, sta->addr);
  799. if (rsta)
  800. sta_id = rsta->sta_id;
  801. }
  802. adapter->priv->key = key;
  803. } else {
  804. if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) ||
  805. (key->cipher == WLAN_CIPHER_SUITE_WEP40)) {
  806. status = rsi_hal_load_key(adapter->priv,
  807. key->key,
  808. key->keylen,
  809. RSI_PAIRWISE_KEY,
  810. key->keyidx,
  811. key->cipher,
  812. sta_id,
  813. vif);
  814. if (status)
  815. return status;
  816. }
  817. }
  818. status = rsi_hal_load_key(adapter->priv,
  819. key->key,
  820. key->keylen,
  821. key_type,
  822. key->keyidx,
  823. key->cipher,
  824. sta_id,
  825. vif);
  826. if (status)
  827. return status;
  828. if (vif->type == NL80211_IFTYPE_STATION && key->key &&
  829. (key->cipher == WLAN_CIPHER_SUITE_WEP104 ||
  830. key->cipher == WLAN_CIPHER_SUITE_WEP40)) {
  831. if (!rsi_send_block_unblock_frame(adapter->priv, false))
  832. adapter->priv->hw_data_qs_blocked = false;
  833. }
  834. return 0;
  835. }
  836. /**
  837. * rsi_mac80211_set_key() - This function sets type of key to be loaded.
  838. * @hw: Pointer to the ieee80211_hw structure.
  839. * @cmd: enum set_key_cmd.
  840. * @vif: Pointer to the ieee80211_vif structure.
  841. * @sta: Pointer to the ieee80211_sta structure.
  842. * @key: Pointer to the ieee80211_key_conf structure.
  843. *
  844. * Return: status: 0 on success, negative error code on failure.
  845. */
  846. static int rsi_mac80211_set_key(struct ieee80211_hw *hw,
  847. enum set_key_cmd cmd,
  848. struct ieee80211_vif *vif,
  849. struct ieee80211_sta *sta,
  850. struct ieee80211_key_conf *key)
  851. {
  852. struct rsi_hw *adapter = hw->priv;
  853. struct rsi_common *common = adapter->priv;
  854. struct security_info *secinfo = &common->secinfo;
  855. int status;
  856. mutex_lock(&common->mutex);
  857. switch (cmd) {
  858. case SET_KEY:
  859. secinfo->security_enable = true;
  860. status = rsi_hal_key_config(hw, vif, key, sta);
  861. if (status) {
  862. mutex_unlock(&common->mutex);
  863. return status;
  864. }
  865. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  866. secinfo->ptk_cipher = key->cipher;
  867. else
  868. secinfo->gtk_cipher = key->cipher;
  869. key->hw_key_idx = key->keyidx;
  870. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  871. rsi_dbg(ERR_ZONE, "%s: RSI set_key\n", __func__);
  872. break;
  873. case DISABLE_KEY:
  874. if (vif->type == NL80211_IFTYPE_STATION)
  875. secinfo->security_enable = false;
  876. rsi_dbg(ERR_ZONE, "%s: RSI del key\n", __func__);
  877. memset(key, 0, sizeof(struct ieee80211_key_conf));
  878. status = rsi_hal_key_config(hw, vif, key, sta);
  879. break;
  880. default:
  881. status = -EOPNOTSUPP;
  882. break;
  883. }
  884. mutex_unlock(&common->mutex);
  885. return status;
  886. }
  887. /**
  888. * rsi_mac80211_ampdu_action() - This function selects the AMPDU action for
  889. * the corresponding mlme_action flag and
  890. * informs the f/w regarding this.
  891. * @hw: Pointer to the ieee80211_hw structure.
  892. * @vif: Pointer to the ieee80211_vif structure.
  893. * @params: Pointer to A-MPDU action parameters
  894. *
  895. * Return: status: 0 on success, negative error code on failure.
  896. */
  897. static int rsi_mac80211_ampdu_action(struct ieee80211_hw *hw,
  898. struct ieee80211_vif *vif,
  899. struct ieee80211_ampdu_params *params)
  900. {
  901. int status = -EOPNOTSUPP;
  902. struct rsi_hw *adapter = hw->priv;
  903. struct rsi_common *common = adapter->priv;
  904. struct rsi_sta *rsta = NULL;
  905. u16 seq_no = 0, seq_start = 0;
  906. u8 ii = 0;
  907. struct ieee80211_sta *sta = params->sta;
  908. u8 sta_id = 0;
  909. enum ieee80211_ampdu_mlme_action action = params->action;
  910. u16 tid = params->tid;
  911. u16 *ssn = &params->ssn;
  912. u8 buf_size = params->buf_size;
  913. for (ii = 0; ii < RSI_MAX_VIFS; ii++) {
  914. if (vif == adapter->vifs[ii])
  915. break;
  916. }
  917. mutex_lock(&common->mutex);
  918. if (ssn != NULL)
  919. seq_no = *ssn;
  920. if ((vif->type == NL80211_IFTYPE_AP) ||
  921. (vif->type == NL80211_IFTYPE_P2P_GO)) {
  922. rsta = rsi_find_sta(common, sta->addr);
  923. if (!rsta) {
  924. rsi_dbg(ERR_ZONE, "No station mapped\n");
  925. status = 0;
  926. goto unlock;
  927. }
  928. sta_id = rsta->sta_id;
  929. }
  930. rsi_dbg(INFO_ZONE,
  931. "%s: AMPDU action tid=%d ssn=0x%x, buf_size=%d sta_id=%d\n",
  932. __func__, tid, seq_no, buf_size, sta_id);
  933. switch (action) {
  934. case IEEE80211_AMPDU_RX_START:
  935. status = rsi_send_aggregation_params_frame(common,
  936. tid,
  937. seq_no,
  938. buf_size,
  939. STA_RX_ADDBA_DONE,
  940. sta_id);
  941. break;
  942. case IEEE80211_AMPDU_RX_STOP:
  943. status = rsi_send_aggregation_params_frame(common,
  944. tid,
  945. 0,
  946. buf_size,
  947. STA_RX_DELBA,
  948. sta_id);
  949. break;
  950. case IEEE80211_AMPDU_TX_START:
  951. if ((vif->type == NL80211_IFTYPE_STATION) ||
  952. (vif->type == NL80211_IFTYPE_P2P_CLIENT))
  953. common->vif_info[ii].seq_start = seq_no;
  954. else if ((vif->type == NL80211_IFTYPE_AP) ||
  955. (vif->type == NL80211_IFTYPE_P2P_GO))
  956. rsta->seq_start[tid] = seq_no;
  957. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  958. status = 0;
  959. break;
  960. case IEEE80211_AMPDU_TX_STOP_CONT:
  961. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  962. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  963. status = rsi_send_aggregation_params_frame(common,
  964. tid,
  965. seq_no,
  966. buf_size,
  967. STA_TX_DELBA,
  968. sta_id);
  969. if (!status)
  970. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  971. break;
  972. case IEEE80211_AMPDU_TX_OPERATIONAL:
  973. if ((vif->type == NL80211_IFTYPE_STATION) ||
  974. (vif->type == NL80211_IFTYPE_P2P_CLIENT))
  975. seq_start = common->vif_info[ii].seq_start;
  976. else if ((vif->type == NL80211_IFTYPE_AP) ||
  977. (vif->type == NL80211_IFTYPE_P2P_GO))
  978. seq_start = rsta->seq_start[tid];
  979. status = rsi_send_aggregation_params_frame(common,
  980. tid,
  981. seq_start,
  982. buf_size,
  983. STA_TX_ADDBA_DONE,
  984. sta_id);
  985. break;
  986. default:
  987. rsi_dbg(ERR_ZONE, "%s: Unknown AMPDU action\n", __func__);
  988. break;
  989. }
  990. unlock:
  991. mutex_unlock(&common->mutex);
  992. return status;
  993. }
  994. /**
  995. * rsi_mac80211_set_rts_threshold() - This function sets rts threshold value.
  996. * @hw: Pointer to the ieee80211_hw structure.
  997. * @value: Rts threshold value.
  998. *
  999. * Return: 0 on success.
  1000. */
  1001. static int rsi_mac80211_set_rts_threshold(struct ieee80211_hw *hw,
  1002. u32 value)
  1003. {
  1004. struct rsi_hw *adapter = hw->priv;
  1005. struct rsi_common *common = adapter->priv;
  1006. mutex_lock(&common->mutex);
  1007. common->rts_threshold = value;
  1008. mutex_unlock(&common->mutex);
  1009. return 0;
  1010. }
  1011. /**
  1012. * rsi_mac80211_set_rate_mask() - This function sets bitrate_mask to be used.
  1013. * @hw: Pointer to the ieee80211_hw structure
  1014. * @vif: Pointer to the ieee80211_vif structure.
  1015. * @mask: Pointer to the cfg80211_bitrate_mask structure.
  1016. *
  1017. * Return: 0 on success.
  1018. */
  1019. static int rsi_mac80211_set_rate_mask(struct ieee80211_hw *hw,
  1020. struct ieee80211_vif *vif,
  1021. const struct cfg80211_bitrate_mask *mask)
  1022. {
  1023. struct rsi_hw *adapter = hw->priv;
  1024. struct rsi_common *common = adapter->priv;
  1025. enum nl80211_band band = hw->conf.chandef.chan->band;
  1026. mutex_lock(&common->mutex);
  1027. common->fixedrate_mask[band] = 0;
  1028. if (mask->control[band].legacy == 0xfff) {
  1029. common->fixedrate_mask[band] =
  1030. (mask->control[band].ht_mcs[0] << 12);
  1031. } else {
  1032. common->fixedrate_mask[band] =
  1033. mask->control[band].legacy;
  1034. }
  1035. mutex_unlock(&common->mutex);
  1036. return 0;
  1037. }
  1038. /**
  1039. * rsi_perform_cqm() - This function performs cqm.
  1040. * @common: Pointer to the driver private structure.
  1041. * @bssid: pointer to the bssid.
  1042. * @rssi: RSSI value.
  1043. */
  1044. static void rsi_perform_cqm(struct rsi_common *common,
  1045. u8 *bssid,
  1046. s8 rssi,
  1047. struct ieee80211_vif *vif)
  1048. {
  1049. s8 last_event = common->cqm_info.last_cqm_event_rssi;
  1050. int thold = common->cqm_info.rssi_thold;
  1051. u32 hyst = common->cqm_info.rssi_hyst;
  1052. enum nl80211_cqm_rssi_threshold_event event;
  1053. if (rssi < thold && (last_event == 0 || rssi < (last_event - hyst)))
  1054. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  1055. else if (rssi > thold &&
  1056. (last_event == 0 || rssi > (last_event + hyst)))
  1057. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  1058. else
  1059. return;
  1060. common->cqm_info.last_cqm_event_rssi = rssi;
  1061. rsi_dbg(INFO_ZONE, "CQM: Notifying event: %d\n", event);
  1062. ieee80211_cqm_rssi_notify(vif, event, rssi, GFP_KERNEL);
  1063. return;
  1064. }
  1065. /**
  1066. * rsi_fill_rx_status() - This function fills rx status in
  1067. * ieee80211_rx_status structure.
  1068. * @hw: Pointer to the ieee80211_hw structure.
  1069. * @skb: Pointer to the socket buffer structure.
  1070. * @common: Pointer to the driver private structure.
  1071. * @rxs: Pointer to the ieee80211_rx_status structure.
  1072. *
  1073. * Return: None.
  1074. */
  1075. static void rsi_fill_rx_status(struct ieee80211_hw *hw,
  1076. struct sk_buff *skb,
  1077. struct rsi_common *common,
  1078. struct ieee80211_rx_status *rxs)
  1079. {
  1080. struct rsi_hw *adapter = common->priv;
  1081. struct ieee80211_vif *vif;
  1082. struct ieee80211_bss_conf *bss = NULL;
  1083. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1084. struct skb_info *rx_params = (struct skb_info *)info->driver_data;
  1085. struct ieee80211_hdr *hdr;
  1086. char rssi = rx_params->rssi;
  1087. u8 hdrlen = 0;
  1088. u8 channel = rx_params->channel;
  1089. s32 freq;
  1090. int i;
  1091. hdr = ((struct ieee80211_hdr *)(skb->data));
  1092. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1093. memset(info, 0, sizeof(struct ieee80211_tx_info));
  1094. rxs->signal = -(rssi);
  1095. rxs->band = common->band;
  1096. freq = ieee80211_channel_to_frequency(channel, rxs->band);
  1097. if (freq)
  1098. rxs->freq = freq;
  1099. if (ieee80211_has_protected(hdr->frame_control)) {
  1100. if (rsi_is_cipher_wep(common)) {
  1101. memmove(skb->data + 4, skb->data, hdrlen);
  1102. skb_pull(skb, 4);
  1103. } else {
  1104. memmove(skb->data + 8, skb->data, hdrlen);
  1105. skb_pull(skb, 8);
  1106. rxs->flag |= RX_FLAG_MMIC_STRIPPED;
  1107. }
  1108. rxs->flag |= RX_FLAG_DECRYPTED;
  1109. rxs->flag |= RX_FLAG_IV_STRIPPED;
  1110. }
  1111. for (i = 0; i < RSI_MAX_VIFS; i++) {
  1112. vif = adapter->vifs[i];
  1113. if (!vif)
  1114. continue;
  1115. if (vif->type == NL80211_IFTYPE_STATION) {
  1116. bss = &vif->bss_conf;
  1117. break;
  1118. }
  1119. }
  1120. if (!bss)
  1121. return;
  1122. /* CQM only for connected AP beacons, the RSSI is a weighted avg */
  1123. if (bss->assoc && !(memcmp(bss->bssid, hdr->addr2, ETH_ALEN))) {
  1124. if (ieee80211_is_beacon(hdr->frame_control))
  1125. rsi_perform_cqm(common, hdr->addr2, rxs->signal, vif);
  1126. }
  1127. return;
  1128. }
  1129. /**
  1130. * rsi_indicate_pkt_to_os() - This function sends recieved packet to mac80211.
  1131. * @common: Pointer to the driver private structure.
  1132. * @skb: Pointer to the socket buffer structure.
  1133. *
  1134. * Return: None.
  1135. */
  1136. void rsi_indicate_pkt_to_os(struct rsi_common *common,
  1137. struct sk_buff *skb)
  1138. {
  1139. struct rsi_hw *adapter = common->priv;
  1140. struct ieee80211_hw *hw = adapter->hw;
  1141. struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
  1142. if ((common->iface_down) || (!adapter->sc_nvifs)) {
  1143. dev_kfree_skb(skb);
  1144. return;
  1145. }
  1146. /* filling in the ieee80211_rx_status flags */
  1147. rsi_fill_rx_status(hw, skb, common, rx_status);
  1148. ieee80211_rx_irqsafe(hw, skb);
  1149. }
  1150. static void rsi_set_min_rate(struct ieee80211_hw *hw,
  1151. struct ieee80211_sta *sta,
  1152. struct rsi_common *common)
  1153. {
  1154. u8 band = hw->conf.chandef.chan->band;
  1155. u8 ii;
  1156. u32 rate_bitmap;
  1157. bool matched = false;
  1158. common->bitrate_mask[band] = sta->supp_rates[band];
  1159. rate_bitmap = (common->fixedrate_mask[band] & sta->supp_rates[band]);
  1160. if (rate_bitmap & 0xfff) {
  1161. /* Find out the min rate */
  1162. for (ii = 0; ii < ARRAY_SIZE(rsi_rates); ii++) {
  1163. if (rate_bitmap & BIT(ii)) {
  1164. common->min_rate = rsi_rates[ii].hw_value;
  1165. matched = true;
  1166. break;
  1167. }
  1168. }
  1169. }
  1170. common->vif_info[0].is_ht = sta->ht_cap.ht_supported;
  1171. if ((common->vif_info[0].is_ht) && (rate_bitmap >> 12)) {
  1172. for (ii = 0; ii < ARRAY_SIZE(rsi_mcsrates); ii++) {
  1173. if ((rate_bitmap >> 12) & BIT(ii)) {
  1174. common->min_rate = rsi_mcsrates[ii];
  1175. matched = true;
  1176. break;
  1177. }
  1178. }
  1179. }
  1180. if (!matched)
  1181. common->min_rate = 0xffff;
  1182. }
  1183. /**
  1184. * rsi_mac80211_sta_add() - This function notifies driver about a peer getting
  1185. * connected.
  1186. * @hw: pointer to the ieee80211_hw structure.
  1187. * @vif: Pointer to the ieee80211_vif structure.
  1188. * @sta: Pointer to the ieee80211_sta structure.
  1189. *
  1190. * Return: 0 on success, negative error codes on failure.
  1191. */
  1192. static int rsi_mac80211_sta_add(struct ieee80211_hw *hw,
  1193. struct ieee80211_vif *vif,
  1194. struct ieee80211_sta *sta)
  1195. {
  1196. struct rsi_hw *adapter = hw->priv;
  1197. struct rsi_common *common = adapter->priv;
  1198. bool sta_exist = false;
  1199. struct rsi_sta *rsta;
  1200. int status = 0;
  1201. rsi_dbg(INFO_ZONE, "Station Add: %pM\n", sta->addr);
  1202. mutex_lock(&common->mutex);
  1203. if ((vif->type == NL80211_IFTYPE_AP) ||
  1204. (vif->type == NL80211_IFTYPE_P2P_GO)) {
  1205. u8 cnt;
  1206. int sta_idx = -1;
  1207. int free_index = -1;
  1208. /* Check if max stations reached */
  1209. if (common->num_stations >= common->max_stations) {
  1210. rsi_dbg(ERR_ZONE, "Reject: Max Stations exists\n");
  1211. status = -EOPNOTSUPP;
  1212. goto unlock;
  1213. }
  1214. for (cnt = 0; cnt < common->max_stations; cnt++) {
  1215. rsta = &common->stations[cnt];
  1216. if (!rsta->sta) {
  1217. if (free_index < 0)
  1218. free_index = cnt;
  1219. continue;
  1220. }
  1221. if (!memcmp(rsta->sta->addr, sta->addr, ETH_ALEN)) {
  1222. rsi_dbg(INFO_ZONE, "Station exists\n");
  1223. sta_idx = cnt;
  1224. sta_exist = true;
  1225. break;
  1226. }
  1227. }
  1228. if (!sta_exist) {
  1229. if (free_index >= 0)
  1230. sta_idx = free_index;
  1231. }
  1232. if (sta_idx < 0) {
  1233. rsi_dbg(ERR_ZONE,
  1234. "%s: Some problem reaching here...\n",
  1235. __func__);
  1236. status = -EINVAL;
  1237. goto unlock;
  1238. }
  1239. rsta = &common->stations[sta_idx];
  1240. rsta->sta = sta;
  1241. rsta->sta_id = sta_idx;
  1242. for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++)
  1243. rsta->start_tx_aggr[cnt] = false;
  1244. for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++)
  1245. rsta->seq_start[cnt] = 0;
  1246. if (!sta_exist) {
  1247. rsi_dbg(INFO_ZONE, "New Station\n");
  1248. /* Send peer notify to device */
  1249. rsi_dbg(INFO_ZONE, "Indicate bss status to device\n");
  1250. rsi_inform_bss_status(common, RSI_OPMODE_AP, 1,
  1251. sta->addr, sta->wme, sta->aid,
  1252. sta, sta_idx, 0, vif);
  1253. if (common->key) {
  1254. struct ieee80211_key_conf *key = common->key;
  1255. if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) ||
  1256. (key->cipher == WLAN_CIPHER_SUITE_WEP40))
  1257. rsi_hal_load_key(adapter->priv,
  1258. key->key,
  1259. key->keylen,
  1260. RSI_PAIRWISE_KEY,
  1261. key->keyidx,
  1262. key->cipher,
  1263. sta_idx,
  1264. vif);
  1265. }
  1266. common->num_stations++;
  1267. }
  1268. }
  1269. if ((vif->type == NL80211_IFTYPE_STATION) ||
  1270. (vif->type == NL80211_IFTYPE_P2P_CLIENT)) {
  1271. rsi_set_min_rate(hw, sta, common);
  1272. if (sta->ht_cap.ht_supported) {
  1273. common->vif_info[0].is_ht = true;
  1274. common->bitrate_mask[NL80211_BAND_2GHZ] =
  1275. sta->supp_rates[NL80211_BAND_2GHZ];
  1276. if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ||
  1277. (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
  1278. common->vif_info[0].sgi = true;
  1279. ieee80211_start_tx_ba_session(sta, 0, 0);
  1280. }
  1281. }
  1282. unlock:
  1283. mutex_unlock(&common->mutex);
  1284. return status;
  1285. }
  1286. /**
  1287. * rsi_mac80211_sta_remove() - This function notifies driver about a peer
  1288. * getting disconnected.
  1289. * @hw: Pointer to the ieee80211_hw structure.
  1290. * @vif: Pointer to the ieee80211_vif structure.
  1291. * @sta: Pointer to the ieee80211_sta structure.
  1292. *
  1293. * Return: 0 on success, negative error codes on failure.
  1294. */
  1295. static int rsi_mac80211_sta_remove(struct ieee80211_hw *hw,
  1296. struct ieee80211_vif *vif,
  1297. struct ieee80211_sta *sta)
  1298. {
  1299. struct rsi_hw *adapter = hw->priv;
  1300. struct rsi_common *common = adapter->priv;
  1301. struct ieee80211_bss_conf *bss = &vif->bss_conf;
  1302. struct rsi_sta *rsta;
  1303. rsi_dbg(INFO_ZONE, "Station Remove: %pM\n", sta->addr);
  1304. mutex_lock(&common->mutex);
  1305. if ((vif->type == NL80211_IFTYPE_AP) ||
  1306. (vif->type == NL80211_IFTYPE_P2P_GO)) {
  1307. u8 sta_idx, cnt;
  1308. /* Send peer notify to device */
  1309. rsi_dbg(INFO_ZONE, "Indicate bss status to device\n");
  1310. for (sta_idx = 0; sta_idx < common->max_stations; sta_idx++) {
  1311. rsta = &common->stations[sta_idx];
  1312. if (!rsta->sta)
  1313. continue;
  1314. if (!memcmp(rsta->sta->addr, sta->addr, ETH_ALEN)) {
  1315. rsi_inform_bss_status(common, RSI_OPMODE_AP, 0,
  1316. sta->addr, sta->wme,
  1317. sta->aid, sta, sta_idx,
  1318. 0, vif);
  1319. rsta->sta = NULL;
  1320. rsta->sta_id = -1;
  1321. for (cnt = 0; cnt < IEEE80211_NUM_TIDS; cnt++)
  1322. rsta->start_tx_aggr[cnt] = false;
  1323. if (common->num_stations > 0)
  1324. common->num_stations--;
  1325. break;
  1326. }
  1327. }
  1328. if (sta_idx >= common->max_stations)
  1329. rsi_dbg(ERR_ZONE, "%s: No station found\n", __func__);
  1330. }
  1331. if ((vif->type == NL80211_IFTYPE_STATION) ||
  1332. (vif->type == NL80211_IFTYPE_P2P_CLIENT)) {
  1333. /* Resetting all the fields to default values */
  1334. memcpy((u8 *)bss->bssid, (u8 *)sta->addr, ETH_ALEN);
  1335. bss->qos = sta->wme;
  1336. common->bitrate_mask[NL80211_BAND_2GHZ] = 0;
  1337. common->bitrate_mask[NL80211_BAND_5GHZ] = 0;
  1338. common->min_rate = 0xffff;
  1339. common->vif_info[0].is_ht = false;
  1340. common->vif_info[0].sgi = false;
  1341. common->vif_info[0].seq_start = 0;
  1342. common->secinfo.ptk_cipher = 0;
  1343. common->secinfo.gtk_cipher = 0;
  1344. if (!common->iface_down)
  1345. rsi_send_rx_filter_frame(common, 0);
  1346. }
  1347. mutex_unlock(&common->mutex);
  1348. return 0;
  1349. }
  1350. /**
  1351. * rsi_mac80211_set_antenna() - This function is used to configure
  1352. * tx and rx antennas.
  1353. * @hw: Pointer to the ieee80211_hw structure.
  1354. * @tx_ant: Bitmap for tx antenna
  1355. * @rx_ant: Bitmap for rx antenna
  1356. *
  1357. * Return: 0 on success, Negative error code on failure.
  1358. */
  1359. static int rsi_mac80211_set_antenna(struct ieee80211_hw *hw,
  1360. u32 tx_ant, u32 rx_ant)
  1361. {
  1362. struct rsi_hw *adapter = hw->priv;
  1363. struct rsi_common *common = adapter->priv;
  1364. u8 antenna = 0;
  1365. if (tx_ant > 1 || rx_ant > 1) {
  1366. rsi_dbg(ERR_ZONE,
  1367. "Invalid antenna selection (tx: %d, rx:%d)\n",
  1368. tx_ant, rx_ant);
  1369. rsi_dbg(ERR_ZONE,
  1370. "Use 0 for int_ant, 1 for ext_ant\n");
  1371. return -EINVAL;
  1372. }
  1373. rsi_dbg(INFO_ZONE, "%s: Antenna map Tx %x Rx %d\n",
  1374. __func__, tx_ant, rx_ant);
  1375. mutex_lock(&common->mutex);
  1376. antenna = tx_ant ? ANTENNA_SEL_UFL : ANTENNA_SEL_INT;
  1377. if (common->ant_in_use != antenna)
  1378. if (rsi_set_antenna(common, antenna))
  1379. goto fail_set_antenna;
  1380. rsi_dbg(INFO_ZONE, "(%s) Antenna path configured successfully\n",
  1381. tx_ant ? "UFL" : "INT");
  1382. common->ant_in_use = antenna;
  1383. mutex_unlock(&common->mutex);
  1384. return 0;
  1385. fail_set_antenna:
  1386. rsi_dbg(ERR_ZONE, "%s: Failed.\n", __func__);
  1387. mutex_unlock(&common->mutex);
  1388. return -EINVAL;
  1389. }
  1390. /**
  1391. * rsi_mac80211_get_antenna() - This function is used to configure
  1392. * tx and rx antennas.
  1393. *
  1394. * @hw: Pointer to the ieee80211_hw structure.
  1395. * @tx_ant: Bitmap for tx antenna
  1396. * @rx_ant: Bitmap for rx antenna
  1397. *
  1398. * Return: 0 on success, negative error codes on failure.
  1399. */
  1400. static int rsi_mac80211_get_antenna(struct ieee80211_hw *hw,
  1401. u32 *tx_ant, u32 *rx_ant)
  1402. {
  1403. struct rsi_hw *adapter = hw->priv;
  1404. struct rsi_common *common = adapter->priv;
  1405. mutex_lock(&common->mutex);
  1406. *tx_ant = (common->ant_in_use == ANTENNA_SEL_UFL) ? 1 : 0;
  1407. *rx_ant = 0;
  1408. mutex_unlock(&common->mutex);
  1409. return 0;
  1410. }
  1411. static int rsi_map_region_code(enum nl80211_dfs_regions region_code)
  1412. {
  1413. switch (region_code) {
  1414. case NL80211_DFS_FCC:
  1415. return RSI_REGION_FCC;
  1416. case NL80211_DFS_ETSI:
  1417. return RSI_REGION_ETSI;
  1418. case NL80211_DFS_JP:
  1419. return RSI_REGION_TELEC;
  1420. case NL80211_DFS_UNSET:
  1421. return RSI_REGION_WORLD;
  1422. }
  1423. return RSI_REGION_WORLD;
  1424. }
  1425. static void rsi_reg_notify(struct wiphy *wiphy,
  1426. struct regulatory_request *request)
  1427. {
  1428. struct ieee80211_supported_band *sband;
  1429. struct ieee80211_channel *ch;
  1430. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  1431. struct rsi_hw * adapter = hw->priv;
  1432. struct rsi_common *common = adapter->priv;
  1433. int i;
  1434. mutex_lock(&common->mutex);
  1435. rsi_dbg(INFO_ZONE, "country = %s dfs_region = %d\n",
  1436. request->alpha2, request->dfs_region);
  1437. if (common->num_supp_bands > 1) {
  1438. sband = wiphy->bands[NL80211_BAND_5GHZ];
  1439. for (i = 0; i < sband->n_channels; i++) {
  1440. ch = &sband->channels[i];
  1441. if (ch->flags & IEEE80211_CHAN_DISABLED)
  1442. continue;
  1443. if (ch->flags & IEEE80211_CHAN_RADAR)
  1444. ch->flags |= IEEE80211_CHAN_NO_IR;
  1445. }
  1446. }
  1447. adapter->dfs_region = rsi_map_region_code(request->dfs_region);
  1448. rsi_dbg(INFO_ZONE, "RSI region code = %d\n", adapter->dfs_region);
  1449. adapter->country[0] = request->alpha2[0];
  1450. adapter->country[1] = request->alpha2[1];
  1451. mutex_unlock(&common->mutex);
  1452. }
  1453. static void rsi_mac80211_rfkill_poll(struct ieee80211_hw *hw)
  1454. {
  1455. struct rsi_hw *adapter = hw->priv;
  1456. struct rsi_common *common = adapter->priv;
  1457. mutex_lock(&common->mutex);
  1458. if (common->fsm_state != FSM_MAC_INIT_DONE)
  1459. wiphy_rfkill_set_hw_state(hw->wiphy, true);
  1460. else
  1461. wiphy_rfkill_set_hw_state(hw->wiphy, false);
  1462. mutex_unlock(&common->mutex);
  1463. }
  1464. static void rsi_resume_conn_channel(struct rsi_common *common)
  1465. {
  1466. struct rsi_hw *adapter = common->priv;
  1467. struct ieee80211_vif *vif;
  1468. int cnt;
  1469. for (cnt = 0; cnt < RSI_MAX_VIFS; cnt++) {
  1470. vif = adapter->vifs[cnt];
  1471. if (!vif)
  1472. continue;
  1473. if ((vif->type == NL80211_IFTYPE_AP) ||
  1474. (vif->type == NL80211_IFTYPE_P2P_GO)) {
  1475. rsi_switch_channel(adapter, vif);
  1476. break;
  1477. }
  1478. if (((vif->type == NL80211_IFTYPE_STATION) ||
  1479. (vif->type == NL80211_IFTYPE_P2P_CLIENT)) &&
  1480. vif->bss_conf.assoc) {
  1481. rsi_switch_channel(adapter, vif);
  1482. break;
  1483. }
  1484. }
  1485. }
  1486. void rsi_roc_timeout(struct timer_list *t)
  1487. {
  1488. struct rsi_common *common = from_timer(common, t, roc_timer);
  1489. rsi_dbg(INFO_ZONE, "Remain on channel expired\n");
  1490. mutex_lock(&common->mutex);
  1491. ieee80211_remain_on_channel_expired(common->priv->hw);
  1492. if (timer_pending(&common->roc_timer))
  1493. del_timer(&common->roc_timer);
  1494. rsi_resume_conn_channel(common);
  1495. mutex_unlock(&common->mutex);
  1496. }
  1497. static int rsi_mac80211_roc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1498. struct ieee80211_channel *chan, int duration,
  1499. enum ieee80211_roc_type type)
  1500. {
  1501. struct rsi_hw *adapter = (struct rsi_hw *)hw->priv;
  1502. struct rsi_common *common = (struct rsi_common *)adapter->priv;
  1503. int status = 0;
  1504. rsi_dbg(INFO_ZONE, "***** Remain on channel *****\n");
  1505. mutex_lock(&common->mutex);
  1506. rsi_dbg(INFO_ZONE, "%s: channel: %d duration: %dms\n",
  1507. __func__, chan->hw_value, duration);
  1508. if (timer_pending(&common->roc_timer)) {
  1509. rsi_dbg(INFO_ZONE, "Stop on-going ROC\n");
  1510. del_timer(&common->roc_timer);
  1511. }
  1512. common->roc_timer.expires = msecs_to_jiffies(duration) + jiffies;
  1513. add_timer(&common->roc_timer);
  1514. /* Configure band */
  1515. if (rsi_band_check(common, chan)) {
  1516. rsi_dbg(ERR_ZONE, "Failed to set band\n");
  1517. status = -EINVAL;
  1518. goto out;
  1519. }
  1520. /* Configure channel */
  1521. if (rsi_set_channel(common, chan)) {
  1522. rsi_dbg(ERR_ZONE, "Failed to set the channel\n");
  1523. status = -EINVAL;
  1524. goto out;
  1525. }
  1526. common->roc_vif = vif;
  1527. ieee80211_ready_on_channel(hw);
  1528. rsi_dbg(INFO_ZONE, "%s: Ready on channel :%d\n",
  1529. __func__, chan->hw_value);
  1530. out:
  1531. mutex_unlock(&common->mutex);
  1532. return status;
  1533. }
  1534. static int rsi_mac80211_cancel_roc(struct ieee80211_hw *hw)
  1535. {
  1536. struct rsi_hw *adapter = hw->priv;
  1537. struct rsi_common *common = adapter->priv;
  1538. rsi_dbg(INFO_ZONE, "Cancel remain on channel\n");
  1539. mutex_lock(&common->mutex);
  1540. if (!timer_pending(&common->roc_timer)) {
  1541. mutex_unlock(&common->mutex);
  1542. return 0;
  1543. }
  1544. del_timer(&common->roc_timer);
  1545. rsi_resume_conn_channel(common);
  1546. mutex_unlock(&common->mutex);
  1547. return 0;
  1548. }
  1549. #ifdef CONFIG_PM
  1550. static const struct wiphy_wowlan_support rsi_wowlan_support = {
  1551. .flags = WIPHY_WOWLAN_ANY |
  1552. WIPHY_WOWLAN_MAGIC_PKT |
  1553. WIPHY_WOWLAN_DISCONNECT |
  1554. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  1555. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  1556. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  1557. WIPHY_WOWLAN_4WAY_HANDSHAKE,
  1558. };
  1559. static u16 rsi_wow_map_triggers(struct rsi_common *common,
  1560. struct cfg80211_wowlan *wowlan)
  1561. {
  1562. u16 wow_triggers = 0;
  1563. rsi_dbg(INFO_ZONE, "Mapping wowlan triggers\n");
  1564. if (wowlan->any)
  1565. wow_triggers |= RSI_WOW_ANY;
  1566. if (wowlan->magic_pkt)
  1567. wow_triggers |= RSI_WOW_MAGIC_PKT;
  1568. if (wowlan->disconnect)
  1569. wow_triggers |= RSI_WOW_DISCONNECT;
  1570. if (wowlan->gtk_rekey_failure || wowlan->eap_identity_req ||
  1571. wowlan->four_way_handshake)
  1572. wow_triggers |= RSI_WOW_GTK_REKEY;
  1573. return wow_triggers;
  1574. }
  1575. int rsi_config_wowlan(struct rsi_hw *adapter, struct cfg80211_wowlan *wowlan)
  1576. {
  1577. struct rsi_common *common = adapter->priv;
  1578. u16 triggers = 0;
  1579. u16 rx_filter_word = 0;
  1580. struct ieee80211_bss_conf *bss = NULL;
  1581. rsi_dbg(INFO_ZONE, "Config WoWLAN to device\n");
  1582. if (!adapter->vifs[0])
  1583. return -EINVAL;
  1584. bss = &adapter->vifs[0]->bss_conf;
  1585. if (WARN_ON(!wowlan)) {
  1586. rsi_dbg(ERR_ZONE, "WoW triggers not enabled\n");
  1587. return -EINVAL;
  1588. }
  1589. common->wow_flags |= RSI_WOW_ENABLED;
  1590. triggers = rsi_wow_map_triggers(common, wowlan);
  1591. if (!triggers) {
  1592. rsi_dbg(ERR_ZONE, "%s:No valid WoW triggers\n", __func__);
  1593. return -EINVAL;
  1594. }
  1595. if (!bss->assoc) {
  1596. rsi_dbg(ERR_ZONE,
  1597. "Cannot configure WoWLAN (Station not connected)\n");
  1598. common->wow_flags |= RSI_WOW_NO_CONNECTION;
  1599. return 0;
  1600. }
  1601. rsi_dbg(INFO_ZONE, "TRIGGERS %x\n", triggers);
  1602. rsi_send_wowlan_request(common, triggers, 1);
  1603. /**
  1604. * Increase the beacon_miss threshold & keep-alive timers in
  1605. * vap_update frame
  1606. */
  1607. rsi_send_vap_dynamic_update(common);
  1608. rx_filter_word = (ALLOW_DATA_ASSOC_PEER | DISALLOW_BEACONS);
  1609. rsi_send_rx_filter_frame(common, rx_filter_word);
  1610. return 0;
  1611. }
  1612. EXPORT_SYMBOL(rsi_config_wowlan);
  1613. static int rsi_mac80211_suspend(struct ieee80211_hw *hw,
  1614. struct cfg80211_wowlan *wowlan)
  1615. {
  1616. struct rsi_hw *adapter = hw->priv;
  1617. struct rsi_common *common = adapter->priv;
  1618. rsi_dbg(INFO_ZONE, "%s: mac80211 suspend\n", __func__);
  1619. mutex_lock(&common->mutex);
  1620. if (rsi_config_wowlan(adapter, wowlan)) {
  1621. rsi_dbg(ERR_ZONE, "Failed to configure WoWLAN\n");
  1622. mutex_unlock(&common->mutex);
  1623. return 1;
  1624. }
  1625. mutex_unlock(&common->mutex);
  1626. return 0;
  1627. }
  1628. static int rsi_mac80211_resume(struct ieee80211_hw *hw)
  1629. {
  1630. u16 rx_filter_word = 0;
  1631. struct rsi_hw *adapter = hw->priv;
  1632. struct rsi_common *common = adapter->priv;
  1633. common->wow_flags = 0;
  1634. rsi_dbg(INFO_ZONE, "%s: mac80211 resume\n", __func__);
  1635. if (common->hibernate_resume)
  1636. return 0;
  1637. mutex_lock(&common->mutex);
  1638. rsi_send_wowlan_request(common, 0, 0);
  1639. rx_filter_word = (ALLOW_DATA_ASSOC_PEER | ALLOW_CTRL_ASSOC_PEER |
  1640. ALLOW_MGMT_ASSOC_PEER);
  1641. rsi_send_rx_filter_frame(common, rx_filter_word);
  1642. mutex_unlock(&common->mutex);
  1643. return 0;
  1644. }
  1645. #endif
  1646. static const struct ieee80211_ops mac80211_ops = {
  1647. .tx = rsi_mac80211_tx,
  1648. .start = rsi_mac80211_start,
  1649. .stop = rsi_mac80211_stop,
  1650. .add_interface = rsi_mac80211_add_interface,
  1651. .remove_interface = rsi_mac80211_remove_interface,
  1652. .config = rsi_mac80211_config,
  1653. .bss_info_changed = rsi_mac80211_bss_info_changed,
  1654. .conf_tx = rsi_mac80211_conf_tx,
  1655. .configure_filter = rsi_mac80211_conf_filter,
  1656. .set_key = rsi_mac80211_set_key,
  1657. .set_rts_threshold = rsi_mac80211_set_rts_threshold,
  1658. .set_bitrate_mask = rsi_mac80211_set_rate_mask,
  1659. .ampdu_action = rsi_mac80211_ampdu_action,
  1660. .sta_add = rsi_mac80211_sta_add,
  1661. .sta_remove = rsi_mac80211_sta_remove,
  1662. .set_antenna = rsi_mac80211_set_antenna,
  1663. .get_antenna = rsi_mac80211_get_antenna,
  1664. .rfkill_poll = rsi_mac80211_rfkill_poll,
  1665. .remain_on_channel = rsi_mac80211_roc,
  1666. .cancel_remain_on_channel = rsi_mac80211_cancel_roc,
  1667. #ifdef CONFIG_PM
  1668. .suspend = rsi_mac80211_suspend,
  1669. .resume = rsi_mac80211_resume,
  1670. #endif
  1671. };
  1672. /**
  1673. * rsi_mac80211_attach() - This function is used to initialize Mac80211 stack.
  1674. * @common: Pointer to the driver private structure.
  1675. *
  1676. * Return: 0 on success, negative error codes on failure.
  1677. */
  1678. int rsi_mac80211_attach(struct rsi_common *common)
  1679. {
  1680. int status = 0;
  1681. struct ieee80211_hw *hw = NULL;
  1682. struct wiphy *wiphy = NULL;
  1683. struct rsi_hw *adapter = common->priv;
  1684. u8 addr_mask[ETH_ALEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x3};
  1685. rsi_dbg(INIT_ZONE, "%s: Performing mac80211 attach\n", __func__);
  1686. hw = ieee80211_alloc_hw(sizeof(struct rsi_hw), &mac80211_ops);
  1687. if (!hw) {
  1688. rsi_dbg(ERR_ZONE, "%s: ieee80211 hw alloc failed\n", __func__);
  1689. return -ENOMEM;
  1690. }
  1691. wiphy = hw->wiphy;
  1692. SET_IEEE80211_DEV(hw, adapter->device);
  1693. hw->priv = adapter;
  1694. adapter->hw = hw;
  1695. ieee80211_hw_set(hw, SIGNAL_DBM);
  1696. ieee80211_hw_set(hw, HAS_RATE_CONTROL);
  1697. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  1698. ieee80211_hw_set(hw, SUPPORTS_PS);
  1699. ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
  1700. hw->queues = MAX_HW_QUEUES;
  1701. hw->extra_tx_headroom = RSI_NEEDED_HEADROOM;
  1702. hw->max_rates = 1;
  1703. hw->max_rate_tries = MAX_RETRIES;
  1704. hw->uapsd_queues = RSI_IEEE80211_UAPSD_QUEUES;
  1705. hw->uapsd_max_sp_len = IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL;
  1706. hw->max_tx_aggregation_subframes = RSI_MAX_TX_AGGR_FRMS;
  1707. hw->max_rx_aggregation_subframes = RSI_MAX_RX_AGGR_FRMS;
  1708. hw->rate_control_algorithm = "AARF";
  1709. SET_IEEE80211_PERM_ADDR(hw, common->mac_addr);
  1710. ether_addr_copy(hw->wiphy->addr_mask, addr_mask);
  1711. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1712. BIT(NL80211_IFTYPE_AP) |
  1713. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  1714. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  1715. BIT(NL80211_IFTYPE_P2P_GO);
  1716. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1717. wiphy->retry_short = RETRY_SHORT;
  1718. wiphy->retry_long = RETRY_LONG;
  1719. wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  1720. wiphy->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  1721. wiphy->flags = 0;
  1722. wiphy->available_antennas_rx = 1;
  1723. wiphy->available_antennas_tx = 1;
  1724. rsi_register_rates_channels(adapter, NL80211_BAND_2GHZ);
  1725. wiphy->bands[NL80211_BAND_2GHZ] =
  1726. &adapter->sbands[NL80211_BAND_2GHZ];
  1727. if (common->num_supp_bands > 1) {
  1728. rsi_register_rates_channels(adapter, NL80211_BAND_5GHZ);
  1729. wiphy->bands[NL80211_BAND_5GHZ] =
  1730. &adapter->sbands[NL80211_BAND_5GHZ];
  1731. }
  1732. /* AP Parameters */
  1733. wiphy->max_ap_assoc_sta = rsi_max_ap_stas[common->oper_mode - 1];
  1734. common->max_stations = wiphy->max_ap_assoc_sta;
  1735. rsi_dbg(ERR_ZONE, "Max Stations Allowed = %d\n", common->max_stations);
  1736. hw->sta_data_size = sizeof(struct rsi_sta);
  1737. wiphy->flags = WIPHY_FLAG_REPORTS_OBSS;
  1738. wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  1739. wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
  1740. wiphy->reg_notifier = rsi_reg_notify;
  1741. #ifdef CONFIG_PM
  1742. wiphy->wowlan = &rsi_wowlan_support;
  1743. #endif
  1744. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
  1745. /* Wi-Fi direct parameters */
  1746. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  1747. wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX;
  1748. wiphy->max_remain_on_channel_duration = 10000;
  1749. hw->max_listen_interval = 10;
  1750. wiphy->iface_combinations = rsi_iface_combinations;
  1751. wiphy->n_iface_combinations = ARRAY_SIZE(rsi_iface_combinations);
  1752. if (common->coex_mode > 1)
  1753. wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  1754. status = ieee80211_register_hw(hw);
  1755. if (status)
  1756. return status;
  1757. return rsi_init_dbgfs(adapter);
  1758. }