rsi_91x_mac80211.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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_common.h"
  20. static const struct ieee80211_channel rsi_2ghz_channels[] = {
  21. { .band = NL80211_BAND_2GHZ, .center_freq = 2412,
  22. .hw_value = 1 }, /* Channel 1 */
  23. { .band = NL80211_BAND_2GHZ, .center_freq = 2417,
  24. .hw_value = 2 }, /* Channel 2 */
  25. { .band = NL80211_BAND_2GHZ, .center_freq = 2422,
  26. .hw_value = 3 }, /* Channel 3 */
  27. { .band = NL80211_BAND_2GHZ, .center_freq = 2427,
  28. .hw_value = 4 }, /* Channel 4 */
  29. { .band = NL80211_BAND_2GHZ, .center_freq = 2432,
  30. .hw_value = 5 }, /* Channel 5 */
  31. { .band = NL80211_BAND_2GHZ, .center_freq = 2437,
  32. .hw_value = 6 }, /* Channel 6 */
  33. { .band = NL80211_BAND_2GHZ, .center_freq = 2442,
  34. .hw_value = 7 }, /* Channel 7 */
  35. { .band = NL80211_BAND_2GHZ, .center_freq = 2447,
  36. .hw_value = 8 }, /* Channel 8 */
  37. { .band = NL80211_BAND_2GHZ, .center_freq = 2452,
  38. .hw_value = 9 }, /* Channel 9 */
  39. { .band = NL80211_BAND_2GHZ, .center_freq = 2457,
  40. .hw_value = 10 }, /* Channel 10 */
  41. { .band = NL80211_BAND_2GHZ, .center_freq = 2462,
  42. .hw_value = 11 }, /* Channel 11 */
  43. { .band = NL80211_BAND_2GHZ, .center_freq = 2467,
  44. .hw_value = 12 }, /* Channel 12 */
  45. { .band = NL80211_BAND_2GHZ, .center_freq = 2472,
  46. .hw_value = 13 }, /* Channel 13 */
  47. { .band = NL80211_BAND_2GHZ, .center_freq = 2484,
  48. .hw_value = 14 }, /* Channel 14 */
  49. };
  50. static const struct ieee80211_channel rsi_5ghz_channels[] = {
  51. { .band = NL80211_BAND_5GHZ, .center_freq = 5180,
  52. .hw_value = 36, }, /* Channel 36 */
  53. { .band = NL80211_BAND_5GHZ, .center_freq = 5200,
  54. .hw_value = 40, }, /* Channel 40 */
  55. { .band = NL80211_BAND_5GHZ, .center_freq = 5220,
  56. .hw_value = 44, }, /* Channel 44 */
  57. { .band = NL80211_BAND_5GHZ, .center_freq = 5240,
  58. .hw_value = 48, }, /* Channel 48 */
  59. { .band = NL80211_BAND_5GHZ, .center_freq = 5260,
  60. .hw_value = 52, }, /* Channel 52 */
  61. { .band = NL80211_BAND_5GHZ, .center_freq = 5280,
  62. .hw_value = 56, }, /* Channel 56 */
  63. { .band = NL80211_BAND_5GHZ, .center_freq = 5300,
  64. .hw_value = 60, }, /* Channel 60 */
  65. { .band = NL80211_BAND_5GHZ, .center_freq = 5320,
  66. .hw_value = 64, }, /* Channel 64 */
  67. { .band = NL80211_BAND_5GHZ, .center_freq = 5500,
  68. .hw_value = 100, }, /* Channel 100 */
  69. { .band = NL80211_BAND_5GHZ, .center_freq = 5520,
  70. .hw_value = 104, }, /* Channel 104 */
  71. { .band = NL80211_BAND_5GHZ, .center_freq = 5540,
  72. .hw_value = 108, }, /* Channel 108 */
  73. { .band = NL80211_BAND_5GHZ, .center_freq = 5560,
  74. .hw_value = 112, }, /* Channel 112 */
  75. { .band = NL80211_BAND_5GHZ, .center_freq = 5580,
  76. .hw_value = 116, }, /* Channel 116 */
  77. { .band = NL80211_BAND_5GHZ, .center_freq = 5600,
  78. .hw_value = 120, }, /* Channel 120 */
  79. { .band = NL80211_BAND_5GHZ, .center_freq = 5620,
  80. .hw_value = 124, }, /* Channel 124 */
  81. { .band = NL80211_BAND_5GHZ, .center_freq = 5640,
  82. .hw_value = 128, }, /* Channel 128 */
  83. { .band = NL80211_BAND_5GHZ, .center_freq = 5660,
  84. .hw_value = 132, }, /* Channel 132 */
  85. { .band = NL80211_BAND_5GHZ, .center_freq = 5680,
  86. .hw_value = 136, }, /* Channel 136 */
  87. { .band = NL80211_BAND_5GHZ, .center_freq = 5700,
  88. .hw_value = 140, }, /* Channel 140 */
  89. { .band = NL80211_BAND_5GHZ, .center_freq = 5745,
  90. .hw_value = 149, }, /* Channel 149 */
  91. { .band = NL80211_BAND_5GHZ, .center_freq = 5765,
  92. .hw_value = 153, }, /* Channel 153 */
  93. { .band = NL80211_BAND_5GHZ, .center_freq = 5785,
  94. .hw_value = 157, }, /* Channel 157 */
  95. { .band = NL80211_BAND_5GHZ, .center_freq = 5805,
  96. .hw_value = 161, }, /* Channel 161 */
  97. { .band = NL80211_BAND_5GHZ, .center_freq = 5825,
  98. .hw_value = 165, }, /* Channel 165 */
  99. };
  100. struct ieee80211_rate rsi_rates[12] = {
  101. { .bitrate = STD_RATE_01 * 5, .hw_value = RSI_RATE_1 },
  102. { .bitrate = STD_RATE_02 * 5, .hw_value = RSI_RATE_2 },
  103. { .bitrate = STD_RATE_5_5 * 5, .hw_value = RSI_RATE_5_5 },
  104. { .bitrate = STD_RATE_11 * 5, .hw_value = RSI_RATE_11 },
  105. { .bitrate = STD_RATE_06 * 5, .hw_value = RSI_RATE_6 },
  106. { .bitrate = STD_RATE_09 * 5, .hw_value = RSI_RATE_9 },
  107. { .bitrate = STD_RATE_12 * 5, .hw_value = RSI_RATE_12 },
  108. { .bitrate = STD_RATE_18 * 5, .hw_value = RSI_RATE_18 },
  109. { .bitrate = STD_RATE_24 * 5, .hw_value = RSI_RATE_24 },
  110. { .bitrate = STD_RATE_36 * 5, .hw_value = RSI_RATE_36 },
  111. { .bitrate = STD_RATE_48 * 5, .hw_value = RSI_RATE_48 },
  112. { .bitrate = STD_RATE_54 * 5, .hw_value = RSI_RATE_54 },
  113. };
  114. const u16 rsi_mcsrates[8] = {
  115. RSI_RATE_MCS0, RSI_RATE_MCS1, RSI_RATE_MCS2, RSI_RATE_MCS3,
  116. RSI_RATE_MCS4, RSI_RATE_MCS5, RSI_RATE_MCS6, RSI_RATE_MCS7
  117. };
  118. /**
  119. * rsi_is_cipher_wep() - This function determines if the cipher is WEP or not.
  120. * @common: Pointer to the driver private structure.
  121. *
  122. * Return: If cipher type is WEP, a value of 1 is returned, else 0.
  123. */
  124. bool rsi_is_cipher_wep(struct rsi_common *common)
  125. {
  126. if (((common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP104) ||
  127. (common->secinfo.gtk_cipher == WLAN_CIPHER_SUITE_WEP40)) &&
  128. (!common->secinfo.ptk_cipher))
  129. return true;
  130. else
  131. return false;
  132. }
  133. /**
  134. * rsi_register_rates_channels() - This function registers channels and rates.
  135. * @adapter: Pointer to the adapter structure.
  136. * @band: Operating band to be set.
  137. *
  138. * Return: None.
  139. */
  140. static void rsi_register_rates_channels(struct rsi_hw *adapter, int band)
  141. {
  142. struct ieee80211_supported_band *sbands = &adapter->sbands[band];
  143. void *channels = NULL;
  144. if (band == NL80211_BAND_2GHZ) {
  145. channels = kmalloc(sizeof(rsi_2ghz_channels), GFP_KERNEL);
  146. memcpy(channels,
  147. rsi_2ghz_channels,
  148. sizeof(rsi_2ghz_channels));
  149. sbands->band = NL80211_BAND_2GHZ;
  150. sbands->n_channels = ARRAY_SIZE(rsi_2ghz_channels);
  151. sbands->bitrates = rsi_rates;
  152. sbands->n_bitrates = ARRAY_SIZE(rsi_rates);
  153. } else {
  154. channels = kmalloc(sizeof(rsi_5ghz_channels), GFP_KERNEL);
  155. memcpy(channels,
  156. rsi_5ghz_channels,
  157. sizeof(rsi_5ghz_channels));
  158. sbands->band = NL80211_BAND_5GHZ;
  159. sbands->n_channels = ARRAY_SIZE(rsi_5ghz_channels);
  160. sbands->bitrates = &rsi_rates[4];
  161. sbands->n_bitrates = ARRAY_SIZE(rsi_rates) - 4;
  162. }
  163. sbands->channels = channels;
  164. memset(&sbands->ht_cap, 0, sizeof(struct ieee80211_sta_ht_cap));
  165. sbands->ht_cap.ht_supported = true;
  166. sbands->ht_cap.cap = (IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  167. IEEE80211_HT_CAP_SGI_20 |
  168. IEEE80211_HT_CAP_SGI_40);
  169. sbands->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K;
  170. sbands->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  171. sbands->ht_cap.mcs.rx_mask[0] = 0xff;
  172. sbands->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  173. /* sbands->ht_cap.mcs.rx_highest = 0x82; */
  174. }
  175. /**
  176. * rsi_mac80211_detach() - This function is used to de-initialize the
  177. * Mac80211 stack.
  178. * @adapter: Pointer to the adapter structure.
  179. *
  180. * Return: None.
  181. */
  182. void rsi_mac80211_detach(struct rsi_hw *adapter)
  183. {
  184. struct ieee80211_hw *hw = adapter->hw;
  185. enum nl80211_band band;
  186. if (hw) {
  187. ieee80211_stop_queues(hw);
  188. ieee80211_unregister_hw(hw);
  189. ieee80211_free_hw(hw);
  190. }
  191. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  192. struct ieee80211_supported_band *sband =
  193. &adapter->sbands[band];
  194. kfree(sband->channels);
  195. }
  196. #ifdef CONFIG_RSI_DEBUGFS
  197. rsi_remove_dbgfs(adapter);
  198. kfree(adapter->dfsentry);
  199. #endif
  200. }
  201. EXPORT_SYMBOL_GPL(rsi_mac80211_detach);
  202. /**
  203. * rsi_indicate_tx_status() - This function indicates the transmit status.
  204. * @adapter: Pointer to the adapter structure.
  205. * @skb: Pointer to the socket buffer structure.
  206. * @status: Status
  207. *
  208. * Return: None.
  209. */
  210. void rsi_indicate_tx_status(struct rsi_hw *adapter,
  211. struct sk_buff *skb,
  212. int status)
  213. {
  214. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  215. memset(info->driver_data, 0, IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
  216. if (!status)
  217. info->flags |= IEEE80211_TX_STAT_ACK;
  218. ieee80211_tx_status_irqsafe(adapter->hw, skb);
  219. }
  220. /**
  221. * rsi_mac80211_tx() - This is the handler that 802.11 module calls for each
  222. * transmitted frame.SKB contains the buffer starting
  223. * from the IEEE 802.11 header.
  224. * @hw: Pointer to the ieee80211_hw structure.
  225. * @control: Pointer to the ieee80211_tx_control structure
  226. * @skb: Pointer to the socket buffer structure.
  227. *
  228. * Return: None
  229. */
  230. static void rsi_mac80211_tx(struct ieee80211_hw *hw,
  231. struct ieee80211_tx_control *control,
  232. struct sk_buff *skb)
  233. {
  234. struct rsi_hw *adapter = hw->priv;
  235. struct rsi_common *common = adapter->priv;
  236. rsi_core_xmit(common, skb);
  237. }
  238. /**
  239. * rsi_mac80211_start() - This is first handler that 802.11 module calls, since
  240. * the driver init is complete by then, just
  241. * returns success.
  242. * @hw: Pointer to the ieee80211_hw structure.
  243. *
  244. * Return: 0 as success.
  245. */
  246. static int rsi_mac80211_start(struct ieee80211_hw *hw)
  247. {
  248. struct rsi_hw *adapter = hw->priv;
  249. struct rsi_common *common = adapter->priv;
  250. mutex_lock(&common->mutex);
  251. common->iface_down = false;
  252. mutex_unlock(&common->mutex);
  253. rsi_send_rx_filter_frame(common, 0);
  254. return 0;
  255. }
  256. /**
  257. * rsi_mac80211_stop() - This is the last handler that 802.11 module calls.
  258. * @hw: Pointer to the ieee80211_hw structure.
  259. *
  260. * Return: None.
  261. */
  262. static void rsi_mac80211_stop(struct ieee80211_hw *hw)
  263. {
  264. struct rsi_hw *adapter = hw->priv;
  265. struct rsi_common *common = adapter->priv;
  266. mutex_lock(&common->mutex);
  267. common->iface_down = true;
  268. mutex_unlock(&common->mutex);
  269. }
  270. /**
  271. * rsi_mac80211_add_interface() - This function is called when a netdevice
  272. * attached to the hardware is enabled.
  273. * @hw: Pointer to the ieee80211_hw structure.
  274. * @vif: Pointer to the ieee80211_vif structure.
  275. *
  276. * Return: ret: 0 on success, negative error code on failure.
  277. */
  278. static int rsi_mac80211_add_interface(struct ieee80211_hw *hw,
  279. struct ieee80211_vif *vif)
  280. {
  281. struct rsi_hw *adapter = hw->priv;
  282. struct rsi_common *common = adapter->priv;
  283. int ret = -EOPNOTSUPP;
  284. mutex_lock(&common->mutex);
  285. switch (vif->type) {
  286. case NL80211_IFTYPE_STATION:
  287. if (!adapter->sc_nvifs) {
  288. ++adapter->sc_nvifs;
  289. adapter->vifs[0] = vif;
  290. ret = rsi_set_vap_capabilities(common,
  291. STA_OPMODE,
  292. VAP_ADD);
  293. }
  294. break;
  295. default:
  296. rsi_dbg(ERR_ZONE,
  297. "%s: Interface type %d not supported\n", __func__,
  298. vif->type);
  299. }
  300. mutex_unlock(&common->mutex);
  301. return ret;
  302. }
  303. /**
  304. * rsi_mac80211_remove_interface() - This function notifies driver that an
  305. * interface is going down.
  306. * @hw: Pointer to the ieee80211_hw structure.
  307. * @vif: Pointer to the ieee80211_vif structure.
  308. *
  309. * Return: None.
  310. */
  311. static void rsi_mac80211_remove_interface(struct ieee80211_hw *hw,
  312. struct ieee80211_vif *vif)
  313. {
  314. struct rsi_hw *adapter = hw->priv;
  315. struct rsi_common *common = adapter->priv;
  316. mutex_lock(&common->mutex);
  317. if (vif->type == NL80211_IFTYPE_STATION) {
  318. adapter->sc_nvifs--;
  319. rsi_set_vap_capabilities(common, STA_OPMODE, VAP_DELETE);
  320. }
  321. if (!memcmp(adapter->vifs[0], vif, sizeof(struct ieee80211_vif)))
  322. adapter->vifs[0] = NULL;
  323. mutex_unlock(&common->mutex);
  324. }
  325. /**
  326. * rsi_channel_change() - This function is a performs the checks
  327. * required for changing a channel and sets
  328. * the channel accordingly.
  329. * @hw: Pointer to the ieee80211_hw structure.
  330. *
  331. * Return: 0 on success, negative error code on failure.
  332. */
  333. static int rsi_channel_change(struct ieee80211_hw *hw)
  334. {
  335. struct rsi_hw *adapter = hw->priv;
  336. struct rsi_common *common = adapter->priv;
  337. int status = -EOPNOTSUPP;
  338. struct ieee80211_channel *curchan = hw->conf.chandef.chan;
  339. u16 channel = curchan->hw_value;
  340. struct ieee80211_bss_conf *bss = &adapter->vifs[0]->bss_conf;
  341. rsi_dbg(INFO_ZONE,
  342. "%s: Set channel: %d MHz type: %d channel_no %d\n",
  343. __func__, curchan->center_freq,
  344. curchan->flags, channel);
  345. if (bss->assoc) {
  346. if (!common->hw_data_qs_blocked &&
  347. (rsi_get_connected_channel(adapter) != channel)) {
  348. rsi_dbg(INFO_ZONE, "blk data q %d\n", channel);
  349. if (!rsi_send_block_unblock_frame(common, true))
  350. common->hw_data_qs_blocked = true;
  351. }
  352. }
  353. status = rsi_band_check(common);
  354. if (!status)
  355. status = rsi_set_channel(adapter->priv, curchan);
  356. if (bss->assoc) {
  357. if (common->hw_data_qs_blocked &&
  358. (rsi_get_connected_channel(adapter) == channel)) {
  359. rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel);
  360. if (!rsi_send_block_unblock_frame(common, false))
  361. common->hw_data_qs_blocked = false;
  362. }
  363. } else {
  364. if (common->hw_data_qs_blocked) {
  365. rsi_dbg(INFO_ZONE, "unblk data q %d\n", channel);
  366. if (!rsi_send_block_unblock_frame(common, false))
  367. common->hw_data_qs_blocked = false;
  368. }
  369. }
  370. return status;
  371. }
  372. /**
  373. * rsi_config_power() - This function configures tx power to device
  374. * @hw: Pointer to the ieee80211_hw structure.
  375. *
  376. * Return: 0 on success, negative error code on failure.
  377. */
  378. static int rsi_config_power(struct ieee80211_hw *hw)
  379. {
  380. struct rsi_hw *adapter = hw->priv;
  381. struct rsi_common *common = adapter->priv;
  382. struct ieee80211_conf *conf = &hw->conf;
  383. if (adapter->sc_nvifs <= 0) {
  384. rsi_dbg(ERR_ZONE, "%s: No virtual interface found\n", __func__);
  385. return -EINVAL;
  386. }
  387. rsi_dbg(INFO_ZONE,
  388. "%s: Set tx power: %d dBM\n", __func__, conf->power_level);
  389. if (conf->power_level == common->tx_power)
  390. return 0;
  391. common->tx_power = conf->power_level;
  392. return rsi_send_radio_params_update(common);
  393. }
  394. /**
  395. * rsi_mac80211_config() - This function is a handler for configuration
  396. * requests. The stack calls this function to
  397. * change hardware configuration, e.g., channel.
  398. * @hw: Pointer to the ieee80211_hw structure.
  399. * @changed: Changed flags set.
  400. *
  401. * Return: 0 on success, negative error code on failure.
  402. */
  403. static int rsi_mac80211_config(struct ieee80211_hw *hw,
  404. u32 changed)
  405. {
  406. struct rsi_hw *adapter = hw->priv;
  407. struct rsi_common *common = adapter->priv;
  408. int status = -EOPNOTSUPP;
  409. mutex_lock(&common->mutex);
  410. if (changed & IEEE80211_CONF_CHANGE_CHANNEL)
  411. status = rsi_channel_change(hw);
  412. /* tx power */
  413. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  414. rsi_dbg(INFO_ZONE, "%s: Configuring Power\n", __func__);
  415. status = rsi_config_power(hw);
  416. }
  417. mutex_unlock(&common->mutex);
  418. return status;
  419. }
  420. /**
  421. * rsi_get_connected_channel() - This function is used to get the current
  422. * connected channel number.
  423. * @adapter: Pointer to the adapter structure.
  424. *
  425. * Return: Current connected AP's channel number is returned.
  426. */
  427. u16 rsi_get_connected_channel(struct rsi_hw *adapter)
  428. {
  429. struct ieee80211_vif *vif = adapter->vifs[0];
  430. if (vif) {
  431. struct ieee80211_bss_conf *bss = &vif->bss_conf;
  432. struct ieee80211_channel *channel = bss->chandef.chan;
  433. return channel->hw_value;
  434. }
  435. return 0;
  436. }
  437. /**
  438. * rsi_mac80211_bss_info_changed() - This function is a handler for config
  439. * requests related to BSS parameters that
  440. * may vary during BSS's lifespan.
  441. * @hw: Pointer to the ieee80211_hw structure.
  442. * @vif: Pointer to the ieee80211_vif structure.
  443. * @bss_conf: Pointer to the ieee80211_bss_conf structure.
  444. * @changed: Changed flags set.
  445. *
  446. * Return: None.
  447. */
  448. static void rsi_mac80211_bss_info_changed(struct ieee80211_hw *hw,
  449. struct ieee80211_vif *vif,
  450. struct ieee80211_bss_conf *bss_conf,
  451. u32 changed)
  452. {
  453. struct rsi_hw *adapter = hw->priv;
  454. struct rsi_common *common = adapter->priv;
  455. u16 rx_filter_word = 0;
  456. mutex_lock(&common->mutex);
  457. if (changed & BSS_CHANGED_ASSOC) {
  458. rsi_dbg(INFO_ZONE, "%s: Changed Association status: %d\n",
  459. __func__, bss_conf->assoc);
  460. if (bss_conf->assoc) {
  461. /* Send the RX filter frame */
  462. rx_filter_word = (ALLOW_DATA_ASSOC_PEER |
  463. ALLOW_CTRL_ASSOC_PEER |
  464. ALLOW_MGMT_ASSOC_PEER);
  465. rsi_send_rx_filter_frame(common, rx_filter_word);
  466. }
  467. rsi_inform_bss_status(common,
  468. bss_conf->assoc,
  469. bss_conf->bssid,
  470. bss_conf->qos,
  471. bss_conf->aid);
  472. }
  473. if (changed & BSS_CHANGED_CQM) {
  474. common->cqm_info.last_cqm_event_rssi = 0;
  475. common->cqm_info.rssi_thold = bss_conf->cqm_rssi_thold;
  476. common->cqm_info.rssi_hyst = bss_conf->cqm_rssi_hyst;
  477. rsi_dbg(INFO_ZONE, "RSSI throld & hysteresis are: %d %d\n",
  478. common->cqm_info.rssi_thold,
  479. common->cqm_info.rssi_hyst);
  480. }
  481. mutex_unlock(&common->mutex);
  482. }
  483. /**
  484. * rsi_mac80211_conf_filter() - This function configure the device's RX filter.
  485. * @hw: Pointer to the ieee80211_hw structure.
  486. * @changed: Changed flags set.
  487. * @total_flags: Total initial flags set.
  488. * @multicast: Multicast.
  489. *
  490. * Return: None.
  491. */
  492. static void rsi_mac80211_conf_filter(struct ieee80211_hw *hw,
  493. u32 changed_flags,
  494. u32 *total_flags,
  495. u64 multicast)
  496. {
  497. /* Not doing much here as of now */
  498. *total_flags &= RSI_SUPP_FILTERS;
  499. }
  500. /**
  501. * rsi_mac80211_conf_tx() - This function configures TX queue parameters
  502. * (EDCF (aifs, cw_min, cw_max), bursting)
  503. * for a hardware TX queue.
  504. * @hw: Pointer to the ieee80211_hw structure
  505. * @vif: Pointer to the ieee80211_vif structure.
  506. * @queue: Queue number.
  507. * @params: Pointer to ieee80211_tx_queue_params structure.
  508. *
  509. * Return: 0 on success, negative error code on failure.
  510. */
  511. static int rsi_mac80211_conf_tx(struct ieee80211_hw *hw,
  512. struct ieee80211_vif *vif, u16 queue,
  513. const struct ieee80211_tx_queue_params *params)
  514. {
  515. struct rsi_hw *adapter = hw->priv;
  516. struct rsi_common *common = adapter->priv;
  517. u8 idx = 0;
  518. if (queue >= IEEE80211_NUM_ACS)
  519. return 0;
  520. rsi_dbg(INFO_ZONE,
  521. "%s: Conf queue %d, aifs: %d, cwmin: %d cwmax: %d, txop: %d\n",
  522. __func__, queue, params->aifs,
  523. params->cw_min, params->cw_max, params->txop);
  524. mutex_lock(&common->mutex);
  525. /* Map into the way the f/w expects */
  526. switch (queue) {
  527. case IEEE80211_AC_VO:
  528. idx = VO_Q;
  529. break;
  530. case IEEE80211_AC_VI:
  531. idx = VI_Q;
  532. break;
  533. case IEEE80211_AC_BE:
  534. idx = BE_Q;
  535. break;
  536. case IEEE80211_AC_BK:
  537. idx = BK_Q;
  538. break;
  539. default:
  540. idx = BE_Q;
  541. break;
  542. }
  543. memcpy(&common->edca_params[idx],
  544. params,
  545. sizeof(struct ieee80211_tx_queue_params));
  546. mutex_unlock(&common->mutex);
  547. return 0;
  548. }
  549. /**
  550. * rsi_hal_key_config() - This function loads the keys into the firmware.
  551. * @hw: Pointer to the ieee80211_hw structure.
  552. * @vif: Pointer to the ieee80211_vif structure.
  553. * @key: Pointer to the ieee80211_key_conf structure.
  554. *
  555. * Return: status: 0 on success, -1 on failure.
  556. */
  557. static int rsi_hal_key_config(struct ieee80211_hw *hw,
  558. struct ieee80211_vif *vif,
  559. struct ieee80211_key_conf *key)
  560. {
  561. struct rsi_hw *adapter = hw->priv;
  562. int status;
  563. u8 key_type;
  564. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  565. key_type = RSI_PAIRWISE_KEY;
  566. else
  567. key_type = RSI_GROUP_KEY;
  568. rsi_dbg(ERR_ZONE, "%s: Cipher 0x%x key_type: %d key_len: %d\n",
  569. __func__, key->cipher, key_type, key->keylen);
  570. if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) ||
  571. (key->cipher == WLAN_CIPHER_SUITE_WEP40)) {
  572. status = rsi_hal_load_key(adapter->priv,
  573. key->key,
  574. key->keylen,
  575. RSI_PAIRWISE_KEY,
  576. key->keyidx,
  577. key->cipher);
  578. if (status)
  579. return status;
  580. }
  581. return rsi_hal_load_key(adapter->priv,
  582. key->key,
  583. key->keylen,
  584. key_type,
  585. key->keyidx,
  586. key->cipher);
  587. }
  588. /**
  589. * rsi_mac80211_set_key() - This function sets type of key to be loaded.
  590. * @hw: Pointer to the ieee80211_hw structure.
  591. * @cmd: enum set_key_cmd.
  592. * @vif: Pointer to the ieee80211_vif structure.
  593. * @sta: Pointer to the ieee80211_sta structure.
  594. * @key: Pointer to the ieee80211_key_conf structure.
  595. *
  596. * Return: status: 0 on success, negative error code on failure.
  597. */
  598. static int rsi_mac80211_set_key(struct ieee80211_hw *hw,
  599. enum set_key_cmd cmd,
  600. struct ieee80211_vif *vif,
  601. struct ieee80211_sta *sta,
  602. struct ieee80211_key_conf *key)
  603. {
  604. struct rsi_hw *adapter = hw->priv;
  605. struct rsi_common *common = adapter->priv;
  606. struct security_info *secinfo = &common->secinfo;
  607. int status;
  608. mutex_lock(&common->mutex);
  609. switch (cmd) {
  610. case SET_KEY:
  611. secinfo->security_enable = true;
  612. status = rsi_hal_key_config(hw, vif, key);
  613. if (status) {
  614. mutex_unlock(&common->mutex);
  615. return status;
  616. }
  617. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  618. secinfo->ptk_cipher = key->cipher;
  619. else
  620. secinfo->gtk_cipher = key->cipher;
  621. key->hw_key_idx = key->keyidx;
  622. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  623. rsi_dbg(ERR_ZONE, "%s: RSI set_key\n", __func__);
  624. break;
  625. case DISABLE_KEY:
  626. secinfo->security_enable = false;
  627. rsi_dbg(ERR_ZONE, "%s: RSI del key\n", __func__);
  628. memset(key, 0, sizeof(struct ieee80211_key_conf));
  629. status = rsi_hal_key_config(hw, vif, key);
  630. break;
  631. default:
  632. status = -EOPNOTSUPP;
  633. break;
  634. }
  635. mutex_unlock(&common->mutex);
  636. return status;
  637. }
  638. /**
  639. * rsi_mac80211_ampdu_action() - This function selects the AMPDU action for
  640. * the corresponding mlme_action flag and
  641. * informs the f/w regarding this.
  642. * @hw: Pointer to the ieee80211_hw structure.
  643. * @vif: Pointer to the ieee80211_vif structure.
  644. * @params: Pointer to A-MPDU action parameters
  645. *
  646. * Return: status: 0 on success, negative error code on failure.
  647. */
  648. static int rsi_mac80211_ampdu_action(struct ieee80211_hw *hw,
  649. struct ieee80211_vif *vif,
  650. struct ieee80211_ampdu_params *params)
  651. {
  652. int status = -EOPNOTSUPP;
  653. struct rsi_hw *adapter = hw->priv;
  654. struct rsi_common *common = adapter->priv;
  655. u16 seq_no = 0;
  656. u8 ii = 0;
  657. struct ieee80211_sta *sta = params->sta;
  658. enum ieee80211_ampdu_mlme_action action = params->action;
  659. u16 tid = params->tid;
  660. u16 *ssn = &params->ssn;
  661. u8 buf_size = params->buf_size;
  662. for (ii = 0; ii < RSI_MAX_VIFS; ii++) {
  663. if (vif == adapter->vifs[ii])
  664. break;
  665. }
  666. mutex_lock(&common->mutex);
  667. rsi_dbg(INFO_ZONE, "%s: AMPDU action %d called\n", __func__, action);
  668. if (ssn != NULL)
  669. seq_no = *ssn;
  670. switch (action) {
  671. case IEEE80211_AMPDU_RX_START:
  672. status = rsi_send_aggregation_params_frame(common,
  673. tid,
  674. seq_no,
  675. buf_size,
  676. STA_RX_ADDBA_DONE);
  677. break;
  678. case IEEE80211_AMPDU_RX_STOP:
  679. status = rsi_send_aggregation_params_frame(common,
  680. tid,
  681. 0,
  682. buf_size,
  683. STA_RX_DELBA);
  684. break;
  685. case IEEE80211_AMPDU_TX_START:
  686. common->vif_info[ii].seq_start = seq_no;
  687. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  688. status = 0;
  689. break;
  690. case IEEE80211_AMPDU_TX_STOP_CONT:
  691. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  692. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  693. status = rsi_send_aggregation_params_frame(common,
  694. tid,
  695. seq_no,
  696. buf_size,
  697. STA_TX_DELBA);
  698. if (!status)
  699. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  700. break;
  701. case IEEE80211_AMPDU_TX_OPERATIONAL:
  702. status = rsi_send_aggregation_params_frame(common,
  703. tid,
  704. common->vif_info[ii]
  705. .seq_start,
  706. buf_size,
  707. STA_TX_ADDBA_DONE);
  708. break;
  709. default:
  710. rsi_dbg(ERR_ZONE, "%s: Uknown AMPDU action\n", __func__);
  711. break;
  712. }
  713. mutex_unlock(&common->mutex);
  714. return status;
  715. }
  716. /**
  717. * rsi_mac80211_set_rts_threshold() - This function sets rts threshold value.
  718. * @hw: Pointer to the ieee80211_hw structure.
  719. * @value: Rts threshold value.
  720. *
  721. * Return: 0 on success.
  722. */
  723. static int rsi_mac80211_set_rts_threshold(struct ieee80211_hw *hw,
  724. u32 value)
  725. {
  726. struct rsi_hw *adapter = hw->priv;
  727. struct rsi_common *common = adapter->priv;
  728. mutex_lock(&common->mutex);
  729. common->rts_threshold = value;
  730. mutex_unlock(&common->mutex);
  731. return 0;
  732. }
  733. /**
  734. * rsi_mac80211_set_rate_mask() - This function sets bitrate_mask to be used.
  735. * @hw: Pointer to the ieee80211_hw structure
  736. * @vif: Pointer to the ieee80211_vif structure.
  737. * @mask: Pointer to the cfg80211_bitrate_mask structure.
  738. *
  739. * Return: 0 on success.
  740. */
  741. static int rsi_mac80211_set_rate_mask(struct ieee80211_hw *hw,
  742. struct ieee80211_vif *vif,
  743. const struct cfg80211_bitrate_mask *mask)
  744. {
  745. struct rsi_hw *adapter = hw->priv;
  746. struct rsi_common *common = adapter->priv;
  747. enum nl80211_band band = hw->conf.chandef.chan->band;
  748. mutex_lock(&common->mutex);
  749. common->fixedrate_mask[band] = 0;
  750. if (mask->control[band].legacy == 0xfff) {
  751. common->fixedrate_mask[band] =
  752. (mask->control[band].ht_mcs[0] << 12);
  753. } else {
  754. common->fixedrate_mask[band] =
  755. mask->control[band].legacy;
  756. }
  757. mutex_unlock(&common->mutex);
  758. return 0;
  759. }
  760. /**
  761. * rsi_perform_cqm() - This function performs cqm.
  762. * @common: Pointer to the driver private structure.
  763. * @bssid: pointer to the bssid.
  764. * @rssi: RSSI value.
  765. */
  766. static void rsi_perform_cqm(struct rsi_common *common,
  767. u8 *bssid,
  768. s8 rssi)
  769. {
  770. struct rsi_hw *adapter = common->priv;
  771. s8 last_event = common->cqm_info.last_cqm_event_rssi;
  772. int thold = common->cqm_info.rssi_thold;
  773. u32 hyst = common->cqm_info.rssi_hyst;
  774. enum nl80211_cqm_rssi_threshold_event event;
  775. if (rssi < thold && (last_event == 0 || rssi < (last_event - hyst)))
  776. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  777. else if (rssi > thold &&
  778. (last_event == 0 || rssi > (last_event + hyst)))
  779. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  780. else
  781. return;
  782. common->cqm_info.last_cqm_event_rssi = rssi;
  783. rsi_dbg(INFO_ZONE, "CQM: Notifying event: %d\n", event);
  784. ieee80211_cqm_rssi_notify(adapter->vifs[0], event, GFP_KERNEL);
  785. return;
  786. }
  787. /**
  788. * rsi_fill_rx_status() - This function fills rx status in
  789. * ieee80211_rx_status structure.
  790. * @hw: Pointer to the ieee80211_hw structure.
  791. * @skb: Pointer to the socket buffer structure.
  792. * @common: Pointer to the driver private structure.
  793. * @rxs: Pointer to the ieee80211_rx_status structure.
  794. *
  795. * Return: None.
  796. */
  797. static void rsi_fill_rx_status(struct ieee80211_hw *hw,
  798. struct sk_buff *skb,
  799. struct rsi_common *common,
  800. struct ieee80211_rx_status *rxs)
  801. {
  802. struct ieee80211_bss_conf *bss = &common->priv->vifs[0]->bss_conf;
  803. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  804. struct skb_info *rx_params = (struct skb_info *)info->driver_data;
  805. struct ieee80211_hdr *hdr;
  806. char rssi = rx_params->rssi;
  807. u8 hdrlen = 0;
  808. u8 channel = rx_params->channel;
  809. s32 freq;
  810. hdr = ((struct ieee80211_hdr *)(skb->data));
  811. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  812. memset(info, 0, sizeof(struct ieee80211_tx_info));
  813. rxs->signal = -(rssi);
  814. rxs->band = common->band;
  815. freq = ieee80211_channel_to_frequency(channel, rxs->band);
  816. if (freq)
  817. rxs->freq = freq;
  818. if (ieee80211_has_protected(hdr->frame_control)) {
  819. if (rsi_is_cipher_wep(common)) {
  820. memmove(skb->data + 4, skb->data, hdrlen);
  821. skb_pull(skb, 4);
  822. } else {
  823. memmove(skb->data + 8, skb->data, hdrlen);
  824. skb_pull(skb, 8);
  825. rxs->flag |= RX_FLAG_MMIC_STRIPPED;
  826. }
  827. rxs->flag |= RX_FLAG_DECRYPTED;
  828. rxs->flag |= RX_FLAG_IV_STRIPPED;
  829. }
  830. /* CQM only for connected AP beacons, the RSSI is a weighted avg */
  831. if (bss->assoc && !(memcmp(bss->bssid, hdr->addr2, ETH_ALEN))) {
  832. if (ieee80211_is_beacon(hdr->frame_control))
  833. rsi_perform_cqm(common, hdr->addr2, rxs->signal);
  834. }
  835. return;
  836. }
  837. /**
  838. * rsi_indicate_pkt_to_os() - This function sends recieved packet to mac80211.
  839. * @common: Pointer to the driver private structure.
  840. * @skb: Pointer to the socket buffer structure.
  841. *
  842. * Return: None.
  843. */
  844. void rsi_indicate_pkt_to_os(struct rsi_common *common,
  845. struct sk_buff *skb)
  846. {
  847. struct rsi_hw *adapter = common->priv;
  848. struct ieee80211_hw *hw = adapter->hw;
  849. struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
  850. if ((common->iface_down) || (!adapter->sc_nvifs)) {
  851. dev_kfree_skb(skb);
  852. return;
  853. }
  854. /* filling in the ieee80211_rx_status flags */
  855. rsi_fill_rx_status(hw, skb, common, rx_status);
  856. ieee80211_rx_irqsafe(hw, skb);
  857. }
  858. static void rsi_set_min_rate(struct ieee80211_hw *hw,
  859. struct ieee80211_sta *sta,
  860. struct rsi_common *common)
  861. {
  862. u8 band = hw->conf.chandef.chan->band;
  863. u8 ii;
  864. u32 rate_bitmap;
  865. bool matched = false;
  866. common->bitrate_mask[band] = sta->supp_rates[band];
  867. rate_bitmap = (common->fixedrate_mask[band] & sta->supp_rates[band]);
  868. if (rate_bitmap & 0xfff) {
  869. /* Find out the min rate */
  870. for (ii = 0; ii < ARRAY_SIZE(rsi_rates); ii++) {
  871. if (rate_bitmap & BIT(ii)) {
  872. common->min_rate = rsi_rates[ii].hw_value;
  873. matched = true;
  874. break;
  875. }
  876. }
  877. }
  878. common->vif_info[0].is_ht = sta->ht_cap.ht_supported;
  879. if ((common->vif_info[0].is_ht) && (rate_bitmap >> 12)) {
  880. for (ii = 0; ii < ARRAY_SIZE(rsi_mcsrates); ii++) {
  881. if ((rate_bitmap >> 12) & BIT(ii)) {
  882. common->min_rate = rsi_mcsrates[ii];
  883. matched = true;
  884. break;
  885. }
  886. }
  887. }
  888. if (!matched)
  889. common->min_rate = 0xffff;
  890. }
  891. /**
  892. * rsi_mac80211_sta_add() - This function notifies driver about a peer getting
  893. * connected.
  894. * @hw: pointer to the ieee80211_hw structure.
  895. * @vif: Pointer to the ieee80211_vif structure.
  896. * @sta: Pointer to the ieee80211_sta structure.
  897. *
  898. * Return: 0 on success, -1 on failure.
  899. */
  900. static int rsi_mac80211_sta_add(struct ieee80211_hw *hw,
  901. struct ieee80211_vif *vif,
  902. struct ieee80211_sta *sta)
  903. {
  904. struct rsi_hw *adapter = hw->priv;
  905. struct rsi_common *common = adapter->priv;
  906. mutex_lock(&common->mutex);
  907. rsi_set_min_rate(hw, sta, common);
  908. if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ||
  909. (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) {
  910. common->vif_info[0].sgi = true;
  911. }
  912. if (sta->ht_cap.ht_supported)
  913. ieee80211_start_tx_ba_session(sta, 0, 0);
  914. mutex_unlock(&common->mutex);
  915. return 0;
  916. }
  917. /**
  918. * rsi_mac80211_sta_remove() - This function notifies driver about a peer
  919. * getting disconnected.
  920. * @hw: Pointer to the ieee80211_hw structure.
  921. * @vif: Pointer to the ieee80211_vif structure.
  922. * @sta: Pointer to the ieee80211_sta structure.
  923. *
  924. * Return: 0 on success, -1 on failure.
  925. */
  926. static int rsi_mac80211_sta_remove(struct ieee80211_hw *hw,
  927. struct ieee80211_vif *vif,
  928. struct ieee80211_sta *sta)
  929. {
  930. struct rsi_hw *adapter = hw->priv;
  931. struct rsi_common *common = adapter->priv;
  932. mutex_lock(&common->mutex);
  933. /* Resetting all the fields to default values */
  934. common->bitrate_mask[NL80211_BAND_2GHZ] = 0;
  935. common->bitrate_mask[NL80211_BAND_5GHZ] = 0;
  936. common->min_rate = 0xffff;
  937. common->vif_info[0].is_ht = false;
  938. common->vif_info[0].sgi = false;
  939. common->vif_info[0].seq_start = 0;
  940. common->secinfo.ptk_cipher = 0;
  941. common->secinfo.gtk_cipher = 0;
  942. rsi_send_rx_filter_frame(common, 0);
  943. mutex_unlock(&common->mutex);
  944. return 0;
  945. }
  946. /**
  947. * rsi_mac80211_set_antenna() - This function is used to configure
  948. * tx and rx antennas.
  949. * @hw: Pointer to the ieee80211_hw structure.
  950. * @tx_ant: Bitmap for tx antenna
  951. * @rx_ant: Bitmap for rx antenna
  952. *
  953. * Return: 0 on success, Negative error code on failure.
  954. */
  955. static int rsi_mac80211_set_antenna(struct ieee80211_hw *hw,
  956. u32 tx_ant, u32 rx_ant)
  957. {
  958. struct rsi_hw *adapter = hw->priv;
  959. struct rsi_common *common = adapter->priv;
  960. u8 antenna = 0;
  961. if (tx_ant > 1 || rx_ant > 1) {
  962. rsi_dbg(ERR_ZONE,
  963. "Invalid antenna selection (tx: %d, rx:%d)\n",
  964. tx_ant, rx_ant);
  965. rsi_dbg(ERR_ZONE,
  966. "Use 0 for int_ant, 1 for ext_ant\n");
  967. return -EINVAL;
  968. }
  969. rsi_dbg(INFO_ZONE, "%s: Antenna map Tx %x Rx %d\n",
  970. __func__, tx_ant, rx_ant);
  971. mutex_lock(&common->mutex);
  972. antenna = tx_ant ? ANTENNA_SEL_UFL : ANTENNA_SEL_INT;
  973. if (common->ant_in_use != antenna)
  974. if (rsi_set_antenna(common, antenna))
  975. goto fail_set_antenna;
  976. rsi_dbg(INFO_ZONE, "(%s) Antenna path configured successfully\n",
  977. tx_ant ? "UFL" : "INT");
  978. common->ant_in_use = antenna;
  979. mutex_unlock(&common->mutex);
  980. return 0;
  981. fail_set_antenna:
  982. rsi_dbg(ERR_ZONE, "%s: Failed.\n", __func__);
  983. mutex_unlock(&common->mutex);
  984. return -EINVAL;
  985. }
  986. /**
  987. * rsi_mac80211_get_antenna() - This function is used to configure
  988. * tx and rx antennas.
  989. *
  990. * @hw: Pointer to the ieee80211_hw structure.
  991. * @tx_ant: Bitmap for tx antenna
  992. * @rx_ant: Bitmap for rx antenna
  993. *
  994. * Return: 0 on success, -1 on failure.
  995. */
  996. static int rsi_mac80211_get_antenna(struct ieee80211_hw *hw,
  997. u32 *tx_ant, u32 *rx_ant)
  998. {
  999. struct rsi_hw *adapter = hw->priv;
  1000. struct rsi_common *common = adapter->priv;
  1001. mutex_lock(&common->mutex);
  1002. *tx_ant = (common->ant_in_use == ANTENNA_SEL_UFL) ? 1 : 0;
  1003. *rx_ant = 0;
  1004. mutex_unlock(&common->mutex);
  1005. return 0;
  1006. }
  1007. static void rsi_reg_notify(struct wiphy *wiphy,
  1008. struct regulatory_request *request)
  1009. {
  1010. struct ieee80211_supported_band *sband;
  1011. struct ieee80211_channel *ch;
  1012. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  1013. struct rsi_hw * adapter = hw->priv;
  1014. int i;
  1015. sband = wiphy->bands[NL80211_BAND_5GHZ];
  1016. for (i = 0; i < sband->n_channels; i++) {
  1017. ch = &sband->channels[i];
  1018. if (ch->flags & IEEE80211_CHAN_DISABLED)
  1019. continue;
  1020. if (ch->flags & IEEE80211_CHAN_RADAR)
  1021. ch->flags |= IEEE80211_CHAN_NO_IR;
  1022. }
  1023. rsi_dbg(INFO_ZONE,
  1024. "country = %s dfs_region = %d\n",
  1025. request->alpha2, request->dfs_region);
  1026. adapter->dfs_region = request->dfs_region;
  1027. }
  1028. static struct ieee80211_ops mac80211_ops = {
  1029. .tx = rsi_mac80211_tx,
  1030. .start = rsi_mac80211_start,
  1031. .stop = rsi_mac80211_stop,
  1032. .add_interface = rsi_mac80211_add_interface,
  1033. .remove_interface = rsi_mac80211_remove_interface,
  1034. .config = rsi_mac80211_config,
  1035. .bss_info_changed = rsi_mac80211_bss_info_changed,
  1036. .conf_tx = rsi_mac80211_conf_tx,
  1037. .configure_filter = rsi_mac80211_conf_filter,
  1038. .set_key = rsi_mac80211_set_key,
  1039. .set_rts_threshold = rsi_mac80211_set_rts_threshold,
  1040. .set_bitrate_mask = rsi_mac80211_set_rate_mask,
  1041. .ampdu_action = rsi_mac80211_ampdu_action,
  1042. .sta_add = rsi_mac80211_sta_add,
  1043. .sta_remove = rsi_mac80211_sta_remove,
  1044. .set_antenna = rsi_mac80211_set_antenna,
  1045. .get_antenna = rsi_mac80211_get_antenna,
  1046. };
  1047. /**
  1048. * rsi_mac80211_attach() - This function is used to initialize Mac80211 stack.
  1049. * @common: Pointer to the driver private structure.
  1050. *
  1051. * Return: 0 on success, -1 on failure.
  1052. */
  1053. int rsi_mac80211_attach(struct rsi_common *common)
  1054. {
  1055. int status = 0;
  1056. struct ieee80211_hw *hw = NULL;
  1057. struct wiphy *wiphy = NULL;
  1058. struct rsi_hw *adapter = common->priv;
  1059. u8 addr_mask[ETH_ALEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x3};
  1060. rsi_dbg(INIT_ZONE, "%s: Performing mac80211 attach\n", __func__);
  1061. hw = ieee80211_alloc_hw(sizeof(struct rsi_hw), &mac80211_ops);
  1062. if (!hw) {
  1063. rsi_dbg(ERR_ZONE, "%s: ieee80211 hw alloc failed\n", __func__);
  1064. return -ENOMEM;
  1065. }
  1066. wiphy = hw->wiphy;
  1067. SET_IEEE80211_DEV(hw, adapter->device);
  1068. hw->priv = adapter;
  1069. adapter->hw = hw;
  1070. ieee80211_hw_set(hw, SIGNAL_DBM);
  1071. ieee80211_hw_set(hw, HAS_RATE_CONTROL);
  1072. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  1073. hw->queues = MAX_HW_QUEUES;
  1074. hw->extra_tx_headroom = RSI_NEEDED_HEADROOM;
  1075. hw->max_rates = 1;
  1076. hw->max_rate_tries = MAX_RETRIES;
  1077. hw->max_tx_aggregation_subframes = 6;
  1078. rsi_register_rates_channels(adapter, NL80211_BAND_2GHZ);
  1079. rsi_register_rates_channels(adapter, NL80211_BAND_5GHZ);
  1080. hw->rate_control_algorithm = "AARF";
  1081. SET_IEEE80211_PERM_ADDR(hw, common->mac_addr);
  1082. ether_addr_copy(hw->wiphy->addr_mask, addr_mask);
  1083. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  1084. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1085. wiphy->retry_short = RETRY_SHORT;
  1086. wiphy->retry_long = RETRY_LONG;
  1087. wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  1088. wiphy->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  1089. wiphy->flags = 0;
  1090. wiphy->available_antennas_rx = 1;
  1091. wiphy->available_antennas_tx = 1;
  1092. wiphy->bands[NL80211_BAND_2GHZ] =
  1093. &adapter->sbands[NL80211_BAND_2GHZ];
  1094. wiphy->bands[NL80211_BAND_5GHZ] =
  1095. &adapter->sbands[NL80211_BAND_5GHZ];
  1096. wiphy->reg_notifier = rsi_reg_notify;
  1097. status = ieee80211_register_hw(hw);
  1098. if (status)
  1099. return status;
  1100. return rsi_init_dbgfs(adapter);
  1101. }