rsi_91x_mac80211.c 55 KB

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