1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "hdf_device_desc.h"
10 #include "hdf_wifi_product.h"
11 #include "hdf_log.h"
12 #include "osal_mem.h"
13 #include "hdf_wlan_chipdriver_manager.h"
14 #include "securec.h"
15 #include "wifi_module.h"
16
17
18 #define HDF_LOG_TAG BDH6Driver
19
20 int32_t InitBDH6Chip(struct HdfWlanDevice *device);
21 int32_t DeinitBDH6Chip(struct HdfWlanDevice *device);
22 int32_t BDH6Deinit(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice);
23 int32_t BDH6Init(struct HdfChipDriver *chipDriver, struct NetDevice *netDevice);
24
25 void BDH6Mac80211Init(struct HdfChipDriver *chipDriver);
26
27
28 // match to "chipInst {" in hcs
29 static const char * const BDH6_DRIVER_NAME = "hisi";
30
31
BuildBDH6Driver(struct HdfWlanDevice * device,uint8_t ifIndex)32 static struct HdfChipDriver *BuildBDH6Driver(struct HdfWlanDevice *device, uint8_t ifIndex)
33 {
34 struct HdfChipDriver *specificDriver = NULL;
35 if (device == NULL) {
36 HDF_LOGE("%s fail : channel is NULL", __func__);
37 return NULL;
38 }
39 (void)device;
40 (void)ifIndex;
41 specificDriver = (struct HdfChipDriver *)OsalMemCalloc(sizeof(struct HdfChipDriver));
42 if (specificDriver == NULL) {
43 HDF_LOGE("%s fail: OsalMemCalloc fail!", __func__);
44 return NULL;
45 }
46 if (memset_s(specificDriver, sizeof(struct HdfChipDriver), 0, sizeof(struct HdfChipDriver)) != EOK) {
47 HDF_LOGE("%s fail: memset_s fail!", __func__);
48 OsalMemFree(specificDriver);
49 return NULL;
50 }
51
52 if (strcpy_s(specificDriver->name, MAX_WIFI_COMPONENT_NAME_LEN, BDH6_DRIVER_NAME) != EOK) {
53 HDF_LOGE("%s fail : strcpy_s fail", __func__);
54 OsalMemFree(specificDriver);
55 return NULL;
56 }
57 specificDriver->init = BDH6Init;
58 specificDriver->deinit = BDH6Deinit;
59
60 HDF_LOGW("bdh6: call BuildBDH6Driver");
61
62 BDH6Mac80211Init(specificDriver);
63
64 return specificDriver;
65 }
66
ReleaseBDH6Driver(struct HdfChipDriver * chipDriver)67 static void ReleaseBDH6Driver(struct HdfChipDriver *chipDriver)
68 {
69 if (chipDriver == NULL) {
70 return;
71 }
72 if (strcmp(chipDriver->name, BDH6_DRIVER_NAME) != 0) {
73 HDF_LOGE("%s:Not my driver!", __func__);
74 return;
75 }
76 OsalMemFree(chipDriver);
77 }
78
GetBDH6GetMaxIFCount(struct HdfChipDriverFactory * factory)79 static uint8_t GetBDH6GetMaxIFCount(struct HdfChipDriverFactory *factory)
80 {
81 (void)factory;
82 return 1;
83 }
84
85 /* bdh wifi6's chip driver register */
HDFWlanRegBDH6DriverFactory(void)86 static int32_t HDFWlanRegBDH6DriverFactory(void)
87 {
88 static struct HdfChipDriverFactory BDH6Factory = { 0 }; // WiFi device chip driver
89 struct HdfChipDriverManager *driverMgr = NULL;
90 driverMgr = HdfWlanGetChipDriverMgr();
91 if (driverMgr == NULL) {
92 HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
93 return HDF_FAILURE;
94 }
95 BDH6Factory.driverName = BDH6_DRIVER_NAME;
96 BDH6Factory.GetMaxIFCount = GetBDH6GetMaxIFCount;
97 BDH6Factory.InitChip = InitBDH6Chip;
98 BDH6Factory.DeinitChip = DeinitBDH6Chip;
99 BDH6Factory.Build = BuildBDH6Driver;
100 BDH6Factory.Release = ReleaseBDH6Driver;
101 BDH6Factory.ReleaseFactory = NULL;
102 if (driverMgr->RegChipDriver(&BDH6Factory) != HDF_SUCCESS) {
103 HDF_LOGE("%s fail: driverMgr is NULL!", __func__);
104 return HDF_FAILURE;
105 }
106
107 return HDF_SUCCESS;
108 }
109
HdfWlanBDH6ChipDriverInit(struct HdfDeviceObject * device)110 static int32_t HdfWlanBDH6ChipDriverInit(struct HdfDeviceObject *device)
111 {
112 (void)device;
113 HDF_LOGW("bdh6: call HdfWlanBDH6ChipDriverInit");
114 return HDFWlanRegBDH6DriverFactory();
115 }
116
HdfWlanBDH6DriverBind(struct HdfDeviceObject * dev)117 static int HdfWlanBDH6DriverBind(struct HdfDeviceObject *dev)
118 {
119 (void)dev;
120 HDF_LOGW("bdh6: call HdfWlanBDH6DriverBind");
121 return HDF_SUCCESS;
122 }
123
HdfWlanBDH6ChipRelease(struct HdfDeviceObject * object)124 static void HdfWlanBDH6ChipRelease(struct HdfDeviceObject *object)
125 {
126 (void)object;
127 HDF_LOGW("bdh6: call HdfWlanBDH6ChipRelease");
128 }
129
130 struct HdfDriverEntry g_hdfBdh6ChipEntry = {
131 .moduleVersion = 1,
132 .Bind = HdfWlanBDH6DriverBind,
133 .Init = HdfWlanBDH6ChipDriverInit,
134 .Release = HdfWlanBDH6ChipRelease,
135 .moduleName = "HDF_WLAN_CHIPS"
136 };
137
138 HDF_INIT(g_hdfBdh6ChipEntry);
139