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 #ifndef ETH_DRV_H 17 #define ETH_DRV_H 18 19 #include "net_device.h" 20 21 #ifdef __cplusplus 22 #if __cplusplus 23 extern "C" { 24 #endif /* __cplusplus */ 25 #endif /* __cplusplus */ 26 27 #define PHY_STATE_TIME 1000 28 #define HIETH_MONITOR_TIME 50 29 #define NETNUM_IO_ETH_DRIVERS_SG_LIST_SIZE 18 30 #define MAX_ETH_DRV_SG NETNUM_IO_ETH_DRIVERS_SG_LIST_SIZE 31 #define MAX_ETH_MSG 1540 32 33 typedef int32_t (*EthCanSend)(struct EthDevice *ethDevice); 34 typedef void (*EthSend)(struct EthDevice *ethDevice, NetBuf *netBuf); 35 typedef void (*EthRecv)(struct EthDevice *ethDevice, NetBuf *netBuf); 36 typedef void (*EthDeliver)(struct EthDevice *ethDevice); 37 typedef int32_t (*EthIntVector)(struct EthDevice *ethDevice); 38 39 struct EthHwrFuns { 40 /* Query - can a packet be sent? */ 41 EthCanSend canSend; 42 /* Send a packet of data */ 43 EthSend send; 44 /* Receive [unload] a packet of data */ 45 EthRecv recv; 46 /* Deliver data from device to network stack */ 47 EthDeliver deliver; 48 /* Get interrupt information from hardware driver */ 49 EthIntVector intVector; 50 }; 51 52 struct EthDrvSg { 53 uint32_t buf; 54 uint32_t len; 55 }; 56 57 struct EthDrvSc { 58 struct EthHwrFuns *funs; 59 void *driverPrivate; 60 const char *devName; 61 int32_t state; 62 }; 63 64 void HiethLinkStatusChanged(struct EthDevice *ethDevice); 65 uint8_t HiethSetHwaddr(struct EthDevice *ethDevice, uint8_t *addr, uint8_t len); 66 void HiethConfigMode(struct netif *netif, uint32_t configFlags, uint8_t setBit); 67 68 int32_t HisiEthSetPhyMode(const char *phyMode); 69 70 void EthDrvSend(struct EthDevice *ethDevice, NetBuf *netBuf); 71 void InitEthnetDrvFun(struct EthDrvSc *drvFun); 72 void UnRegisterTimerFunction(struct EthDevice *ethDevice); 73 74 #ifndef ETHER_ADDR_LEN 75 #define ETHER_ADDR_LEN 6 76 #endif 77 78 #ifdef __cplusplus 79 #if __cplusplus 80 } 81 #endif /* __cplusplus */ 82 #endif /* __cplusplus */ 83 84 #endif /* ETH_DRV_H */ 85