0002-wifi.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. From 8ff6f12fa7093981493e63b56830bd22f634750c Mon Sep 17 00:00:00 2001
  2. From: kitakar5525 <34676735+kitakar5525@users.noreply.github.com>
  3. Date: Thu, 20 Feb 2020 16:51:11 +0900
  4. Subject: [PATCH 2/6] wifi
  5. ---
  6. .../net/wireless/marvell/mwifiex/cfg80211.c | 26 ++++++
  7. drivers/net/wireless/marvell/mwifiex/fw.h | 2 +-
  8. drivers/net/wireless/marvell/mwifiex/pcie.c | 84 +++++++++++--------
  9. .../net/wireless/marvell/mwifiex/sta_cmd.c | 31 ++-----
  10. .../wireless/marvell/mwifiex/sta_cmdresp.c | 4 +-
  11. 5 files changed, 87 insertions(+), 60 deletions(-)
  12. diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
  13. index 12bfd653a4052..68404a1767945 100644
  14. --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
  15. +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
  16. @@ -25,6 +25,11 @@
  17. static char *reg_alpha2;
  18. module_param(reg_alpha2, charp, 0);
  19. +static bool allow_ps_mode;
  20. +module_param(allow_ps_mode, bool, 0444);
  21. +MODULE_PARM_DESC(allow_ps_mode,
  22. + "allow WiFi power management to be enabled. (default: disallowed)");
  23. +
  24. static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = {
  25. {
  26. .max = 3, .types = BIT(NL80211_IFTYPE_STATION) |
  27. @@ -439,6 +444,27 @@ mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy,
  28. ps_mode = enabled;
  29. + /* Allow ps_mode to be enabled only when allow_ps_mode is set
  30. + * (but always allow ps_mode to be disabled in case it gets enabled
  31. + * for unknown reason and you want to disable it) */
  32. + if (ps_mode && !allow_ps_mode) {
  33. + dev_info(priv->adapter->dev,
  34. + "Request to enable ps_mode received but it's disallowed "
  35. + "by module parameter. Rejecting the request.\n");
  36. +
  37. + /* Return negative value to inform userspace tools that setting
  38. + * power_save to be enabled is not permitted. */
  39. + return -1;
  40. + }
  41. +
  42. + if (ps_mode)
  43. + dev_warn(priv->adapter->dev,
  44. + "WARN: Request to enable ps_mode received. Enabling it. "
  45. + "Disable it if you encounter connection instability.\n");
  46. + else
  47. + dev_info(priv->adapter->dev,
  48. + "Request to disable ps_mode received. Disabling it.\n");
  49. +
  50. return mwifiex_drv_set_power(priv, &ps_mode);
  51. }
  52. diff --git a/drivers/net/wireless/marvell/mwifiex/fw.h b/drivers/net/wireless/marvell/mwifiex/fw.h
  53. index a415d73a73e62..d55e70a411d77 100644
  54. --- a/drivers/net/wireless/marvell/mwifiex/fw.h
  55. +++ b/drivers/net/wireless/marvell/mwifiex/fw.h
  56. @@ -953,7 +953,7 @@ struct mwifiex_tkip_param {
  57. struct mwifiex_aes_param {
  58. u8 pn[WPA_PN_SIZE];
  59. __le16 key_len;
  60. - u8 key[WLAN_KEY_LEN_CCMP];
  61. + u8 key[WLAN_KEY_LEN_CCMP_256];
  62. } __packed;
  63. struct mwifiex_wapi_param {
  64. diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c
  65. index 87b4ccca4b9a2..3bdad5e80ecbb 100644
  66. --- a/drivers/net/wireless/marvell/mwifiex/pcie.c
  67. +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c
  68. @@ -146,38 +146,45 @@ static bool mwifiex_pcie_ok_to_access_hw(struct mwifiex_adapter *adapter)
  69. *
  70. * If already not suspended, this function allocates and sends a host
  71. * sleep activate request to the firmware and turns off the traffic.
  72. + *
  73. + * XXX: ignoring all the above comment and just removes the card to
  74. + * fix S0ix and "AP scanning (sometimes) not working after suspend".
  75. + * Required code is extracted from mwifiex_pcie_remove().
  76. */
  77. static int mwifiex_pcie_suspend(struct device *dev)
  78. {
  79. + struct pci_dev *pdev = to_pci_dev(dev);
  80. + struct pcie_service_card *card = pci_get_drvdata(pdev);
  81. struct mwifiex_adapter *adapter;
  82. - struct pcie_service_card *card = dev_get_drvdata(dev);
  83. -
  84. + struct mwifiex_private *priv;
  85. + const struct mwifiex_pcie_card_reg *reg;
  86. + u32 fw_status;
  87. + int ret;
  88. /* Might still be loading firmware */
  89. wait_for_completion(&card->fw_done);
  90. adapter = card->adapter;
  91. - if (!adapter) {
  92. - dev_err(dev, "adapter is not valid\n");
  93. + if (!adapter || !adapter->priv_num)
  94. return 0;
  95. - }
  96. - mwifiex_enable_wake(adapter);
  97. + reg = card->pcie.reg;
  98. + if (reg)
  99. + ret = mwifiex_read_reg(adapter, reg->fw_status, &fw_status);
  100. + else
  101. + fw_status = -1;
  102. - /* Enable the Host Sleep */
  103. - if (!mwifiex_enable_hs(adapter)) {
  104. - mwifiex_dbg(adapter, ERROR,
  105. - "cmd: failed to suspend\n");
  106. - clear_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags);
  107. - mwifiex_disable_wake(adapter);
  108. - return -EFAULT;
  109. - }
  110. + if (fw_status == FIRMWARE_READY_PCIE && !adapter->mfg_mode) {
  111. + mwifiex_deauthenticate_all(adapter);
  112. - flush_workqueue(adapter->workqueue);
  113. + priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  114. +
  115. + mwifiex_disable_auto_ds(priv);
  116. - /* Indicate device suspended */
  117. - set_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
  118. - clear_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags);
  119. + mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN);
  120. + }
  121. +
  122. + mwifiex_remove_card(adapter);
  123. return 0;
  124. }
  125. @@ -189,31 +196,35 @@ static int mwifiex_pcie_suspend(struct device *dev)
  126. *
  127. * If already not resumed, this function turns on the traffic and
  128. * sends a host sleep cancel request to the firmware.
  129. + *
  130. + * XXX: ignoring all the above comment and probes the card that was
  131. + * removed on suspend. Required code is extracted from mwifiex_pcie_probe().
  132. */
  133. static int mwifiex_pcie_resume(struct device *dev)
  134. {
  135. - struct mwifiex_adapter *adapter;
  136. - struct pcie_service_card *card = dev_get_drvdata(dev);
  137. + struct pci_dev *pdev = to_pci_dev(dev);
  138. + struct pcie_service_card *card = pci_get_drvdata(pdev);
  139. + int ret;
  140. + pr_debug("info: vendor=0x%4.04X device=0x%4.04X rev=%d\n",
  141. + pdev->vendor, pdev->device, pdev->revision);
  142. - if (!card->adapter) {
  143. - dev_err(dev, "adapter structure is not valid\n");
  144. - return 0;
  145. - }
  146. + init_completion(&card->fw_done);
  147. - adapter = card->adapter;
  148. + card->dev = pdev;
  149. - if (!test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
  150. - mwifiex_dbg(adapter, WARN,
  151. - "Device already resumed\n");
  152. - return 0;
  153. + /* device tree node parsing and platform specific configuration */
  154. + if (pdev->dev.of_node) {
  155. + ret = mwifiex_pcie_probe_of(&pdev->dev);
  156. + if (ret)
  157. + return ret;
  158. }
  159. - clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
  160. -
  161. - mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
  162. - MWIFIEX_ASYNC_CMD);
  163. - mwifiex_disable_wake(adapter);
  164. + if (mwifiex_add_card(card, &card->fw_done, &pcie_ops,
  165. + MWIFIEX_PCIE, &pdev->dev)) {
  166. + pr_err("%s failed\n", __func__);
  167. + return -1;
  168. + }
  169. return 0;
  170. }
  171. @@ -229,8 +240,13 @@ static int mwifiex_pcie_probe(struct pci_dev *pdev,
  172. const struct pci_device_id *ent)
  173. {
  174. struct pcie_service_card *card;
  175. + struct pci_dev *parent_pdev = pci_upstream_bridge(pdev);
  176. int ret;
  177. + /* disable bridge_d3 to fix driver crashing after suspend on gen4+
  178. + * Surface devices */
  179. + parent_pdev->bridge_d3 = false;
  180. +
  181. pr_debug("info: vendor=0x%4.04X device=0x%4.04X rev=%d\n",
  182. pdev->vendor, pdev->device, pdev->revision);
  183. diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
  184. index 0bd93f26bd7f8..91b03423c09d0 100644
  185. --- a/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
  186. +++ b/drivers/net/wireless/marvell/mwifiex/sta_cmd.c
  187. @@ -2254,7 +2254,6 @@ int mwifiex_sta_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
  188. * - Function init (for first interface only)
  189. * - Read MAC address (for first interface only)
  190. * - Reconfigure Tx buffer size (for first interface only)
  191. - * - Enable auto deep sleep (for first interface only)
  192. * - Get Tx rate
  193. * - Get Tx power
  194. * - Set IBSS coalescing status
  195. @@ -2267,7 +2266,6 @@ int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta, bool init)
  196. struct mwifiex_adapter *adapter = priv->adapter;
  197. int ret;
  198. struct mwifiex_ds_11n_amsdu_aggr_ctrl amsdu_aggr_ctrl;
  199. - struct mwifiex_ds_auto_ds auto_ds;
  200. enum state_11d_t state_11d;
  201. struct mwifiex_ds_11n_tx_cfg tx_cfg;
  202. u8 sdio_sp_rx_aggr_enable;
  203. @@ -2339,16 +2337,10 @@ int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta, bool init)
  204. if (ret)
  205. return -1;
  206. - if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  207. - /* Enable IEEE PS by default */
  208. - priv->adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
  209. - ret = mwifiex_send_cmd(priv,
  210. - HostCmd_CMD_802_11_PS_MODE_ENH,
  211. - EN_AUTO_PS, BITMAP_STA_PS, NULL,
  212. - true);
  213. - if (ret)
  214. - return -1;
  215. - }
  216. + /* Not enabling ps_mode (IEEE power_save) by default. Enabling
  217. + * this causes connection instability, especially on 5GHz APs
  218. + * and eventually causes "firmware wakeup failed". Therefore,
  219. + * the relevant code was removed from here. */
  220. if (drcs) {
  221. adapter->drcs_enabled = true;
  222. @@ -2395,17 +2387,10 @@ int mwifiex_sta_init_cmd(struct mwifiex_private *priv, u8 first_sta, bool init)
  223. if (ret)
  224. return -1;
  225. - if (!disable_auto_ds && first_sta &&
  226. - priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  227. - /* Enable auto deep sleep */
  228. - auto_ds.auto_ds = DEEP_SLEEP_ON;
  229. - auto_ds.idle_time = DEEP_SLEEP_IDLE_TIME;
  230. - ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
  231. - EN_AUTO_PS, BITMAP_AUTO_DS,
  232. - &auto_ds, true);
  233. - if (ret)
  234. - return -1;
  235. - }
  236. + /* Not enabling auto deep sleep (auto_ds) by default. Enabling
  237. + * this reportedly causes "suspend/resume fails when not connected
  238. + * to an Access Point." Therefore, the relevant code was removed
  239. + * from here. */
  240. if (priv->bss_type != MWIFIEX_BSS_TYPE_UAP) {
  241. /* Send cmd to FW to enable/disable 11D function */
  242. diff --git a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
  243. index 962d8bfe6f101..119ccacd1fcc4 100644
  244. --- a/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
  245. +++ b/drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c
  246. @@ -619,7 +619,7 @@ static int mwifiex_ret_802_11_key_material_v2(struct mwifiex_private *priv,
  247. key_v2 = &resp->params.key_material_v2;
  248. len = le16_to_cpu(key_v2->key_param_set.key_params.aes.key_len);
  249. - if (len > WLAN_KEY_LEN_CCMP)
  250. + if (len > sizeof(key_v2->key_param_set.key_params.aes.key))
  251. return -EINVAL;
  252. if (le16_to_cpu(key_v2->action) == HostCmd_ACT_GEN_SET) {
  253. @@ -635,7 +635,7 @@ static int mwifiex_ret_802_11_key_material_v2(struct mwifiex_private *priv,
  254. return 0;
  255. memset(priv->aes_key_v2.key_param_set.key_params.aes.key, 0,
  256. - WLAN_KEY_LEN_CCMP);
  257. + sizeof(key_v2->key_param_set.key_params.aes.key));
  258. priv->aes_key_v2.key_param_set.key_params.aes.key_len =
  259. cpu_to_le16(len);
  260. memcpy(priv->aes_key_v2.key_param_set.key_params.aes.key,
  261. --
  262. 2.28.0