rsi_91x_mac80211.c 54 KB

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