wireless: bcmdhd: support to get FW and NVRAM paths from DT
Bhadram Varka [Mon, 8 Feb 2016 04:18:19 +0000 (09:18 +0530)]
Added two DT properties for FIRMWARE path and NVRAM path.
Read these properties at the time of drive probe and
populate adapter fw_path and nv_path. The same will be
considered every time while doing path update.

Also adds the support for Antenna-tuned nvram path by
adding tuned_nv_path property. It will be populated if
the wifi-antenna-tuning dt node defined.

Added is_file_valid() for checking the existence of file.
It will be useful for other OS's to validate the file
existence.

Bug 1709222

Change-Id: Ic819b00620ec5e7890d1d1a9a9676672c089b25b
Signed-off-by: Bhadram Varka <vbhadram@nvidia.com>
Reviewed-on: http://git-master/r/929908
(cherry picked from commit c516251151b3b4c3214ca0d67d6b9ba698c03024)
Reviewed-on: http://git-master/r/1001152
Reviewed-by: Mohan Thadikamalla <mohant@nvidia.com>
Tested-by: Mohan Thadikamalla <mohant@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>

drivers/net/wireless/bcmdhd/dhd_linux.c
drivers/net/wireless/bcmdhd/dhd_linux_platdev.c
drivers/net/wireless/bcmdhd/wl_cfg80211.c

index 7fb5277..659cadf 100644 (file)
@@ -5425,6 +5425,27 @@ int dhd_get_fw_mode(dhd_info_t *dhdinfo)
        return DHD_FLAG_STA_MODE;
 }
 
+static inline bool is_file_valid(const char *file)
+{
+       struct file *fp;
+       mm_segment_t old_fs = get_fs();
+
+       if (!file)
+               return false;
+
+       set_fs(KERNEL_DS);
+
+       fp = filp_open(file, O_RDONLY, 0);
+       if (IS_ERR_OR_NULL(fp)) {
+               set_fs(old_fs);
+               return false;
+       }
+
+       filp_close(fp, NULL);
+       set_fs(old_fs);
+       return true;
+}
+
 bool dhd_update_fw_nv_path(dhd_info_t *dhdinfo)
 {
        int fw_len;
@@ -5447,21 +5468,23 @@ bool dhd_update_fw_nv_path(dhd_info_t *dhdinfo)
        /* set default firmware and nvram path for built-in type driver */
        if (!dhd_download_fw_on_driverload) {
 #ifdef CONFIG_BCMDHD_FW_PATH
-               fw = CONFIG_BCMDHD_FW_PATH;
+               if (is_file_valid(CONFIG_BCMDHD_FW_PATH))
+                       fw = CONFIG_BCMDHD_FW_PATH;
 #endif /* CONFIG_BCMDHD_FW_PATH */
 #ifdef CONFIG_BCMDHD_NVRAM_PATH
-               nv = CONFIG_BCMDHD_NVRAM_PATH;
+               if (is_file_valid(CONFIG_BCMDHD_NVRAM_PATH))
+                       nv = CONFIG_BCMDHD_NVRAM_PATH;
 #endif /* CONFIG_BCMDHD_NVRAM_PATH */
        }
 
        /* check if we need to initialize the path */
-       if (dhdinfo->fw_path[0] == '\0') {
-               if (adapter && adapter->fw_path && adapter->fw_path[0] != '\0')
+       if (adapter && adapter->fw_path && adapter->fw_path[0] != '\0') {
+               if (is_file_valid(adapter->fw_path))
                        fw = adapter->fw_path;
-
        }
-       if (dhdinfo->nv_path[0] == '\0') {
-               if (adapter && adapter->nv_path && adapter->nv_path[0] != '\0')
+
+       if (adapter && adapter->nv_path && adapter->nv_path[0] != '\0') {
+               if (is_file_valid(adapter->nv_path))
                        nv = adapter->nv_path;
        }
 
@@ -5469,10 +5492,15 @@ bool dhd_update_fw_nv_path(dhd_info_t *dhdinfo)
         *
         * TODO: need a solution for multi-chip, can't use the same firmware for all chips
         */
-       if (firmware_path[0] != '\0')
-               fw = firmware_path;
-       if (nvram_path[0] != '\0')
-               nv = nvram_path;
+       if (firmware_path[0] != '\0') {
+               if (is_file_valid(firmware_path))
+                       fw = firmware_path;
+       }
+
+       if (nvram_path[0] != '\0') {
+               if (is_file_valid(nvram_path))
+                       nv = nvram_path;
+       }
 
        if (fw && fw[0] != '\0') {
                fw_len = strlen(fw);
index c3d54cc..564134c 100644 (file)
@@ -355,6 +355,14 @@ static void wifi_platform_free_country_code_map(wifi_adapter_info_t *adapter)
 }
 #endif
 
+static inline bool is_antenna_tuned(void)
+{
+       struct device_node *np;
+
+       np = of_find_node_by_name(NULL, "wifi-antenna-tuning");
+       return of_device_is_available(np);
+}
+
 static int wifi_plat_dev_drv_probe(struct platform_device *pdev)
 {
        struct resource *resource;
@@ -376,6 +384,12 @@ static int wifi_plat_dev_drv_probe(struct platform_device *pdev)
 
                adapter->wlan_pwr = of_get_named_gpio(node, "wlan-pwr-gpio", 0);
                adapter->wlan_rst = of_get_named_gpio(node, "wlan-rst-gpio", 0);
+               adapter->fw_path = of_get_property(node, "fw_path", NULL);
+               adapter->nv_path = of_get_property(node, "nv_path", NULL);
+
+               if (is_antenna_tuned())
+                       adapter->nv_path = of_get_property(node,
+                                               "tuned_nv_path", NULL);
 
                /* This is to get the irq for the OOB */
                adapter->irq_num = platform_get_irq(pdev, 0);
index ff584b4..f1ce16b 100755 (executable)
@@ -99,6 +99,8 @@ static struct device *cfg80211_parent_dev = NULL;
 static struct bcm_cfg80211 *g_bcm_cfg = NULL;
 u32 wl_dbg_level = WL_DBG_ERR;
 
+extern int op_mode;
+
 #ifdef WLAIBSS_MCHAN
 #define IBSS_IF_NAME "ibss%d"
 #endif /* WLAIBSS_MCHAN */
@@ -8433,7 +8435,8 @@ static s32 wl_setup_wiphy(struct wireless_dev *wdev, struct device *sdiofunc_dev
         * probe response frame in case of SoftAP mode,
         * AP_PROBE_RESP_OFFLOAD flag is set to wiphy->flags variable.
         */
-       if (dhd_get_fw_mode(dhd->info) == DHD_FLAG_HOSTAP_MODE) {
+       if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_HOSTAP_MODE) ||
+           (op_mode == DHD_FLAG_HOSTAP_MODE)) {
                wdev->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
                wdev->wiphy->probe_resp_offload = 0;
        }