rsi_91x_mac80211.c 54 KB

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