Newer
Older
/*
* ethernet.h - library header file
*
* Copyright (C) 2018 iopsys Software Solutions AB. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifndef _ETHERNET_H
#define _ETHERNET_H
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/** enum eth_operstate - maps to operational state of interface */
enum eth_operstate {
IF_UP,
IF_DOWN,
IF_UKNOWN,
IF_DORMANT,
IF_NOTPRESENT,
IF_LLDOWN,
IF_ERROR,
};
struct eth_counters {
unsigned long tx_bytes;
unsigned long rx_bytes;
unsigned long tx_packets;
unsigned long rx_packets;
/** packets dropped due to errors */
unsigned long tx_error_packets;
unsigned long rx_error_packets;
/** no-error packets dropped due to other factors */
unsigned long tx_dropped_packets;
unsigned long rx_dropped_pcakets;
};
#define ETH_PORT_UNDEFINED -1
enum eth_speed {
ETH_10_Half = (1 << 0),
ETH_10_Full = (1 << 1),
ETH_100_Half = (1 << 2),
ETH_100_Full = (1 << 3),
ETH_1000_Half = (1 << 4),
ETH_1000_Full = (1 << 5),
ETH_2500_Full = (1 << 7),
ETH_5000_Full = (1 << 11),
ETH_10000_Full = (1 << 15),
ETH_20000_Full = (1 << 23),
};
struct eth_phy {
uint8_t address;
int portidx;
};
struct eth_link {
int portid;
uint32_t capability;
bool autoneg;
uint32_t speed;
bool fullduplex;
bool down;
};
struct eth_info {
int phy_portmap;
int phy_numports;
};
enum eth_callstatus {
ETH_SUCCESS,
ETH_ERROR,
ETH_EINVAL,
ETH_EUNSUPPORTED,
ETH_EUNKNOWN
};
#ifndef if_mii
static inline struct mii_ioctl_data *if_mii(struct ifreq *rq)
{
return (struct mii_ioctl_data *) &rq->ifr_ifru;
}
#endif
struct eth_ops {
/** interface name/prefix to match */
const char *name;
int (*up)(char *name);
int (*down)(char *name);
int (*get_link_settings)(char *name, struct eth_link *link);
int (*set_link_settings)(char *name, struct eth_link link);
int (*get_operstate)(char *name, enum eth_operstate *s);
int (*set_operstate)(char *name, enum eth_operstate s);
int (*reset_phy)(char *name, int phy_id);
int (*poweroff_phy)(char *name, struct eth_phy p);
int (*poweron_phy)(char *name, struct eth_phy p);
int (*get_phy_id)(char *name, int port, int *phy_id);
int (*get_stats)(char *name, struct eth_counters *s);
int (*get_info)(char *name, struct eth_info *info);
};
/* API list */
int eth_up(char *name);
int eth_down(char *name);
int eth_get_link_settings(char *name, struct eth_link *link);
int eth_set_link_settings(char *name, struct eth_link link);
int eth_get_operstate(char *name, enum eth_operstate *s);
int eth_set_operstate(char *name, enum eth_operstate s);
int eth_get_stats(char *name, struct eth_counters *c);
int eth_get_info(char *name, struct eth_info *info);
int eth_reset_phy(char *name, int phy_id);
int eth_poweroff_phy(char *name, struct eth_phy p);
int eth_poweron_phy(char *name, struct eth_phy p);
int eth_get_phy_id(char *name, int port, int *phy_id);
int eth_ioctl(char *name, int cmd, void *in, int len);
int eth_mii_read(char *name, int phy_id, int reg, int *out);
int eth_mii_write(char *name, int phy_id, int reg, int in);
int eth_mii_get_phy_id(char *ifname, int port, int *phy_id);
int eth_mii_reset_phy(char *name, int phy_id);
#ifdef __cplusplus
}
#endif
#endif /* _ETHERNET_H */