etherdevice.h revision 26e5f8b61896cf7cfe4ba4a9e160b344398c9c12
1/*-
2 * Copyright (c) 2015 Mellanox Technologies, Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice unmodified, this list of conditions, and the following
9 *    disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD$
26 */
27#ifndef _LINUX_ETHERDEVICE
28#define	_LINUX_ETHERDEVICE
29
30#include <linux/types.h>
31
32#define	ETH_MODULE_SFF_8079		1
33#define	ETH_MODULE_SFF_8079_LEN		256
34#define	ETH_MODULE_SFF_8472		2
35#define	ETH_MODULE_SFF_8472_LEN		512
36#define	ETH_MODULE_SFF_8636		3
37#define	ETH_MODULE_SFF_8636_LEN		256
38#define	ETH_MODULE_SFF_8436		4
39#define	ETH_MODULE_SFF_8436_LEN		256
40
41struct ethtool_eeprom {
42	u32	offset;
43	u32	len;
44};
45
46struct ethtool_modinfo {
47	u32	type;
48	u32	eeprom_len;
49};
50
51static inline bool
52is_zero_ether_addr(const u8 * addr)
53{
54	return ((addr[0] + addr[1] + addr[2] + addr[3] + addr[4] + addr[5]) == 0x00);
55}
56
57static inline bool
58is_multicast_ether_addr(const u8 * addr)
59{
60	return (0x01 & addr[0]);
61}
62
63static inline bool
64is_broadcast_ether_addr(const u8 * addr)
65{
66	return ((addr[0] + addr[1] + addr[2] + addr[3] + addr[4] + addr[5]) == (6 * 0xff));
67}
68
69static inline bool
70is_valid_ether_addr(const u8 * addr)
71{
72	return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
73}
74
75static inline void
76ether_addr_copy(u8 * dst, const u8 * src)
77{
78	memcpy(dst, src, 6);
79}
80
81#endif					/* _LINUX_ETHERDEVICE */
82