1 /*
2 * hdf_driver_bdh_register.c
3 *
4 * hdf driver
5 *
6 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23 #include "hdf_device_desc.h"
24 #include "hdf_wifi_product.h"
25 #include "hdf_log.h"
26 #include "osal_mem.h"
27 #include "hdf_wlan_chipdriver_manager.h"
28 #include "securec.h"
29 #include "wifi_module.h"
30 #include "hdf_wifi_core.h"
31 #include "hdf_public_ap6275s.h"
32
33 #define HDF_LOG_TAG BDH6Driver
34 #define BDH6_MAX_WLAN_DEVICE 3
35
36 int32_t InitBDH6Chip(struct HdfWlanDevice *device);
37 int32_t DeinitBDH6Chip(struct HdfWlanDevice *device);
38 int32_t BDH6Deinit(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice);
39 int32_t BDH6Init(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice);
40 void BDH6Mac80211Init(struct HdfChipDriver *chipDriver);
41 static const char * const BDH6_DRIVER_NAME = "ap6275s";
42 DEFINE_MUTEX(bdh6_reset_driver_lock);
43
BDH6_ResetDriver(void)44 void BDH6_ResetDriver(void)
45 {
46 uint8_t i;
47 int32_t ret;
48 struct HdfWlanDevice *wlanDevice = NULL;
49 mutex_lock(&bdh6_reset_driver_lock);
50
51 for (i = 0; i < BDH6_MAX_WLAN_DEVICE; i++) {
52 wlanDevice = HdfWlanGetWlanDevice(i);
53 if (wlanDevice && strcmp(wlanDevice->driverName, BDH6_DRIVER_NAME) == 0 && wlanDevice->reset) {
54 ret = HdfWifiDeinitDevice(wlanDevice);
55 if (ret != HDF_SUCCESS) {
56 continue;
57 }
58
59 ret = wlanDevice->reset->Reset(wlanDevice->reset);
60 if (ret != HDF_SUCCESS) {
61 continue;
62 }
63
64 ret = HdfWifiInitDevice(wlanDevice);
65 }
66 }
67 mutex_unlock(&bdh6_reset_driver_lock);
68 }
69
BuildBDH6Driver(struct HdfWlanDevice * device,uint8_t ifIndex)70 static struct HdfChipDriver *BuildBDH6Driver(struct HdfWlanDevice *device, uint8_t ifIndex)
71 {
72 struct HdfChipDriver *specificDriver = NULL;
73 if (device == NULL) {
74 HDF_LOGE("%s fail : channel is NULL", __func__);
75 return NULL;
76 }
77 (void)device;
78 (void)ifIndex;
79 specificDriver = (struct HdfChipDriver *)OsalMemCalloc(sizeof(struct HdfChipDriver));
80 if (specificDriver == NULL) {
81 HDF_LOGE("%s fail: OsalMemCalloc fail!", __func__);
82 return NULL;
83 }
84 if (memset_s(specificDriver, sizeof(struct HdfChipDriver), 0, sizeof(struct HdfChipDriver)) != EOK) {
85 HDF_LOGE("%s fail: memset_s fail!", __func__);
86 OsalMemFree(specificDriver);
87 return NULL;
88 }
89
90 if (strcpy_s(specificDriver->name, MAX_WIFI_COMPONENT_NAME_LEN, BDH6_DRIVER_NAME) != EOK) {
91 HDF_LOGE("%s fail : strcpy_s fail", __func__);
92 OsalMemFree(specificDriver);
93 return NULL;
94 }
95 specificDriver->init = BDH6Init;
96 specificDriver->deinit = BDH6Deinit;
97
98 HDF_LOGI("bdh6: call BuildBDH6Driver %p", specificDriver);
99
100 BDH6Mac80211Init(specificDriver);
101
102 return specificDriver;
103 }
104
ReleaseBDH6Driver(struct HdfChipDriver * chipDriver)105 static void ReleaseBDH6Driver(struct HdfChipDriver *chipDriver)
106 {
107 if (chipDriver == NULL) {
108 return;
109 }
110 if (strcmp(chipDriver->name, BDH6_DRIVER_NAME) != 0) {
111 HDF_LOGE("%s:Not my driver!", __func__);
112 return;
113 }
114 OsalMemFree(chipDriver);
115 }
116
GetBDH6GetMaxIFCount(struct HdfChipDriverFactory * factory)117 static uint8_t GetBDH6GetMaxIFCount(struct HdfChipDriverFactory *factory)
118 {
119 (void)factory;
120 return 1;
121 }
122
123 /* bdh wifi6's chip driver register */
HDFWlanRegBDH6DriverFactory(void)124 static int32_t HDFWlanRegBDH6DriverFactory(void)
125 {
126 static struct HdfChipDriverFactory BDH6Factory = { 0 }; // WiFi device chip driver
127 struct HdfChipDriverManager *driverMgr = NULL;
128 driverMgr = HdfWlanGetChipDriverMgr();
129 if (driverMgr == NULL) {
130 HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
131 return HDF_FAILURE;
132 }
133 BDH6Factory.driverName = BDH6_DRIVER_NAME;
134 BDH6Factory.GetMaxIFCount = GetBDH6GetMaxIFCount;
135 BDH6Factory.InitChip = InitBDH6Chip;
136 BDH6Factory.DeinitChip = DeinitBDH6Chip;
137 BDH6Factory.Build = BuildBDH6Driver;
138 BDH6Factory.Release = ReleaseBDH6Driver;
139 BDH6Factory.ReleaseFactory = NULL;
140 if (driverMgr->RegChipDriver(&BDH6Factory) != HDF_SUCCESS) {
141 HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
142 return HDF_FAILURE;
143 }
144
145 return HDF_SUCCESS;
146 }
147
148
HdfWlanBDH6ChipDriverInit(struct HdfDeviceObject * device)149 static int32_t HdfWlanBDH6ChipDriverInit(struct HdfDeviceObject *device)
150 {
151 (void)device;
152 HDF_LOGI("bdh6: call HdfWlanBDH6ChipDriverInit");
153 return HDFWlanRegBDH6DriverFactory();
154 }
155
HdfWlanBDH6DriverBind(struct HdfDeviceObject * dev)156 static int HdfWlanBDH6DriverBind(struct HdfDeviceObject *dev)
157 {
158 (void)dev;
159 HDF_LOGI("bdh6: call HdfWlanBDH6DriverBind");
160 return HDF_SUCCESS;
161 }
162
HdfWlanBDH6ChipRelease(struct HdfDeviceObject * object)163 static void HdfWlanBDH6ChipRelease(struct HdfDeviceObject *object)
164 {
165 (void)object;
166 HDF_LOGI("bdh6: call HdfWlanBDH6ChipRelease");
167 }
168
HdfWlanConfigSDIO(uint8_t busId)169 int32_t HdfWlanConfigSDIO(uint8_t busId)
170 {
171 return HDF_SUCCESS;
172 }
173
174 struct HdfDriverEntry g_hdfBdh6ChipEntry = {
175 .moduleVersion = 1,
176 .Bind = HdfWlanBDH6DriverBind,
177 .Init = HdfWlanBDH6ChipDriverInit,
178 .Release = HdfWlanBDH6ChipRelease,
179 .moduleName = "HDF_WLAN_CHIPS_AP6275S"
180 };
181
182 HDF_INIT(g_hdfBdh6ChipEntry);
183