1 /*
2 * Copyright (c) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "devsvc_manager_clnt.h"
17 #include "eth_chip_driver.h"
18 #include "eth_mac.h"
19 #include "hdf_device_desc.h"
20 #include "hdf_log.h"
21 #include "hieth_mac.h"
22 #include "hieth_phy.h"
23 #include "osal_mem.h"
24
25 static const char* const HISI_ETHERNET_DRIVER_NAME = "hieth-sf";
26
HdfEthRegHisiDriverFactory(void)27 static int32_t HdfEthRegHisiDriverFactory(void)
28 {
29 static struct HdfEthChipDriverFactory tmpFactory = { 0 };
30 struct HdfEthChipDriverManager *driverMgr = HdfEthGetChipDriverMgr();
31
32 if (driverMgr == NULL || driverMgr->RegChipDriver == NULL) {
33 HDF_LOGE("%s fail: driverMgr is NULL", __func__);
34 return HDF_FAILURE;
35 }
36 tmpFactory.driverName = HISI_ETHERNET_DRIVER_NAME;
37 tmpFactory.InitEthDriver = InitHiethDriver;
38 tmpFactory.GetMacAddr = EthHisiRandomAddr;
39 tmpFactory.DeinitEthDriver = DeinitHiethDriver;
40 tmpFactory.BuildMacDriver = BuildHisiMacDriver;
41 tmpFactory.ReleaseMacDriver = ReleaseHisiMacDriver;
42 if (driverMgr->RegChipDriver(&tmpFactory) != HDF_SUCCESS) {
43 HDF_LOGE("%s fail: driverMgr is NULL", __func__);
44 return HDF_FAILURE;
45 }
46 HDF_LOGI("hisi eth driver register success");
47 return HDF_SUCCESS;
48 }
49
HdfEthHisiChipDriverInit(struct HdfDeviceObject * device)50 static int32_t HdfEthHisiChipDriverInit(struct HdfDeviceObject *device)
51 {
52 (void)device;
53 return HdfEthRegHisiDriverFactory();
54 }
55
HdfEthHisiDriverBind(struct HdfDeviceObject * dev)56 static int32_t HdfEthHisiDriverBind(struct HdfDeviceObject *dev)
57 {
58 (void)dev;
59 return HDF_SUCCESS;
60 }
61
HdfEthHisiChipRelease(struct HdfDeviceObject * object)62 static void HdfEthHisiChipRelease(struct HdfDeviceObject *object)
63 {
64 (void)object;
65 }
66
67 struct HdfDriverEntry g_hdfHisiEthChipEntry = {
68 .moduleVersion = 1,
69 .Bind = HdfEthHisiDriverBind,
70 .Init = HdfEthHisiChipDriverInit,
71 .Release = HdfEthHisiChipRelease,
72 .moduleName = "HDF_ETHERNET_CHIPS"
73 };
74
75 HDF_INIT(g_hdfHisiEthChipEntry);
76