rsi_91x_mac80211.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  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_8K;
  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_attach() - 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_mac80211_config() - This function is a handler for configuration
  313. * requests. The stack calls this function to
  314. * change hardware configuration, e.g., channel.
  315. * @hw: Pointer to the ieee80211_hw structure.
  316. * @changed: Changed flags set.
  317. *
  318. * Return: 0 on success, negative error code on failure.
  319. */
  320. static int rsi_mac80211_config(struct ieee80211_hw *hw,
  321. u32 changed)
  322. {
  323. struct rsi_hw *adapter = hw->priv;
  324. struct rsi_common *common = adapter->priv;
  325. int status = -EOPNOTSUPP;
  326. mutex_lock(&common->mutex);
  327. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  328. struct ieee80211_channel *curchan = hw->conf.chandef.chan;
  329. u16 channel = curchan->hw_value;
  330. rsi_dbg(INFO_ZONE,
  331. "%s: Set channel: %d MHz type: %d channel_no %d\n",
  332. __func__, curchan->center_freq,
  333. curchan->flags, channel);
  334. common->band = curchan->band;
  335. status = rsi_set_channel(adapter->priv, channel);
  336. }
  337. mutex_unlock(&common->mutex);
  338. return status;
  339. }
  340. /**
  341. * rsi_get_connected_channel() - This function is used to get the current
  342. * connected channel number.
  343. * @adapter: Pointer to the adapter structure.
  344. *
  345. * Return: Current connected AP's channel number is returned.
  346. */
  347. u16 rsi_get_connected_channel(struct rsi_hw *adapter)
  348. {
  349. struct ieee80211_vif *vif = adapter->vifs[0];
  350. if (vif) {
  351. struct ieee80211_bss_conf *bss = &vif->bss_conf;
  352. struct ieee80211_channel *channel = bss->chandef.chan;
  353. return channel->hw_value;
  354. }
  355. return 0;
  356. }
  357. /**
  358. * rsi_mac80211_bss_info_changed() - This function is a handler for config
  359. * requests related to BSS parameters that
  360. * may vary during BSS's lifespan.
  361. * @hw: Pointer to the ieee80211_hw structure.
  362. * @vif: Pointer to the ieee80211_vif structure.
  363. * @bss_conf: Pointer to the ieee80211_bss_conf structure.
  364. * @changed: Changed flags set.
  365. *
  366. * Return: None.
  367. */
  368. static void rsi_mac80211_bss_info_changed(struct ieee80211_hw *hw,
  369. struct ieee80211_vif *vif,
  370. struct ieee80211_bss_conf *bss_conf,
  371. u32 changed)
  372. {
  373. struct rsi_hw *adapter = hw->priv;
  374. struct rsi_common *common = adapter->priv;
  375. mutex_lock(&common->mutex);
  376. if (changed & BSS_CHANGED_ASSOC) {
  377. rsi_dbg(INFO_ZONE, "%s: Changed Association status: %d\n",
  378. __func__, bss_conf->assoc);
  379. rsi_inform_bss_status(common,
  380. bss_conf->assoc,
  381. bss_conf->bssid,
  382. bss_conf->qos,
  383. bss_conf->aid);
  384. }
  385. mutex_unlock(&common->mutex);
  386. }
  387. /**
  388. * rsi_mac80211_conf_filter() - This function configure the device's RX filter.
  389. * @hw: Pointer to the ieee80211_hw structure.
  390. * @changed: Changed flags set.
  391. * @total_flags: Total initial flags set.
  392. * @multicast: Multicast.
  393. *
  394. * Return: None.
  395. */
  396. static void rsi_mac80211_conf_filter(struct ieee80211_hw *hw,
  397. u32 changed_flags,
  398. u32 *total_flags,
  399. u64 multicast)
  400. {
  401. /* Not doing much here as of now */
  402. *total_flags &= RSI_SUPP_FILTERS;
  403. }
  404. /**
  405. * rsi_mac80211_conf_tx() - This function configures TX queue parameters
  406. * (EDCF (aifs, cw_min, cw_max), bursting)
  407. * for a hardware TX queue.
  408. * @hw: Pointer to the ieee80211_hw structure
  409. * @vif: Pointer to the ieee80211_vif structure.
  410. * @queue: Queue number.
  411. * @params: Pointer to ieee80211_tx_queue_params structure.
  412. *
  413. * Return: 0 on success, negative error code on failure.
  414. */
  415. static int rsi_mac80211_conf_tx(struct ieee80211_hw *hw,
  416. struct ieee80211_vif *vif, u16 queue,
  417. const struct ieee80211_tx_queue_params *params)
  418. {
  419. struct rsi_hw *adapter = hw->priv;
  420. struct rsi_common *common = adapter->priv;
  421. u8 idx = 0;
  422. if (queue >= IEEE80211_NUM_ACS)
  423. return 0;
  424. rsi_dbg(INFO_ZONE,
  425. "%s: Conf queue %d, aifs: %d, cwmin: %d cwmax: %d, txop: %d\n",
  426. __func__, queue, params->aifs,
  427. params->cw_min, params->cw_max, params->txop);
  428. mutex_lock(&common->mutex);
  429. /* Map into the way the f/w expects */
  430. switch (queue) {
  431. case IEEE80211_AC_VO:
  432. idx = VO_Q;
  433. break;
  434. case IEEE80211_AC_VI:
  435. idx = VI_Q;
  436. break;
  437. case IEEE80211_AC_BE:
  438. idx = BE_Q;
  439. break;
  440. case IEEE80211_AC_BK:
  441. idx = BK_Q;
  442. break;
  443. default:
  444. idx = BE_Q;
  445. break;
  446. }
  447. memcpy(&common->edca_params[idx],
  448. params,
  449. sizeof(struct ieee80211_tx_queue_params));
  450. mutex_unlock(&common->mutex);
  451. return 0;
  452. }
  453. /**
  454. * rsi_hal_key_config() - This function loads the keys into the firmware.
  455. * @hw: Pointer to the ieee80211_hw structure.
  456. * @vif: Pointer to the ieee80211_vif structure.
  457. * @key: Pointer to the ieee80211_key_conf structure.
  458. *
  459. * Return: status: 0 on success, -1 on failure.
  460. */
  461. static int rsi_hal_key_config(struct ieee80211_hw *hw,
  462. struct ieee80211_vif *vif,
  463. struct ieee80211_key_conf *key)
  464. {
  465. struct rsi_hw *adapter = hw->priv;
  466. int status;
  467. u8 key_type;
  468. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  469. key_type = RSI_PAIRWISE_KEY;
  470. else
  471. key_type = RSI_GROUP_KEY;
  472. rsi_dbg(ERR_ZONE, "%s: Cipher 0x%x key_type: %d key_len: %d\n",
  473. __func__, key->cipher, key_type, key->keylen);
  474. if ((key->cipher == WLAN_CIPHER_SUITE_WEP104) ||
  475. (key->cipher == WLAN_CIPHER_SUITE_WEP40)) {
  476. status = rsi_hal_load_key(adapter->priv,
  477. key->key,
  478. key->keylen,
  479. RSI_PAIRWISE_KEY,
  480. key->keyidx,
  481. key->cipher);
  482. if (status)
  483. return status;
  484. }
  485. return rsi_hal_load_key(adapter->priv,
  486. key->key,
  487. key->keylen,
  488. key_type,
  489. key->keyidx,
  490. key->cipher);
  491. }
  492. /**
  493. * rsi_mac80211_set_key() - This function sets type of key to be loaded.
  494. * @hw: Pointer to the ieee80211_hw structure.
  495. * @cmd: enum set_key_cmd.
  496. * @vif: Pointer to the ieee80211_vif structure.
  497. * @sta: Pointer to the ieee80211_sta structure.
  498. * @key: Pointer to the ieee80211_key_conf structure.
  499. *
  500. * Return: status: 0 on success, negative error code on failure.
  501. */
  502. static int rsi_mac80211_set_key(struct ieee80211_hw *hw,
  503. enum set_key_cmd cmd,
  504. struct ieee80211_vif *vif,
  505. struct ieee80211_sta *sta,
  506. struct ieee80211_key_conf *key)
  507. {
  508. struct rsi_hw *adapter = hw->priv;
  509. struct rsi_common *common = adapter->priv;
  510. struct security_info *secinfo = &common->secinfo;
  511. int status;
  512. mutex_lock(&common->mutex);
  513. switch (cmd) {
  514. case SET_KEY:
  515. secinfo->security_enable = true;
  516. status = rsi_hal_key_config(hw, vif, key);
  517. if (status) {
  518. mutex_unlock(&common->mutex);
  519. return status;
  520. }
  521. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  522. secinfo->ptk_cipher = key->cipher;
  523. else
  524. secinfo->gtk_cipher = key->cipher;
  525. key->hw_key_idx = key->keyidx;
  526. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  527. rsi_dbg(ERR_ZONE, "%s: RSI set_key\n", __func__);
  528. break;
  529. case DISABLE_KEY:
  530. secinfo->security_enable = false;
  531. rsi_dbg(ERR_ZONE, "%s: RSI del key\n", __func__);
  532. memset(key, 0, sizeof(struct ieee80211_key_conf));
  533. status = rsi_hal_key_config(hw, vif, key);
  534. break;
  535. default:
  536. status = -EOPNOTSUPP;
  537. break;
  538. }
  539. mutex_unlock(&common->mutex);
  540. return status;
  541. }
  542. /**
  543. * rsi_mac80211_ampdu_action() - This function selects the AMPDU action for
  544. * the corresponding mlme_action flag and
  545. * informs the f/w regarding this.
  546. * @hw: Pointer to the ieee80211_hw structure.
  547. * @vif: Pointer to the ieee80211_vif structure.
  548. * @action: ieee80211_ampdu_mlme_action enum.
  549. * @sta: Pointer to the ieee80211_sta structure.
  550. * @tid: Traffic identifier.
  551. * @ssn: Pointer to ssn value.
  552. * @buf_size: Buffer size (for kernel version > 2.6.38).
  553. *
  554. * Return: status: 0 on success, negative error code on failure.
  555. */
  556. static int rsi_mac80211_ampdu_action(struct ieee80211_hw *hw,
  557. struct ieee80211_vif *vif,
  558. enum ieee80211_ampdu_mlme_action action,
  559. struct ieee80211_sta *sta,
  560. unsigned short tid,
  561. unsigned short *ssn,
  562. unsigned char buf_size)
  563. {
  564. int status = -EOPNOTSUPP;
  565. struct rsi_hw *adapter = hw->priv;
  566. struct rsi_common *common = adapter->priv;
  567. u16 seq_no = 0;
  568. u8 ii = 0;
  569. for (ii = 0; ii < RSI_MAX_VIFS; ii++) {
  570. if (vif == adapter->vifs[ii])
  571. break;
  572. }
  573. mutex_lock(&common->mutex);
  574. rsi_dbg(INFO_ZONE, "%s: AMPDU action %d called\n", __func__, action);
  575. if (ssn != NULL)
  576. seq_no = *ssn;
  577. switch (action) {
  578. case IEEE80211_AMPDU_RX_START:
  579. status = rsi_send_aggregation_params_frame(common,
  580. tid,
  581. seq_no,
  582. buf_size,
  583. STA_RX_ADDBA_DONE);
  584. break;
  585. case IEEE80211_AMPDU_RX_STOP:
  586. status = rsi_send_aggregation_params_frame(common,
  587. tid,
  588. 0,
  589. buf_size,
  590. STA_RX_DELBA);
  591. break;
  592. case IEEE80211_AMPDU_TX_START:
  593. common->vif_info[ii].seq_start = seq_no;
  594. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  595. status = 0;
  596. break;
  597. case IEEE80211_AMPDU_TX_STOP_CONT:
  598. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  599. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  600. status = rsi_send_aggregation_params_frame(common,
  601. tid,
  602. seq_no,
  603. buf_size,
  604. STA_TX_DELBA);
  605. if (!status)
  606. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  607. break;
  608. case IEEE80211_AMPDU_TX_OPERATIONAL:
  609. status = rsi_send_aggregation_params_frame(common,
  610. tid,
  611. common->vif_info[ii]
  612. .seq_start,
  613. buf_size,
  614. STA_TX_ADDBA_DONE);
  615. break;
  616. default:
  617. rsi_dbg(ERR_ZONE, "%s: Uknown AMPDU action\n", __func__);
  618. break;
  619. }
  620. mutex_unlock(&common->mutex);
  621. return status;
  622. }
  623. /**
  624. * rsi_mac80211_set_rts_threshold() - This function sets rts threshold value.
  625. * @hw: Pointer to the ieee80211_hw structure.
  626. * @value: Rts threshold value.
  627. *
  628. * Return: 0 on success.
  629. */
  630. static int rsi_mac80211_set_rts_threshold(struct ieee80211_hw *hw,
  631. u32 value)
  632. {
  633. struct rsi_hw *adapter = hw->priv;
  634. struct rsi_common *common = adapter->priv;
  635. mutex_lock(&common->mutex);
  636. common->rts_threshold = value;
  637. mutex_unlock(&common->mutex);
  638. return 0;
  639. }
  640. /**
  641. * rsi_mac80211_set_rate_mask() - This function sets bitrate_mask to be used.
  642. * @hw: Pointer to the ieee80211_hw structure
  643. * @vif: Pointer to the ieee80211_vif structure.
  644. * @mask: Pointer to the cfg80211_bitrate_mask structure.
  645. *
  646. * Return: 0 on success.
  647. */
  648. static int rsi_mac80211_set_rate_mask(struct ieee80211_hw *hw,
  649. struct ieee80211_vif *vif,
  650. const struct cfg80211_bitrate_mask *mask)
  651. {
  652. struct rsi_hw *adapter = hw->priv;
  653. struct rsi_common *common = adapter->priv;
  654. mutex_lock(&common->mutex);
  655. common->fixedrate_mask[IEEE80211_BAND_2GHZ] = 0;
  656. if (mask->control[IEEE80211_BAND_2GHZ].legacy == 0xfff) {
  657. common->fixedrate_mask[IEEE80211_BAND_2GHZ] =
  658. (mask->control[IEEE80211_BAND_2GHZ].ht_mcs[0] << 12);
  659. } else {
  660. common->fixedrate_mask[IEEE80211_BAND_2GHZ] =
  661. mask->control[IEEE80211_BAND_2GHZ].legacy;
  662. }
  663. mutex_unlock(&common->mutex);
  664. return 0;
  665. }
  666. /**
  667. * rsi_fill_rx_status() - This function fills rx status in
  668. * ieee80211_rx_status structure.
  669. * @hw: Pointer to the ieee80211_hw structure.
  670. * @skb: Pointer to the socket buffer structure.
  671. * @common: Pointer to the driver private structure.
  672. * @rxs: Pointer to the ieee80211_rx_status structure.
  673. *
  674. * Return: None.
  675. */
  676. static void rsi_fill_rx_status(struct ieee80211_hw *hw,
  677. struct sk_buff *skb,
  678. struct rsi_common *common,
  679. struct ieee80211_rx_status *rxs)
  680. {
  681. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  682. struct skb_info *rx_params = (struct skb_info *)info->driver_data;
  683. struct ieee80211_hdr *hdr;
  684. char rssi = rx_params->rssi;
  685. u8 hdrlen = 0;
  686. u8 channel = rx_params->channel;
  687. s32 freq;
  688. hdr = ((struct ieee80211_hdr *)(skb->data));
  689. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  690. memset(info, 0, sizeof(struct ieee80211_tx_info));
  691. rxs->signal = -(rssi);
  692. if (channel <= 14)
  693. rxs->band = IEEE80211_BAND_2GHZ;
  694. else
  695. rxs->band = IEEE80211_BAND_5GHZ;
  696. freq = ieee80211_channel_to_frequency(channel, rxs->band);
  697. if (freq)
  698. rxs->freq = freq;
  699. if (ieee80211_has_protected(hdr->frame_control)) {
  700. if (rsi_is_cipher_wep(common)) {
  701. memmove(skb->data + 4, skb->data, hdrlen);
  702. skb_pull(skb, 4);
  703. } else {
  704. memmove(skb->data + 8, skb->data, hdrlen);
  705. skb_pull(skb, 8);
  706. rxs->flag |= RX_FLAG_MMIC_STRIPPED;
  707. }
  708. rxs->flag |= RX_FLAG_DECRYPTED;
  709. rxs->flag |= RX_FLAG_IV_STRIPPED;
  710. }
  711. }
  712. /**
  713. * rsi_indicate_pkt_to_os() - This function sends recieved packet to mac80211.
  714. * @common: Pointer to the driver private structure.
  715. * @skb: Pointer to the socket buffer structure.
  716. *
  717. * Return: None.
  718. */
  719. void rsi_indicate_pkt_to_os(struct rsi_common *common,
  720. struct sk_buff *skb)
  721. {
  722. struct rsi_hw *adapter = common->priv;
  723. struct ieee80211_hw *hw = adapter->hw;
  724. struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
  725. if ((common->iface_down) || (!adapter->sc_nvifs)) {
  726. dev_kfree_skb(skb);
  727. return;
  728. }
  729. /* filling in the ieee80211_rx_status flags */
  730. rsi_fill_rx_status(hw, skb, common, rx_status);
  731. ieee80211_rx_irqsafe(hw, skb);
  732. }
  733. static void rsi_set_min_rate(struct ieee80211_hw *hw,
  734. struct ieee80211_sta *sta,
  735. struct rsi_common *common)
  736. {
  737. u8 band = hw->conf.chandef.chan->band;
  738. u8 ii;
  739. u32 rate_bitmap;
  740. bool matched = false;
  741. common->bitrate_mask[band] = sta->supp_rates[band];
  742. rate_bitmap = (common->fixedrate_mask[band] & sta->supp_rates[band]);
  743. if (rate_bitmap & 0xfff) {
  744. /* Find out the min rate */
  745. for (ii = 0; ii < ARRAY_SIZE(rsi_rates); ii++) {
  746. if (rate_bitmap & BIT(ii)) {
  747. common->min_rate = rsi_rates[ii].hw_value;
  748. matched = true;
  749. break;
  750. }
  751. }
  752. }
  753. common->vif_info[0].is_ht = sta->ht_cap.ht_supported;
  754. if ((common->vif_info[0].is_ht) && (rate_bitmap >> 12)) {
  755. for (ii = 0; ii < ARRAY_SIZE(rsi_mcsrates); ii++) {
  756. if ((rate_bitmap >> 12) & BIT(ii)) {
  757. common->min_rate = rsi_mcsrates[ii];
  758. matched = true;
  759. break;
  760. }
  761. }
  762. }
  763. if (!matched)
  764. common->min_rate = 0xffff;
  765. }
  766. /**
  767. * rsi_mac80211_sta_add() - This function notifies driver about a peer getting
  768. * connected.
  769. * @hw: pointer to the ieee80211_hw structure.
  770. * @vif: Pointer to the ieee80211_vif structure.
  771. * @sta: Pointer to the ieee80211_sta structure.
  772. *
  773. * Return: 0 on success, -1 on failure.
  774. */
  775. static int rsi_mac80211_sta_add(struct ieee80211_hw *hw,
  776. struct ieee80211_vif *vif,
  777. struct ieee80211_sta *sta)
  778. {
  779. struct rsi_hw *adapter = hw->priv;
  780. struct rsi_common *common = adapter->priv;
  781. mutex_lock(&common->mutex);
  782. rsi_set_min_rate(hw, sta, common);
  783. if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ||
  784. (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)) {
  785. common->vif_info[0].sgi = true;
  786. }
  787. if (sta->ht_cap.ht_supported)
  788. ieee80211_start_tx_ba_session(sta, 0, 0);
  789. mutex_unlock(&common->mutex);
  790. return 0;
  791. }
  792. /**
  793. * rsi_mac80211_sta_remove() - This function notifies driver about a peer
  794. * getting disconnected.
  795. * @hw: Pointer to the ieee80211_hw structure.
  796. * @vif: Pointer to the ieee80211_vif structure.
  797. * @sta: Pointer to the ieee80211_sta structure.
  798. *
  799. * Return: 0 on success, -1 on failure.
  800. */
  801. static int rsi_mac80211_sta_remove(struct ieee80211_hw *hw,
  802. struct ieee80211_vif *vif,
  803. struct ieee80211_sta *sta)
  804. {
  805. struct rsi_hw *adapter = hw->priv;
  806. struct rsi_common *common = adapter->priv;
  807. mutex_lock(&common->mutex);
  808. /* Resetting all the fields to default values */
  809. common->bitrate_mask[IEEE80211_BAND_2GHZ] = 0;
  810. common->bitrate_mask[IEEE80211_BAND_5GHZ] = 0;
  811. common->min_rate = 0xffff;
  812. common->vif_info[0].is_ht = false;
  813. common->vif_info[0].sgi = false;
  814. common->vif_info[0].seq_start = 0;
  815. common->secinfo.ptk_cipher = 0;
  816. common->secinfo.gtk_cipher = 0;
  817. mutex_unlock(&common->mutex);
  818. return 0;
  819. }
  820. static struct ieee80211_ops mac80211_ops = {
  821. .tx = rsi_mac80211_tx,
  822. .start = rsi_mac80211_start,
  823. .stop = rsi_mac80211_stop,
  824. .add_interface = rsi_mac80211_add_interface,
  825. .remove_interface = rsi_mac80211_remove_interface,
  826. .config = rsi_mac80211_config,
  827. .bss_info_changed = rsi_mac80211_bss_info_changed,
  828. .conf_tx = rsi_mac80211_conf_tx,
  829. .configure_filter = rsi_mac80211_conf_filter,
  830. .set_key = rsi_mac80211_set_key,
  831. .set_rts_threshold = rsi_mac80211_set_rts_threshold,
  832. .set_bitrate_mask = rsi_mac80211_set_rate_mask,
  833. .ampdu_action = rsi_mac80211_ampdu_action,
  834. .sta_add = rsi_mac80211_sta_add,
  835. .sta_remove = rsi_mac80211_sta_remove,
  836. };
  837. /**
  838. * rsi_mac80211_attach() - This function is used to initialize Mac80211 stack.
  839. * @common: Pointer to the driver private structure.
  840. *
  841. * Return: 0 on success, -1 on failure.
  842. */
  843. int rsi_mac80211_attach(struct rsi_common *common)
  844. {
  845. int status = 0;
  846. struct ieee80211_hw *hw = NULL;
  847. struct wiphy *wiphy = NULL;
  848. struct rsi_hw *adapter = common->priv;
  849. u8 addr_mask[ETH_ALEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x3};
  850. rsi_dbg(INIT_ZONE, "%s: Performing mac80211 attach\n", __func__);
  851. hw = ieee80211_alloc_hw(sizeof(struct rsi_hw), &mac80211_ops);
  852. if (!hw) {
  853. rsi_dbg(ERR_ZONE, "%s: ieee80211 hw alloc failed\n", __func__);
  854. return -ENOMEM;
  855. }
  856. wiphy = hw->wiphy;
  857. SET_IEEE80211_DEV(hw, adapter->device);
  858. hw->priv = adapter;
  859. adapter->hw = hw;
  860. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  861. IEEE80211_HW_HAS_RATE_CONTROL |
  862. IEEE80211_HW_AMPDU_AGGREGATION |
  863. 0;
  864. hw->queues = MAX_HW_QUEUES;
  865. hw->extra_tx_headroom = RSI_NEEDED_HEADROOM;
  866. hw->max_rates = 1;
  867. hw->max_rate_tries = MAX_RETRIES;
  868. hw->max_tx_aggregation_subframes = 6;
  869. rsi_register_rates_channels(adapter, IEEE80211_BAND_2GHZ);
  870. hw->rate_control_algorithm = "AARF";
  871. SET_IEEE80211_PERM_ADDR(hw, common->mac_addr);
  872. ether_addr_copy(hw->wiphy->addr_mask, addr_mask);
  873. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  874. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  875. wiphy->retry_short = RETRY_SHORT;
  876. wiphy->retry_long = RETRY_LONG;
  877. wiphy->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  878. wiphy->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  879. wiphy->flags = 0;
  880. wiphy->available_antennas_rx = 1;
  881. wiphy->available_antennas_tx = 1;
  882. wiphy->bands[IEEE80211_BAND_2GHZ] =
  883. &adapter->sbands[IEEE80211_BAND_2GHZ];
  884. status = ieee80211_register_hw(hw);
  885. if (status)
  886. return status;
  887. return rsi_init_dbgfs(adapter);
  888. }