1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5324526Shselasky * Copyright (c) 2013-2017 Mellanox Technologies, Ltd. 6219820Sjeff * All rights reserved. 7219820Sjeff * 8219820Sjeff * Redistribution and use in source and binary forms, with or without 9219820Sjeff * modification, are permitted provided that the following conditions 10219820Sjeff * are met: 11219820Sjeff * 1. Redistributions of source code must retain the above copyright 12219820Sjeff * notice unmodified, this list of conditions, and the following 13219820Sjeff * disclaimer. 14219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15219820Sjeff * notice, this list of conditions and the following disclaimer in the 16219820Sjeff * documentation and/or other materials provided with the distribution. 17219820Sjeff * 18219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28289644Shselasky * 29289644Shselasky * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/netdevice.h 341852 2018-12-12 10:12:14Z hselasky $ 30219820Sjeff */ 31219820Sjeff#ifndef _LINUX_NETDEVICE_H_ 32219820Sjeff#define _LINUX_NETDEVICE_H_ 33219820Sjeff 34219820Sjeff#include <linux/types.h> 35219820Sjeff 36219820Sjeff#include <sys/socket.h> 37219820Sjeff 38219820Sjeff#include <net/if_types.h> 39219820Sjeff#include <net/if.h> 40219820Sjeff#include <net/if_var.h> 41219820Sjeff#include <net/if_dl.h> 42219820Sjeff 43324526Shselasky#include <linux/list.h> 44219820Sjeff#include <linux/completion.h> 45219820Sjeff#include <linux/device.h> 46219820Sjeff#include <linux/workqueue.h> 47219820Sjeff#include <linux/net.h> 48219820Sjeff#include <linux/notifier.h> 49219820Sjeff 50324526Shselasky#ifdef VIMAGE 51324526Shselasky#define init_net *vnet0 52324526Shselasky#else 53324526Shselasky#define init_net *((struct vnet *)0) 54324526Shselasky#endif 55219820Sjeff 56219820Sjeff#define MAX_ADDR_LEN 20 57219820Sjeff 58219820Sjeff#define net_device ifnet 59219820Sjeff 60324526Shselaskystatic inline struct ifnet * 61324526Shselaskydev_get_by_index(struct vnet *vnet, int if_index) 62324526Shselasky{ 63324526Shselasky struct ifnet *retval; 64219820Sjeff 65324526Shselasky CURVNET_SET(vnet); 66324526Shselasky retval = ifnet_byindex_ref(if_index); 67324526Shselasky CURVNET_RESTORE(); 68324526Shselasky 69324526Shselasky return (retval); 70324526Shselasky} 71324526Shselasky 72324526Shselasky#define dev_hold(d) if_ref(d) 73324526Shselasky#define dev_put(d) if_rele(d) 74324526Shselasky#define dev_net(d) ((d)->if_vnet) 75324526Shselasky 76294827Shselasky#define net_eq(a,b) ((a) == (b)) 77294827Shselasky 78219820Sjeff#define netif_running(dev) !!((dev)->if_drv_flags & IFF_DRV_RUNNING) 79219820Sjeff#define netif_oper_up(dev) !!((dev)->if_flags & IFF_UP) 80341852Shselasky#define netif_carrier_ok(dev) ((dev)->if_link_state == LINK_STATE_UP) 81219820Sjeff 82219820Sjeffstatic inline void * 83219820Sjeffnetdev_priv(const struct net_device *dev) 84219820Sjeff{ 85219820Sjeff return (dev->if_softc); 86219820Sjeff} 87219820Sjeff 88294827Shselaskystatic inline struct net_device * 89294827Shselaskynetdev_notifier_info_to_dev(void *ifp) 90294827Shselasky{ 91294827Shselasky return (ifp); 92294827Shselasky} 93294827Shselasky 94293419Shselaskyint register_netdevice_notifier(struct notifier_block *); 95293419Shselaskyint register_inetaddr_notifier(struct notifier_block *); 96293419Shselaskyint unregister_netdevice_notifier(struct notifier_block *); 97293419Shselaskyint unregister_inetaddr_notifier(struct notifier_block *); 98219820Sjeff 99219820Sjeff#define rtnl_lock() 100219820Sjeff#define rtnl_unlock() 101219820Sjeff 102219820Sjeffstatic inline int 103219820Sjeffdev_mc_delete(struct net_device *dev, void *addr, int alen, int all) 104219820Sjeff{ 105219820Sjeff struct sockaddr_dl sdl; 106219820Sjeff 107219820Sjeff if (alen > sizeof(sdl.sdl_data)) 108219820Sjeff return (-EINVAL); 109219820Sjeff memset(&sdl, 0, sizeof(sdl)); 110219820Sjeff sdl.sdl_len = sizeof(sdl); 111219820Sjeff sdl.sdl_family = AF_LINK; 112219820Sjeff sdl.sdl_alen = alen; 113219820Sjeff memcpy(&sdl.sdl_data, addr, alen); 114219820Sjeff 115219820Sjeff return -if_delmulti(dev, (struct sockaddr *)&sdl); 116219820Sjeff} 117219820Sjeff 118219820Sjeffstatic inline int 119294827Shselaskydev_mc_del(struct net_device *dev, void *addr) 120294827Shselasky{ 121294827Shselasky return (dev_mc_delete(dev, addr, 6, 0)); 122294827Shselasky} 123294827Shselasky 124294827Shselaskystatic inline int 125219820Sjeffdev_mc_add(struct net_device *dev, void *addr, int alen, int newonly) 126219820Sjeff{ 127219820Sjeff struct sockaddr_dl sdl; 128219820Sjeff 129219820Sjeff if (alen > sizeof(sdl.sdl_data)) 130219820Sjeff return (-EINVAL); 131219820Sjeff memset(&sdl, 0, sizeof(sdl)); 132219820Sjeff sdl.sdl_len = sizeof(sdl); 133219820Sjeff sdl.sdl_family = AF_LINK; 134219820Sjeff sdl.sdl_alen = alen; 135219820Sjeff memcpy(&sdl.sdl_data, addr, alen); 136219820Sjeff 137219820Sjeff return -if_addmulti(dev, (struct sockaddr *)&sdl, NULL); 138219820Sjeff} 139219820Sjeff 140219820Sjeff#endif /* _LINUX_NETDEVICE_H_ */ 141