etherdevice.h revision e1c5b02269f9183f4c185346c26ce54776d111b9
17c478bdstevel@tonic-gate/*-
27c478bdstevel@tonic-gate * Copyright (c) 2015 Mellanox Technologies, Ltd. All rights reserved.
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
5c13de8fab * modification, are permitted provided that the following conditions
6c13de8fab * are met:
77c478bdstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
87c478bdstevel@tonic-gate *    notice unmodified, this list of conditions, and the following
97c478bdstevel@tonic-gate *    disclaimer.
107c478bdstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
117c478bdstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
127c478bdstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
157c478bdstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
167c478bdstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
177c478bdstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
187c478bdstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
197c478bdstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
207c478bdstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
217c478bdstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
227c478bdstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
237c478bdstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
247c478bdstevel@tonic-gate *
257c478bdstevel@tonic-gate * $FreeBSD$
26ba7866cAli Bahrami */
277c478bdstevel@tonic-gate#ifndef _LINUX_ETHERDEVICE
287c478bdstevel@tonic-gate#define	_LINUX_ETHERDEVICE
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#include <linux/types.h>
317c478bdstevel@tonic-gate
327c478bdstevel@tonic-gate#include <sys/random.h>
33ba7866cAli Bahrami#include <sys/libkern.h>
347c478bdstevel@tonic-gate
354f680ccAli Bahrami#define	ETH_MODULE_SFF_8079		1
367c478bdstevel@tonic-gate#define	ETH_MODULE_SFF_8079_LEN		256
377c478bdstevel@tonic-gate#define	ETH_MODULE_SFF_8472		2
387c478bdstevel@tonic-gate#define	ETH_MODULE_SFF_8472_LEN		512
39c13de8fab#define	ETH_MODULE_SFF_8636		3
407c478bdstevel@tonic-gate#define	ETH_MODULE_SFF_8636_LEN		256
417c478bdstevel@tonic-gate#define	ETH_MODULE_SFF_8436		4
427c478bdstevel@tonic-gate#define	ETH_MODULE_SFF_8436_LEN		256
437c478bdstevel@tonic-gate
447c478bdstevel@tonic-gatestruct ethtool_eeprom {
457c478bdstevel@tonic-gate	u32	offset;
46c13de8fab	u32	len;
477c478bdstevel@tonic-gate};
487c478bdstevel@tonic-gate
49ba7866cAli Bahramistruct ethtool_modinfo {
50ba7866cAli Bahrami	u32	type;
517c478bdstevel@tonic-gate	u32	eeprom_len;
527c478bdstevel@tonic-gate};
537c478bdstevel@tonic-gate
544f680ccAli Bahramistatic inline bool
557c478bdstevel@tonic-gateis_zero_ether_addr(const u8 * addr)
567c478bdstevel@tonic-gate{
577c478bdstevel@tonic-gate	return ((addr[0] + addr[1] + addr[2] + addr[3] + addr[4] + addr[5]) == 0x00);
58ba7866cAli Bahrami}
597c478bdstevel@tonic-gate
607c478bdstevel@tonic-gatestatic inline bool
617c478bdstevel@tonic-gateis_multicast_ether_addr(const u8 * addr)
627c478bdstevel@tonic-gate{
63ba7866cAli Bahrami	return (0x01 & addr[0]);
64ba7866cAli Bahrami}
65ba7866cAli Bahrami
66ba7866cAli Bahramistatic inline bool
67ba7866cAli Bahramiis_broadcast_ether_addr(const u8 * addr)
68ba7866cAli Bahrami{
69ba7866cAli Bahrami	return ((addr[0] + addr[1] + addr[2] + addr[3] + addr[4] + addr[5]) == (6 * 0xff));
707c478bdstevel@tonic-gate}
717c478bdstevel@tonic-gate
72ba7866cAli Bahramistatic inline bool
73ba7866cAli Bahramiis_valid_ether_addr(const u8 * addr)
747c478bdstevel@tonic-gate{
757c478bdstevel@tonic-gate	return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
767c478bdstevel@tonic-gate}
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gatestatic inline void
797c478bdstevel@tonic-gateether_addr_copy(u8 * dst, const u8 * src)
807c478bdstevel@tonic-gate{
817c478bdstevel@tonic-gate	memcpy(dst, src, 6);
827c478bdstevel@tonic-gate}
837c478bdstevel@tonic-gate
847c478bdstevel@tonic-gatestatic inline bool
857c478bdstevel@tonic-gateether_addr_equal(const u8 *pa, const u8 *pb)
867c478bdstevel@tonic-gate{
877c478bdstevel@tonic-gate	return (memcmp(pa, pb, 6) == 0);
887c478bdstevel@tonic-gate}
897c478bdstevel@tonic-gate
907c478bdstevel@tonic-gatestatic inline bool
917c478bdstevel@tonic-gateether_addr_equal_64bits(const u8 *pa, const u8 *pb)
927c478bdstevel@tonic-gate{
937c478bdstevel@tonic-gate	return (memcmp(pa, pb, 6) == 0);
947c478bdstevel@tonic-gate}
957c478bdstevel@tonic-gate
967c478bdstevel@tonic-gatestatic inline void
977c478bdstevel@tonic-gateeth_broadcast_addr(u8 *pa)
987c478bdstevel@tonic-gate{
997c478bdstevel@tonic-gate	memset(pa, 0xff, 6);
1007c478bdstevel@tonic-gate}
1017c478bdstevel@tonic-gate
1027c478bdstevel@tonic-gatestatic inline void
1037c478bdstevel@tonic-gaterandom_ether_addr(u8 * dst)
1047c478bdstevel@tonic-gate{
1057c478bdstevel@tonic-gate	read_random(dst, 6);
1067c478bdstevel@tonic-gate
1077c478bdstevel@tonic-gate	dst[0] &= 0xfe;
1087c478bdstevel@tonic-gate	dst[0] |= 0x02;
1097c478bdstevel@tonic-gate}
1107c478bdstevel@tonic-gate
1117c478bdstevel@tonic-gate#endif					/* _LINUX_ETHERDEVICE */
1127c478bdstevel@tonic-gate