1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "hdf_wifi_product.h"
20 #include "hi_wifi_api.h"
21 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
22 #include "oal_thread.h"
23 #include "osal_time.h"
24 #endif
25 #include "wifi_mac80211_ops.h"
26 #include "wal_cfg80211.h"
27 #include "net_adpater.h"
28 #include "hdf_wlan_utils.h"
29
30 #define HDF_LOG_TAG Hi3881Driver
31
InitHi3881Chip(struct HdfWlanDevice * device)32 int32_t InitHi3881Chip(struct HdfWlanDevice *device)
33 {
34 uint8_t maxPortCount = 3;
35 int32_t ret = HI_SUCCESS;
36 uint8_t maxRetryCount = 3;
37 if (device == NULL || device->bus == NULL) {
38 HDF_LOGE("%s:NULL ptr!", __func__);
39 return HI_FAIL;
40 }
41
42 do {
43 if (ret != HI_SUCCESS) {
44 if (device->reset != NULL && device->reset->Reset != NULL) {
45 device->reset->Reset(device->reset);
46 }
47 HDF_LOGE("%s:Retry init hi3881!last ret=%d", __func__, ret);
48 }
49 ret = hi_wifi_init(maxPortCount, device->bus);
50 } while (ret != 0 && --maxRetryCount > 0);
51
52 if (ret != 0) {
53 HDF_LOGE("%s:Init hi3881 driver failed!", __func__);
54 return ret;
55 }
56 return HI_SUCCESS;
57 }
58
DeinitHi3881Chip(struct HdfWlanDevice * device)59 int32_t DeinitHi3881Chip(struct HdfWlanDevice *device)
60 {
61 int32_t ret;
62 (void)device;
63 ret = hi_wifi_deinit();
64 if (ret != 0) {
65 HDF_LOGE("%s:Deinit failed!ret=%d", __func__, ret);
66 }
67 return ret;
68 }
69
Hi3881Init(struct HdfChipDriver * chipDriver,struct NetDevice * netDevice)70 int32_t Hi3881Init(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice)
71 {
72 hi_u16 mode;
73 int32_t ret;
74 nl80211_iftype_uint8 type;
75 (void)chipDriver;
76 HDF_LOGI("%s: start...", __func__);
77 mode = wal_get_vap_mode();
78 if (mode >= WAL_WIFI_MODE_BUTT) {
79 oam_error_log1(0, 0, "wal_init_drv_netdev:: invalid mode[%d]", mode);
80 return HI_FAIL;
81 }
82 if (mode == WAL_WIFI_MODE_STA) {
83 type = NL80211_IFTYPE_STATION;
84 #ifdef _PRE_WLAN_FEATURE_P2P
85 if (InitNetdev(netDevice, NL80211_IFTYPE_P2P_DEVICE) != HI_SUCCESS) {
86 return HI_FAIL;
87 }
88 #endif
89 } else if (mode == WAL_WIFI_MODE_AP) {
90 type = NL80211_IFTYPE_AP;
91 } else {
92 oam_error_log1(0, 0, "wal_init_drv_netdev:: invalid mode[%d]", mode);
93 return HI_FAIL;
94 }
95 ret = wal_init_drv_wlan_netdev(type, WAL_PHY_MODE_11N, netDevice);
96 if (ret != HI_SUCCESS) {
97 oam_error_log2(0, OAM_SF_ANY, "wal_init_drv_netdev %s failed.l_return:%d\n", netDevice->name, ret);
98 }
99 return ret;
100 }
101
Hi3881Deinit(struct HdfChipDriver * chipDriver,struct NetDevice * netDevice)102 int32_t Hi3881Deinit(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice)
103 {
104 int32_t ret;
105 (void)chipDriver;
106 ret = DeinitNetdev(NL80211_IFTYPE_P2P_DEVICE);
107 if (ret != HI_SUCCESS) {
108 oam_error_log1(0, OAM_SF_ANY, "Hi3881Deinit: DeinitNetdev p2p device fail, ret = %d\n", ret);
109 return ret;
110 }
111 return wal_deinit_drv_wlan_netdev(netDevice);
112 }
113