11bd4fe43Sopenharmony_ci/* 21bd4fe43Sopenharmony_ci * Copyright (c) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 31bd4fe43Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41bd4fe43Sopenharmony_ci * you may not use this file except in compliance with the License. 51bd4fe43Sopenharmony_ci * You may obtain a copy of the License at 61bd4fe43Sopenharmony_ci * 71bd4fe43Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81bd4fe43Sopenharmony_ci * 91bd4fe43Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101bd4fe43Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111bd4fe43Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121bd4fe43Sopenharmony_ci * See the License for the specific language governing permissions and 131bd4fe43Sopenharmony_ci * limitations under the License. 141bd4fe43Sopenharmony_ci */ 151bd4fe43Sopenharmony_ci 161bd4fe43Sopenharmony_ci#include "net_adapter.h" 171bd4fe43Sopenharmony_ci#include "ctrl.h" 181bd4fe43Sopenharmony_ci#include "eth_chip_driver.h" 191bd4fe43Sopenharmony_ci#include "eth_drv.h" 201bd4fe43Sopenharmony_ci#include "net_device.h" 211bd4fe43Sopenharmony_ci 221bd4fe43Sopenharmony_cistatic int32_t EthSetMacAddr(struct NetDevice *netDev, void *addr) 231bd4fe43Sopenharmony_ci{ 241bd4fe43Sopenharmony_ci int32_t ret; 251bd4fe43Sopenharmony_ci 261bd4fe43Sopenharmony_ci if (netDev == NULL) { 271bd4fe43Sopenharmony_ci HDF_LOGE("%s:input is NULL!", __func__); 281bd4fe43Sopenharmony_ci return HDF_FAILURE; 291bd4fe43Sopenharmony_ci } 301bd4fe43Sopenharmony_ci ret = HiethSetHwaddr((struct EthDevice *)netDev->mlPriv, (unsigned char *)addr, ETHER_ADDR_LEN); 311bd4fe43Sopenharmony_ci if (ret != HDF_SUCCESS) { 321bd4fe43Sopenharmony_ci HDF_LOGE("%s: HiethSetHwaddr is fail!", __func__); 331bd4fe43Sopenharmony_ci } 341bd4fe43Sopenharmony_ci return ret; 351bd4fe43Sopenharmony_ci} 361bd4fe43Sopenharmony_ci 371bd4fe43Sopenharmony_cistatic NetDevTxResult EthXmit(struct NetDevice *netDev, NetBuf *netbuf) 381bd4fe43Sopenharmony_ci{ 391bd4fe43Sopenharmony_ci EthDrvSend((struct EthDevice *)netDev->mlPriv, netbuf); 401bd4fe43Sopenharmony_ci return NETDEV_TX_OK; 411bd4fe43Sopenharmony_ci} 421bd4fe43Sopenharmony_ci 431bd4fe43Sopenharmony_cistatic void LinkStatusChanged(struct NetDevice *netDev) 441bd4fe43Sopenharmony_ci{ 451bd4fe43Sopenharmony_ci HiethLinkStatusChanged((struct EthDevice *)netDev->mlPriv); 461bd4fe43Sopenharmony_ci} 471bd4fe43Sopenharmony_ci 481bd4fe43Sopenharmony_cistruct NetDeviceInterFace g_ethNetDevOps = { 491bd4fe43Sopenharmony_ci .xmit = EthXmit, 501bd4fe43Sopenharmony_ci .setMacAddr = EthSetMacAddr, 511bd4fe43Sopenharmony_ci .linkStatusChanged = LinkStatusChanged, 521bd4fe43Sopenharmony_ci}; 531bd4fe43Sopenharmony_ci 541bd4fe43Sopenharmony_ciint32_t EthernetInitNetdev(NetDevice *netdev) 551bd4fe43Sopenharmony_ci{ 561bd4fe43Sopenharmony_ci int32_t ret; 571bd4fe43Sopenharmony_ci 581bd4fe43Sopenharmony_ci if (netdev == NULL) { 591bd4fe43Sopenharmony_ci HDF_LOGE("%s netdev is null!", __func__); 601bd4fe43Sopenharmony_ci return HDF_ERR_INVALID_PARAM; 611bd4fe43Sopenharmony_ci } 621bd4fe43Sopenharmony_ci netdev->netDeviceIf = &g_ethNetDevOps; 631bd4fe43Sopenharmony_ci 641bd4fe43Sopenharmony_ci ret = NetDeviceAdd(netdev); 651bd4fe43Sopenharmony_ci if (ret != HDF_SUCCESS) { 661bd4fe43Sopenharmony_ci HDF_LOGE("%s NetDeviceAdd return error code %d!", __func__, ret); 671bd4fe43Sopenharmony_ci return ret; 681bd4fe43Sopenharmony_ci } 691bd4fe43Sopenharmony_ci return ret; 701bd4fe43Sopenharmony_ci} 71