/* * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "hdf_wifi_product.h" #include "hi_wifi_api.h" #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) #include "oal_thread.h" #include "osal_time.h" #endif #include "wifi_mac80211_ops.h" #include "wal_cfg80211.h" #include "net_adpater.h" #include "hdf_wlan_utils.h" #define HDF_LOG_TAG Hi3881Driver int32_t InitHi3881Chip(struct HdfWlanDevice *device) { uint8_t maxPortCount = 3; int32_t ret = HI_SUCCESS; uint8_t maxRetryCount = 3; if (device == NULL || device->bus == NULL) { HDF_LOGE("%s:NULL ptr!", __func__); return HI_FAIL; } do { if (ret != HI_SUCCESS) { if (device->reset != NULL && device->reset->Reset != NULL) { device->reset->Reset(device->reset); } HDF_LOGE("%s:Retry init hi3881!last ret=%d", __func__, ret); } ret = hi_wifi_init(maxPortCount, device->bus); } while (ret != 0 && --maxRetryCount > 0); if (ret != 0) { HDF_LOGE("%s:Init hi3881 driver failed!", __func__); return ret; } return HI_SUCCESS; } int32_t DeinitHi3881Chip(struct HdfWlanDevice *device) { int32_t ret; (void)device; ret = hi_wifi_deinit(); if (ret != 0) { HDF_LOGE("%s:Deinit failed!ret=%d", __func__, ret); } return ret; } int32_t Hi3881Init(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice) { hi_u16 mode; int32_t ret; nl80211_iftype_uint8 type; (void)chipDriver; HDF_LOGI("%s: start...", __func__); mode = wal_get_vap_mode(); if (mode >= WAL_WIFI_MODE_BUTT) { oam_error_log1(0, 0, "wal_init_drv_netdev:: invalid mode[%d]", mode); return HI_FAIL; } if (mode == WAL_WIFI_MODE_STA) { type = NL80211_IFTYPE_STATION; #ifdef _PRE_WLAN_FEATURE_P2P if (InitNetdev(netDevice, NL80211_IFTYPE_P2P_DEVICE) != HI_SUCCESS) { return HI_FAIL; } #endif } else if (mode == WAL_WIFI_MODE_AP) { type = NL80211_IFTYPE_AP; } else { oam_error_log1(0, 0, "wal_init_drv_netdev:: invalid mode[%d]", mode); return HI_FAIL; } ret = wal_init_drv_wlan_netdev(type, WAL_PHY_MODE_11N, netDevice); if (ret != HI_SUCCESS) { oam_error_log2(0, OAM_SF_ANY, "wal_init_drv_netdev %s failed.l_return:%d\n", netDevice->name, ret); } return ret; } int32_t Hi3881Deinit(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice) { int32_t ret; (void)chipDriver; ret = DeinitNetdev(NL80211_IFTYPE_P2P_DEVICE); if (ret != HI_SUCCESS) { oam_error_log1(0, OAM_SF_ANY, "Hi3881Deinit: DeinitNetdev p2p device fail, ret = %d\n", ret); return ret; } return wal_deinit_drv_wlan_netdev(netDevice); }