• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "net_adapter.h"
17 #include "ctrl.h"
18 #include "eth_chip_driver.h"
19 #include "eth_drv.h"
20 #include "net_device.h"
21 
EthSetMacAddr(struct NetDevice * netDev,void * addr)22 static int32_t EthSetMacAddr(struct NetDevice *netDev, void *addr)
23 {
24     int32_t ret;
25 
26     if (netDev == NULL) {
27         HDF_LOGE("%s:input is NULL!", __func__);
28         return HDF_FAILURE;
29     }
30     ret = HiethSetHwaddr((struct EthDevice *)netDev->mlPriv, (unsigned char *)addr, ETHER_ADDR_LEN);
31     if (ret != HDF_SUCCESS) {
32         HDF_LOGE("%s: HiethSetHwaddr is fail!", __func__);
33     }
34     return ret;
35 }
36 
EthXmit(struct NetDevice * netDev,NetBuf * netbuf)37 static NetDevTxResult EthXmit(struct NetDevice *netDev, NetBuf *netbuf)
38 {
39     EthDrvSend((struct EthDevice *)netDev->mlPriv, netbuf);
40     return NETDEV_TX_OK;
41 }
42 
LinkStatusChanged(struct NetDevice * netDev)43 static void LinkStatusChanged(struct NetDevice *netDev)
44 {
45     HiethLinkStatusChanged((struct EthDevice *)netDev->mlPriv);
46 }
47 
48 struct NetDeviceInterFace g_ethNetDevOps = {
49     .xmit = EthXmit,
50     .setMacAddr = EthSetMacAddr,
51     .linkStatusChanged = LinkStatusChanged,
52 };
53 
EthernetInitNetdev(NetDevice * netdev)54 int32_t EthernetInitNetdev(NetDevice *netdev)
55 {
56     int32_t ret;
57 
58     if (netdev == NULL) {
59         HDF_LOGE("%s netdev is null!", __func__);
60         return HDF_ERR_INVALID_PARAM;
61     }
62     netdev->netDeviceIf = &g_ethNetDevOps;
63 
64     ret = NetDeviceAdd(netdev);
65     if (ret != HDF_SUCCESS) {
66         HDF_LOGE("%s NetDeviceAdd return error code %d!", __func__, ret);
67         return ret;
68     }
69     return ret;
70 }
71