rsi_91x_mac80211.c 44 KB

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