Path: blob/main/sys/compat/linuxkpi/common/include/linux/etherdevice.h
39604 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>2930#include <sys/random.h>31#include <sys/libkern.h>3233#define ETH_MODULE_SFF_8079 134#define ETH_MODULE_SFF_8079_LEN 25635#define ETH_MODULE_SFF_8472 236#define ETH_MODULE_SFF_8472_LEN 51237#define ETH_MODULE_SFF_8636 338#define ETH_MODULE_SFF_8636_LEN 25639#define ETH_MODULE_SFF_8436 440#define ETH_MODULE_SFF_8436_LEN 2564142struct ethtool_eeprom {43u32 offset;44u32 len;45};4647struct ethtool_modinfo {48u32 type;49u32 eeprom_len;50};5152static inline bool53is_zero_ether_addr(const u8 * addr)54{55return ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) ==560x00);57}5859static inline bool60is_unicast_ether_addr(const u8 * addr)61{62return ((addr[0] & 0x01) == 0x00);63}6465static inline bool66is_multicast_ether_addr(const u8 * addr)67{68return ((addr[0] & 0x01) == 0x01);69}7071static inline bool72is_broadcast_ether_addr(const u8 * addr)73{74return ((addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) ==750xff);76}7778static inline bool79is_valid_ether_addr(const u8 * addr)80{81return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);82}8384static inline void85ether_addr_copy(u8 * dst, const u8 * src)86{87memcpy(dst, src, 6);88}8990static inline bool91ether_addr_equal_unaligned(const u8 *pa, const u8 *pb)92{93return (memcmp(pa, pb, 6) == 0);94}95#define ether_addr_equal(_pa, _pb) ether_addr_equal_unaligned(_pa, _pb)9697static inline bool98ether_addr_equal_64bits(const u8 *pa, const u8 *pb)99{100return (memcmp(pa, pb, 6) == 0);101}102103static inline void104eth_broadcast_addr(u8 *pa)105{106memset(pa, 0xff, 6);107}108109static inline void110eth_zero_addr(u8 *pa)111{112memset(pa, 0, 6);113}114115static inline void116random_ether_addr(u8 *dst)117{118arc4random_buf(dst, 6);119120dst[0] &= 0xfe;121dst[0] |= 0x02;122}123124static inline void125eth_random_addr(u8 *dst)126{127128random_ether_addr(dst);129}130131static inline int132device_get_mac_address(struct device *dev, char *dst)133{134135/* XXX get mac address from FDT? */136return (-ENOENT);137}138139#endif /* _LINUXKPI_LINUX_ETHERDEVICE_H_ */140141142