Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all |
| 7 | * copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 10 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 12 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 15 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 16 | * PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
| 19 | /** |
| 20 | * DOC: wlan_hdd_green_ap.c |
| 21 | * |
| 22 | * WLAN Host Device Driver Green AP implementation |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <wlan_hdd_green_ap.h> |
| 27 | #include <wlan_hdd_main.h> |
| 28 | #include <wlan_policy_mgr_api.h> |
| 29 | #include <wlan_green_ap_ucfg_api.h> |
Abhinav Kumar | b074f2f | 2018-09-15 15:32:11 +0530 | [diff] [blame] | 30 | #include "wlan_mlme_ucfg_api.h" |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * hdd_green_ap_check_enable() - to check whether to enable green ap or not |
| 34 | * @hdd_ctx: hdd context |
| 35 | * @enable_green_ap: 1 - enable green ap enabled, 0 - disbale green ap |
| 36 | * |
| 37 | * Return: 0 - success, < 0 - failure |
| 38 | */ |
| 39 | static int hdd_green_ap_check_enable(struct hdd_context *hdd_ctx, |
| 40 | bool *enable_green_ap) |
| 41 | { |
| 42 | uint8_t num_sessions, mode; |
| 43 | QDF_STATUS status; |
| 44 | |
| 45 | for (mode = 0; |
| 46 | mode < QDF_MAX_NO_OF_MODE; |
| 47 | mode++) { |
| 48 | if (mode == QDF_SAP_MODE || mode == QDF_P2P_GO_MODE) |
| 49 | continue; |
| 50 | |
| 51 | status = policy_mgr_mode_specific_num_active_sessions( |
Dustin Brown | 1dbefe6 | 2018-09-11 16:32:03 -0700 | [diff] [blame] | 52 | hdd_ctx->psoc, mode, &num_sessions); |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 53 | hdd_debug("No. of active sessions for mode: %d is %d", |
| 54 | mode, num_sessions); |
| 55 | if (status != QDF_STATUS_SUCCESS) { |
| 56 | hdd_err("Failed to get num sessions for mode: %d", |
| 57 | mode); |
| 58 | return -EINVAL; |
| 59 | } else if (num_sessions) { |
| 60 | *enable_green_ap = false; |
| 61 | return 0; |
| 62 | } |
| 63 | } |
| 64 | *enable_green_ap = true; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | void hdd_green_ap_add_sta(struct hdd_context *hdd_ctx) |
| 69 | { |
Dustin Brown | 07901ec | 2018-09-07 11:02:41 -0700 | [diff] [blame] | 70 | wlan_green_ap_add_sta(hdd_ctx->pdev); |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void hdd_green_ap_del_sta(struct hdd_context *hdd_ctx) |
| 74 | { |
Dustin Brown | 07901ec | 2018-09-07 11:02:41 -0700 | [diff] [blame] | 75 | wlan_green_ap_del_sta(hdd_ctx->pdev); |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | int hdd_green_ap_enable_egap(struct hdd_context *hdd_ctx) |
| 79 | { |
| 80 | QDF_STATUS status; |
| 81 | |
Dustin Brown | 07901ec | 2018-09-07 11:02:41 -0700 | [diff] [blame] | 82 | status = ucfg_green_ap_enable_egap(hdd_ctx->pdev); |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 83 | if (QDF_IS_STATUS_ERROR(status)) { |
| 84 | hdd_debug("enhance green ap is not enabled, status %d", |
| 85 | status); |
| 86 | return qdf_status_to_os_return(status); |
| 87 | } |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 92 | int hdd_green_ap_start_state_mc(struct hdd_context *hdd_ctx, |
| 93 | enum QDF_OPMODE mode, bool is_session_start) |
| 94 | { |
| 95 | struct hdd_config *cfg; |
| 96 | bool enable_green_ap = false; |
| 97 | uint8_t num_sap_sessions = 0, num_p2p_go_sessions = 0, ret = 0; |
Abhinav Kumar | b074f2f | 2018-09-15 15:32:11 +0530 | [diff] [blame] | 98 | QDF_STATUS status; |
| 99 | bool bval = false; |
gaurank kathpalia | 4a205fc | 2018-09-15 00:59:15 +0530 | [diff] [blame] | 100 | uint8_t ps_enable; |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 101 | |
| 102 | cfg = hdd_ctx->config; |
| 103 | if (!cfg) { |
| 104 | hdd_err("NULL hdd config"); |
| 105 | return -EINVAL; |
| 106 | } |
| 107 | |
Abhinav Kumar | b074f2f | 2018-09-15 15:32:11 +0530 | [diff] [blame] | 108 | status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval); |
| 109 | if (!QDF_IS_STATUS_SUCCESS(status)) { |
| 110 | hdd_err("unable to get vht_enable2x2"); |
| 111 | return -EINVAL; |
| 112 | } |
| 113 | |
gaurank kathpalia | 4a205fc | 2018-09-15 00:59:15 +0530 | [diff] [blame] | 114 | if (!bval) { |
| 115 | hdd_debug(" 2x2 not enabled"); |
| 116 | } |
| 117 | |
| 118 | if (QDF_IS_STATUS_ERROR(ucfg_green_ap_get_ps_config(hdd_ctx->pdev, |
| 119 | &ps_enable))) |
| 120 | return 0; |
| 121 | |
| 122 | if (!ps_enable) { |
| 123 | hdd_debug("Green AP not enabled"); |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 124 | return 0; |
| 125 | } |
| 126 | |
Dustin Brown | 1dbefe6 | 2018-09-11 16:32:03 -0700 | [diff] [blame] | 127 | policy_mgr_mode_specific_num_active_sessions(hdd_ctx->psoc, |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 128 | QDF_SAP_MODE, |
| 129 | &num_sap_sessions); |
Dustin Brown | 1dbefe6 | 2018-09-11 16:32:03 -0700 | [diff] [blame] | 130 | policy_mgr_mode_specific_num_active_sessions(hdd_ctx->psoc, |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 131 | QDF_P2P_GO_MODE, |
| 132 | &num_p2p_go_sessions); |
| 133 | |
| 134 | switch (mode) { |
| 135 | case QDF_STA_MODE: |
| 136 | case QDF_P2P_CLIENT_MODE: |
| 137 | case QDF_IBSS_MODE: |
| 138 | if (!num_sap_sessions && !num_p2p_go_sessions) |
| 139 | return 0; |
| 140 | |
| 141 | if (is_session_start) { |
| 142 | hdd_debug("Disabling Green AP"); |
Dustin Brown | 07901ec | 2018-09-07 11:02:41 -0700 | [diff] [blame] | 143 | ucfg_green_ap_set_ps_config(hdd_ctx->pdev, |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 144 | false); |
Dustin Brown | 07901ec | 2018-09-07 11:02:41 -0700 | [diff] [blame] | 145 | wlan_green_ap_stop(hdd_ctx->pdev); |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 146 | } else { |
| 147 | ret = hdd_green_ap_check_enable(hdd_ctx, |
| 148 | &enable_green_ap); |
| 149 | if (!ret) { |
| 150 | if (enable_green_ap) { |
| 151 | hdd_debug("Enabling Green AP"); |
| 152 | ucfg_green_ap_set_ps_config( |
Dustin Brown | 07901ec | 2018-09-07 11:02:41 -0700 | [diff] [blame] | 153 | hdd_ctx->pdev, true); |
| 154 | wlan_green_ap_start(hdd_ctx->pdev); |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 155 | } |
| 156 | } else { |
| 157 | hdd_err("Failed to check Green AP enable status"); |
| 158 | } |
| 159 | } |
| 160 | break; |
| 161 | case QDF_SAP_MODE: |
| 162 | case QDF_P2P_GO_MODE: |
| 163 | if (is_session_start) { |
| 164 | ret = hdd_green_ap_check_enable(hdd_ctx, |
| 165 | &enable_green_ap); |
| 166 | if (!ret) { |
| 167 | if (enable_green_ap) { |
| 168 | hdd_debug("Enabling Green AP"); |
| 169 | ucfg_green_ap_set_ps_config( |
Dustin Brown | 07901ec | 2018-09-07 11:02:41 -0700 | [diff] [blame] | 170 | hdd_ctx->pdev, true); |
| 171 | wlan_green_ap_start(hdd_ctx->pdev); |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 172 | } |
| 173 | } else { |
| 174 | hdd_err("Failed to check Green AP enable status"); |
| 175 | } |
| 176 | } else { |
| 177 | if (!num_sap_sessions && !num_p2p_go_sessions) { |
| 178 | hdd_debug("Disabling Green AP"); |
Dustin Brown | 07901ec | 2018-09-07 11:02:41 -0700 | [diff] [blame] | 179 | ucfg_green_ap_set_ps_config(hdd_ctx->pdev, |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 180 | false); |
Dustin Brown | 07901ec | 2018-09-07 11:02:41 -0700 | [diff] [blame] | 181 | wlan_green_ap_stop(hdd_ctx->pdev); |
Jeff Johnson | 8bb6111 | 2018-03-31 13:33:54 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | break; |
| 185 | default: |
| 186 | break; |
| 187 | } |
| 188 | return ret; |
| 189 | } |