1 /*
2 * Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd
3 * This file contains confidential and proprietary information of
4 * OSWare Technology Co., Ltd
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #include <linux/etherdevice.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/version.h>
22 #include "eth_chip_driver.h"
23 #include "net_device.h"
24 #include "netbuf_adapter.h"
25 #include "net_device_adapter.h"
26 #include "nxpeth_phy.h"
27 #include "net_adapter.h"
28
29 struct net_device *g_save_eth_net = NULL;
30 extern const struct Net_device_ops fec_netDev_ops;
31 extern struct net_device *get_eth_netdev(void);
32 extern int nxp_fec_set_mac(unsigned char *mac_address, struct NetDevice *netDev);
EthSetMacAddr(struct NetDevice * netDev,void * addr)33 static int32_t EthSetMacAddr(struct NetDevice *netDev, void *addr)
34 {
35 nxp_fec_set_mac((unsigned char *)addr, netDev);
36 HDF_LOGE("%s SetMac successful !", __func__);
37 return HDF_SUCCESS;
38 }
39
EthXmit(struct NetDevice * netDev,NetBuf * netbuf)40 static int32_t EthXmit(struct NetDevice *netDev, NetBuf *netbuf)
41 {
42 int32_t ret = 0;
43
44 fec_netDev_ops.ndo_start_xmit(netbuf, netDev);
45
46 return ret;
47 }
48
EthOpen(struct NetDevice * netDev)49 static int32_t EthOpen(struct NetDevice *netDev)
50 {
51 int32_t ret = 0;
52
53 fec_netDev_ops.ndo_open(netDev);
54 HDF_LOGE("%s open successful !", __func__);
55 return ret;
56 }
57
EthStop(struct NetDevice * netDev)58 static int32_t EthStop(struct NetDevice *netDev)
59 {
60 int32_t ret = 0;
61
62 fec_netDev_ops.ndo_stop(netDev);
63 HDF_LOGE("%s stop successful !", __func__);
64
65 return ret;
66 }
67
68 struct NetDeviceInterFace g_ethnetdevops = {
69 .xmit = EthXmit,
70 .setMacAddr = EthSetMacAddr,
71 .open = EthOpen,
72 .stop = EthStop,
73 };
74
EthernetInitNetdev(NetDevice * netdev)75 int32_t EthernetInitNetdev(NetDevice *netdev)
76 {
77 int32_t ret = HDF_FAILURE;
78
79 if (netdev == NULL) {
80 HDF_LOGE("%s netdev is null!", __func__);
81 return HDF_ERR_INVALID_PARAM;
82 }
83 netdev->netDeviceIf = &g_ethnetdevops;
84
85 ret = NetDeviceAdd(netdev);
86 if (ret != HDF_SUCCESS) {
87 HDF_LOGE("%s NetDeviceAdd return error code %d!", __func__, ret);
88 return ret;
89 }
90
91 // open netdevice
92 HDF_LOGE("%s netdev->netDeviceIf->open!", __func__);
93 netdev->netDeviceIf->open(netdev);
94
95 return ret;
96 }
97
set_eth_netdev(struct net_device * dev)98 void set_eth_netdev(struct net_device *dev)
99 {
100 g_save_eth_net = dev;
101 }
102
get_eth_netdev(void)103 struct net_device *get_eth_netdev(void)
104 {
105 return g_save_eth_net;
106 }
107
108 EXPORT_SYMBOL(set_eth_netdev);
109 EXPORT_SYMBOL(get_eth_netdev);
110