Path: blob/main/sys/compat/linuxkpi/common/include/linux/etherdevice.h
102292 views
/*-1* Copyright (c) 2015-2016 Mellanox Technologies, Ltd. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice unmodified, this list of conditions, and the following8* disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR14* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES15* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,17* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT18* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,19* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY20* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT21* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF22* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23*/24#ifndef _LINUXKPI_LINUX_ETHERDEVICE_H_25#define _LINUXKPI_LINUX_ETHERDEVICE_H_2627#include <linux/types.h>28#include <linux/device.h>29#include <linux/skbuff.h>30#include <linux/netdevice.h>3132#include <sys/random.h>33#include <sys/libkern.h>3435#define ETH_MODULE_SFF_8079 136#define ETH_MODULE_SFF_8079_LEN 25637#define ETH_MODULE_SFF_8472 238#define ETH_MODULE_SFF_8472_LEN 51239#define ETH_MODULE_SFF_8636 340#define ETH_MODULE_SFF_8636_LEN 25641#define ETH_MODULE_SFF_8436 442#define ETH_MODULE_SFF_8436_LEN 2564344struct ethtool_eeprom {45u32 offset;46u32 len;47};4849struct ethtool_modinfo {50u32 type;51u32 eeprom_len;52};5354static inline bool55is_zero_ether_addr(const u8 * addr)56{57return ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) ==580x00);59}6061static inline bool62is_unicast_ether_addr(const u8 * addr)63{64return ((addr[0] & 0x01) == 0x00);65}6667static inline bool68is_multicast_ether_addr(const u8 * addr)69{70return ((addr[0] & 0x01) == 0x01);71}7273static inline bool74is_broadcast_ether_addr(const u8 * addr)75{76return ((addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) ==770xff);78}7980static inline bool81is_valid_ether_addr(const u8 * addr)82{83return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);84}8586static inline void87ether_addr_copy(u8 * dst, const u8 * src)88{89memcpy(dst, src, 6);90}9192static inline bool93ether_addr_equal_unaligned(const u8 *pa, const u8 *pb)94{95return (memcmp(pa, pb, 6) == 0);96}97#define ether_addr_equal(_pa, _pb) ether_addr_equal_unaligned(_pa, _pb)9899static inline bool100ether_addr_equal_64bits(const u8 *pa, const u8 *pb)101{102return (memcmp(pa, pb, 6) == 0);103}104105static inline void106eth_broadcast_addr(u8 *pa)107{108memset(pa, 0xff, 6);109}110111static inline void112eth_zero_addr(u8 *pa)113{114memset(pa, 0, 6);115}116117static inline void118random_ether_addr(u8 *dst)119{120arc4random_buf(dst, 6);121122dst[0] &= 0xfe;123dst[0] |= 0x02;124}125126static inline void127eth_random_addr(u8 *dst)128{129130random_ether_addr(dst);131}132133static inline int134device_get_mac_address(struct device *dev, char *dst)135{136137/* XXX get mac address from FDT? */138return (-ENOENT);139}140141/* Returns network byte order. */142static inline uint16_t143eth_type_trans(struct sk_buff *skb, struct net_device *dev)144{145pr_debug("%s: TODO\n", __func__);146return (htons(ETHERTYPE_8023));147}148149static inline void150eth_hw_addr_set(struct net_device *dev, const u8 *addr)151{152pr_debug("%s: TODO (if we want to)\n", __func__);153}154155static inline int156eth_platform_get_mac_address(struct device *dev __unused, u8 *addr __unused)157{158pr_debug("%s: TODO\n", __func__);159return (-ENODEV);160}161162#endif /* _LINUXKPI_LINUX_ETHERDEVICE_H_ */163164165