1  /**
2   * Copyright (C) 2016 CSI Project. All rights reserved.
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *   http://www.apache.org/licenses/LICENSE-2.0
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  
18  #ifndef _CSI_NET_H_
19  #define _CSI_NET_H_
20  
21  #ifdef __cplusplus
22  extern "C" {
23  #endif
24  
25  #define CSI_ETH_VERSION_MAJOR_MINOR(major,minor) (((major) << 8) | (minor))
26  
27  /**
28  \brief Driver Version
29  */
30  typedef struct csi_driver_version {
31      uint16_t api;                         ///< API version
32      uint16_t drv;                         ///< Driver version
33  } csi_drv_version_t;
34  
35  /* General return codes */
36  #define CSI_ETH_OK                 0 ///< Operation succeeded
37  #define CSI_ETH_ERROR             CSI_DRV_ERRNO_ETH_BASE+1 ///< Unspecified error
38  #define CSI_ETH_ERROR_BUSY        CSI_DRV_ERRNO_ETH_BASE+2 ///< Driver is busy
39  #define CSI_ETH_ERROR_TIMEOUT     CSI_DRV_ERRNO_ETH_BASE+3 ///< Timeout occurred
40  #define CSI_ETH_ERROR_UNSUPPORTED CSI_DRV_ERRNO_ETH_BASE+4 ///< Operation not supported
41  #define CSI_ETH_ERROR_PARAMETER   CSI_DRV_ERRNO_ETH_BASE+5 ///< Parameter error
42  #define CSI_ETH_ERROR_SPECIFIC    CSI_DRV_ERRNO_ETH_BASE+6 ///< Start of driver specific errors
43  
44  /**
45  \brief General power states
46  */
47  typedef enum eth_power_state {
48      CSI_ETH_POWER_OFF,                        ///< Power off: no operation possible
49      CSI_ETH_POWER_LOW,                        ///< Low Power mode: retain state, detect and signal wake-up events
50      CSI_ETH_POWER_FULL                        ///< Power on: full operation at maximum performance
51  } eth_power_state_t;
52  
53  /**
54  \brief Ethernet Media Interface type
55  */
56  #define CSI_ETH_INTERFACE_MII           (0)     ///< Media Independent Interface (MII)
57  #define CSI_ETH_INTERFACE_RMII          (1)     ///< Reduced Media Independent Interface (RMII)
58  #define CSI_ETH_INTERFACE_SMII          (2)     ///< Serial Media Independent Interface (SMII)
59  
60  /**
61  \brief Ethernet link speed
62  */
63  #define CSI_ETH_SPEED_10M               (0)     ///< 10 Mbps link speed
64  #define CSI_ETH_SPEED_100M              (1)     ///< 100 Mbps link speed
65  #define CSI_ETH_SPEED_1G                (2)     ///< 1 Gpbs link speed
66  
67  /**
68  \brief Ethernet duplex mode
69  */
70  #define CSI_ETH_DUPLEX_HALF             (0)     ///< Half duplex link
71  #define CSI_ETH_DUPLEX_FULL             (1)     ///< Full duplex link
72  
73  /**
74  \brief Ethernet auto-negotiation
75  */
76  #define CSI_ETH_AUTONEG_DISABLE         (0)     ///< Disable auto-negotiation
77  #define CSI_ETH_AUTONEG_ENABLE          (1)     ///< Enable auto-negotiation
78  
79  /**
80  \brief Ethernet link state
81  */
82  typedef enum eth_link_state {
83      ETH_LINK_DOWN,                    ///< Link is down
84      ETH_LINK_UP                       ///< Link is up
85  } eth_link_state_t;
86  
87  /**
88  \brief Ethernet link information
89  */
90  typedef volatile struct eth_link_info {
91      uint32_t speed              : 2;                ///< Link speed: 0= 10 MBit, 1= 100 MBit, 2= 1 GBit
92      uint32_t duplex             : 1;                ///< Duplex mode: 0= Half, 1= Full
93      uint32_t autoneg            : 1;                ///< Set the interface to Auto Negotiation mode of transmission parameters
94      uint32_t loopback           : 1;                ///< Set the interface into a Loop-back test mode
95      uint32_t isolation          : 1;                ///< Set to indicate electrical isolation of PHY interface from MII/RMII interface
96      uint32_t reserved           : 26;
97  } eth_link_info_t;
98  
99  /**
100  \brief Ethernet MAC Address
101  */
102  typedef struct eth_mac_addr {
103      uint8_t b[6];                         ///< MAC Address (6 bytes), MSB first
104  } eth_mac_addr_t;
105  
106  #ifdef __cplusplus
107  }
108  #endif
109  
110  #endif /* CSI_NET_H_ */
111  
112