rsi_91x_mac80211.c 31 KB

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