-
Anjan Chanda authoredAnjan Chanda authored
ethernet.h 3.80 KiB
/*
* ethernet.h - library header file
*
* Copyright (C) 2018 Inteno Broadband Technology AB. All rights reserved.
*
* Author: anjan.chanda@inteno.se
*
* 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
*/
#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 */