initial work towards a FreeBSD network driver source level compatibility layer.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20985 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Hugo Santos
2007-05-02 23:10:18 +00:00
parent 3499cb7591
commit 750ddafd50
45 changed files with 4348 additions and 0 deletions
+1
View File
@@ -2,6 +2,7 @@ SubDir HAIKU_TOP src libs ;
SubInclude HAIKU_TOP src libs agg ;
SubInclude HAIKU_TOP src libs bsd ;
SubInclude HAIKU_TOP src libs compat ;
SubInclude HAIKU_TOP src libs crypt ;
SubInclude HAIKU_TOP src libs edit ;
SubInclude HAIKU_TOP src libs expat ;
+3
View File
@@ -0,0 +1,3 @@
SubDir HAIKU_TOP src libs compat ;
SubInclude HAIKU_TOP src libs compat freebsd_network ;
+12
View File
@@ -0,0 +1,12 @@
SubDir HAIKU_TOP src libs compat freebsd_network ;
UsePrivateHeaders kernel net ;
UseHeaders [ FDirName $(SUBDIR) ] : true ;
UseHeaders [ FDirName $(SUBDIR) headers ] : true ;
SubDirCcFlags [ FDefines _KERNEL=1 ] ;
Library libfreebsd_network.a :
compat.c
;
+3
View File
@@ -0,0 +1,3 @@
FreeBSD network driver compatability layer. Based on FreeBSD 6.2.
- Hugo, 3 May 2007
+58
View File
@@ -0,0 +1,58 @@
/*
* Copyright 2007, Hugo Santos. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Hugo Santos, [email protected]
*
* Some of this code is based on previous work by Marcus Overhagen.
*/
#include <KernelExport.h>
#include <drivers/PCI.h>
#include <compat/dev/pci/pcivar.h>
#include <compat/sys/bus.h>
// TODO a lot.
status_t init_compat_layer(void);
pci_module_info *gPci;
struct device {
int devId;
pci_info * pciInfo;
uint8 pciBus;
uint8 pciDev;
uint8 pciFunc;
};
uint32_t
pci_read_config(device_t dev, int offset, int size)
{
return gPci->read_pci_config(dev->pciBus, dev->pciDev, dev->pciFunc,
offset, size);
}
void
pci_write_config(device_t dev, int offset, uint32_t value, int size)
{
gPci->write_pci_config(dev->pciBus, dev->pciDev, dev->pciFunc, offset,
size, value);
}
status_t
init_compat_layer()
{
return B_OK;
}
module_dependency module_dependencies[] = {
{B_PCI_MODULE_NAME, (module_info **)&gPci},
{}
};
@@ -0,0 +1,33 @@
#ifndef _FBSD_COMPAT_ALTQ_IF_ALTQ_H_
#define _FBSD_COMPAT_ALTQ_IF_ALTQ_H_
#include <sys/mbuf.h>
#include <sys/mutex.h>
struct ifaltq {
struct mbuf * ifq_head;
struct mbuf * ifq_tail;
int ifq_len;
int ifq_maxlen;
struct mtx ifq_mtx;
struct mbuf * ifq_drv_head;
struct mbuf * ifq_drv_tail;
int ifq_drv_len;
int ifq_drv_maxlen;
int altq_flags;
};
#define ALTQF_READY 0x1
#define ALTDQ_REMOVE 1
#define ALTQ_IS_ENABLED(ifq) 0
#define ALTQ_DEQUEUE(ifr, m) (m) = NULL
#define TBR_IS_ENABLED(ifq) 0
#define tbr_dequeue_ptr(ifq, v) NULL
#endif
@@ -0,0 +1,229 @@
/* $NetBSD: miivar.h,v 1.8 1999/04/23 04:24:32 thorpej Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: src/sys/dev/mii/miivar.h,v 1.15.14.1 2006/06/24 06:14:24 oleg Exp $
*/
#ifndef _DEV_MII_MIIVAR_H_
#define _DEV_MII_MIIVAR_H_
#include <sys/queue.h>
/*
* Media Independent Interface configuration defintions.
*/
struct mii_softc;
/*
* Callbacks from MII layer into network interface device driver.
*/
typedef int (*mii_readreg_t)(struct device *, int, int);
typedef void (*mii_writereg_t)(struct device *, int, int, int);
typedef void (*mii_statchg_t)(struct device *);
/*
* A network interface driver has one of these structures in its softc.
* It is the interface from the network interface driver to the MII
* layer.
*/
struct mii_data {
struct ifmedia mii_media; /* media information */
struct ifnet *mii_ifp; /* pointer back to network interface */
/*
* For network interfaces with multiple PHYs, a list of all
* PHYs is required so they can all be notified when a media
* request is made.
*/
LIST_HEAD(mii_listhead, mii_softc) mii_phys;
int mii_instance;
/*
* PHY driver fills this in with active media status.
*/
int mii_media_status;
int mii_media_active;
/*
* Calls from MII layer into network interface driver.
*/
mii_readreg_t mii_readreg;
mii_writereg_t mii_writereg;
mii_statchg_t mii_statchg;
};
typedef struct mii_data mii_data_t;
/*
* This call is used by the MII layer to call into the PHY driver
* to perform a `service request'.
*/
typedef int (*mii_downcall_t)(struct mii_softc *, struct mii_data *, int);
/*
* Requests that can be made to the downcall.
*/
#define MII_TICK 1 /* once-per-second tick */
#define MII_MEDIACHG 2 /* user changed media; perform the switch */
#define MII_POLLSTAT 3 /* user requested media status; fill it in */
/*
* Each PHY driver's softc has one of these as the first member.
* XXX This would be better named "phy_softc", but this is the name
* XXX BSDI used, and we would like to have the same interface.
*/
struct mii_softc {
device_t mii_dev; /* generic device glue */
LIST_ENTRY(mii_softc) mii_list; /* entry on parent's PHY list */
int mii_phy; /* our MII address */
int mii_inst; /* instance for ifmedia */
mii_downcall_t mii_service; /* our downcall */
struct mii_data *mii_pdata; /* pointer to parent's mii_data */
int mii_flags; /* misc. flags; see below */
int mii_capabilities; /* capabilities from BMSR */
int mii_extcapabilities; /* extended capabilities */
int mii_ticks; /* MII_TICK counter */
int mii_anegticks; /* ticks before retrying aneg */
int mii_media_active; /* last active media */
int mii_media_status; /* last active status */
};
typedef struct mii_softc mii_softc_t;
/* mii_flags */
#define MIIF_INITDONE 0x0001 /* has been initialized (mii_data) */
#define MIIF_NOISOLATE 0x0002 /* do not isolate the PHY */
#define MIIF_NOLOOP 0x0004 /* no loopback capability */
#define MIIF_AUTOTSLEEP 0x0010 /* use tsleep(), not callout() */
#define MIIF_HAVEFIBER 0x0020 /* from parent: has fiber interface */
#define MIIF_HAVE_GTCR 0x0040 /* has 100base-T2/1000base-T CR */
#define MIIF_IS_1000X 0x0080 /* is a 1000BASE-X device */
#define MIIF_DOPAUSE 0x0100 /* advertise PAUSE capability */
#define MIIF_IS_HPNA 0x0200 /* is a HomePNA device */
/* Default mii_anegticks values */
#define MII_ANEGTICKS 5
#define MII_ANEGTICKS_GIGE 17
#define MIIF_INHERIT_MASK (MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP)
/*
* Used to attach a PHY to a parent.
*/
struct mii_attach_args {
struct mii_data *mii_data; /* pointer to parent data */
int mii_phyno; /* MII address */
int mii_id1; /* PHY ID register 1 */
int mii_id2; /* PHY ID register 2 */
int mii_capmask; /* capability mask from BMSR */
};
typedef struct mii_attach_args mii_attach_args_t;
/*
* Used to match a PHY.
*/
struct mii_phydesc {
u_int32_t mpd_oui; /* the PHY's OUI */
u_int32_t mpd_model; /* the PHY's model */
const char *mpd_name; /* the PHY's name */
};
/*
* An array of these structures map MII media types to BMCR/ANAR settings.
*/
struct mii_media {
int mm_bmcr; /* BMCR settings for this media */
int mm_anar; /* ANAR settings for this media */
int mm_gtcr; /* 100base-T2 or 1000base-T CR */
};
#define MII_MEDIA_NONE 0
#define MII_MEDIA_10_T 1
#define MII_MEDIA_10_T_FDX 2
#define MII_MEDIA_100_T4 3
#define MII_MEDIA_100_TX 4
#define MII_MEDIA_100_TX_FDX 5
#define MII_MEDIA_1000_X 6
#define MII_MEDIA_1000_X_FDX 7
#define MII_MEDIA_1000_T 8
#define MII_MEDIA_1000_T_FDX 9
#define MII_NMEDIA 10
#ifdef _KERNEL
#define PHY_READ(p, r) \
MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r))
#define PHY_WRITE(p, r, v) \
MIIBUS_WRITEREG((p)->mii_dev, (p)->mii_phy, (r), (v))
extern devclass_t miibus_devclass;
extern driver_t miibus_driver;
int miibus_probe(device_t);
int miibus_attach(device_t);
int miibus_detach(device_t);
int mii_anar(int);
void mii_down(struct mii_data *);
int mii_mediachg(struct mii_data *);
void mii_tick(struct mii_data *);
void mii_pollstat(struct mii_data *);
int mii_phy_probe(device_t, device_t *, ifm_change_cb_t, ifm_stat_cb_t);
void mii_add_media(struct mii_softc *);
void mii_phy_add_media(struct mii_softc *);
int mii_media_from_bmcr(int);
int mii_phy_auto(struct mii_softc *);
int mii_phy_detach(device_t dev);
void mii_phy_down(struct mii_softc *);
void mii_phy_reset(struct mii_softc *);
void mii_phy_setmedia(struct mii_softc *sc);
void mii_phy_update(struct mii_softc *, int);
int mii_phy_tick(struct mii_softc *);
const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma, const struct mii_phydesc *mpd);
void ukphy_status(struct mii_softc *);
#endif /* _KERNEL */
#endif /* _DEV_MII_MIIVAR_H_ */
@@ -0,0 +1,14 @@
#ifndef _FBSD_COMPAT_DEV_PCI_PCIREG_H_
#define _FBSD_COMPAT_DEV_PCI_PCIREG_H_
#define PCIR_COMMAND 0x04
#define PCIR_REVID 0x08
#define PCIR_CACHELNSZ 0x0c
#define PCIR_SUBVEND_0 0x2c
#define PCIR_SUBDEV_0 0x2e
#define PCIM_CMD_PORTEN 0x0001
#define PCIM_CMD_MEMEN 0x0002
#define PCIM_CMD_MWRICEN 0x0010
#endif
@@ -0,0 +1,21 @@
#ifndef _FBSD_COMPAT_DEV_PCI_PCIVAR_H_
#define _FBSD_COMPAT_DEV_PCI_PCIVAR_H_
#include <sys/bus.h>
int pci_enable_busmaster(device_t dev);
uint32_t pci_get_devid(device_t dev);
void pci_set_intpin(device_t dev, uint8_t pin);
uint8_t pci_get_intpin(device_t dev);
uint16_t pci_get_vendor(device_t dev);
uint16_t pci_get_device(device_t dev);
uint16_t pci_get_subvendor(device_t dev);
uint16_t pci_get_subdevice(device_t dev);
uint8_t pci_get_revid(device_t dev);
uint32_t pci_read_config(device_t dev, int reg, int width);
void pci_write_config(device_t dev, int reg, uint32_t val, int width);
#endif
@@ -0,0 +1,4 @@
#ifndef _FBSD_COMPAT_MACHINE_ENDIAN_H_
#define _FBSD_COMPAT_MACHINE_ENDIAN_H_
#endif
@@ -0,0 +1,9 @@
#ifndef _FBSD_COMPAT_MACHINE_RESOURCE_H_
#define _FBSD_COMPAT_MACHINE_RESOURCE_H_
#define SYS_RES_IRQ 0x1
#define SYS_RES_DRQ 0x2
#define SYS_RES_MEMORY 0x3
#define SYS_RES_IOPORT 0x4
#endif
@@ -0,0 +1,7 @@
#ifndef _FBSD_COMPAT_NET_BPF_H_
#define _FBSD_COMPAT_NET_BPF_H_
#define bpf_mtap(bpf_if, mbuf) do { } while (0)
#define BPF_MTAP(ifp, m) do { } while (0)
#endif
@@ -0,0 +1,382 @@
/*
* Fundamental constants relating to ethernet.
*
* $FreeBSD: src/sys/net/ethernet.h,v 1.24 2004/10/05 19:28:52 sam Exp $
*
*/
#ifndef _NET_ETHERNET_H_
#define _NET_ETHERNET_H_
/*
* Somce basic Ethernet constants.
*/
#define ETHER_ADDR_LEN 6 /* length of an Ethernet address */
#define ETHER_TYPE_LEN 2 /* length of the Ethernet type field */
#define ETHER_CRC_LEN 4 /* length of the Ethernet CRC */
#define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
#define ETHER_MIN_LEN 64 /* minimum frame len, including CRC */
#define ETHER_MAX_LEN 1518 /* maximum frame len, including CRC */
#define ETHER_MAX_LEN_JUMBO 9018 /* max jumbo frame len, including CRC */
#define ETHER_VLAN_ENCAP_LEN 4 /* len of 802.1Q VLAN encapsulation */
/*
* Mbuf adjust factor to force 32-bit alignment of IP header.
* Drivers should do m_adj(m, ETHER_ALIGN) when setting up a
* receive so the upper layers get the IP header properly aligned
* past the 14-byte Ethernet header.
*/
#define ETHER_ALIGN 2 /* driver adjust for IP hdr alignment */
/*
* Compute the maximum frame size based on ethertype (i.e. possible
* encapsulation) and whether or not an FCS is present.
*/
#define ETHER_MAX_FRAME(ifp, etype, hasfcs) \
((ifp)->if_mtu + ETHER_HDR_LEN + \
((hasfcs) ? ETHER_CRC_LEN : 0) + \
(((etype) == ETHERTYPE_VLAN) ? ETHER_VLAN_ENCAP_LEN : 0))
/*
* Ethernet-specific mbuf flags.
*/
#define M_HASFCS M_PROTO5 /* FCS included at end of frame */
/*
* Ethernet CRC32 polynomials (big- and little-endian verions).
*/
#define ETHER_CRC_POLY_LE 0xedb88320
#define ETHER_CRC_POLY_BE 0x04c11db6
/*
* A macro to validate a length with
*/
#define ETHER_IS_VALID_LEN(foo) \
((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
/*
* Structure of a 10Mb/s Ethernet header.
*/
struct ether_header {
u_char ether_dhost[ETHER_ADDR_LEN];
u_char ether_shost[ETHER_ADDR_LEN];
u_short ether_type;
};
/*
* Structure of a 48-bit Ethernet address.
*/
struct ether_addr {
u_char octet[ETHER_ADDR_LEN];
};
#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
/*
* NOTE: 0x0000-0x05DC (0..1500) are generally IEEE 802.3 length fields.
* However, there are some conflicts.
*/
#define ETHERTYPE_8023 0x0004 /* IEEE 802.3 packet */
/* 0x0101 .. 0x1FF Experimental */
#define ETHERTYPE_PUP 0x0200 /* Xerox PUP protocol - see 0A00 */
#define ETHERTYPE_PUPAT 0x0200 /* PUP Address Translation - see 0A01 */
#define ETHERTYPE_SPRITE 0x0500 /* ??? */
/* 0x0400 Nixdorf */
#define ETHERTYPE_NS 0x0600 /* XNS */
#define ETHERTYPE_NSAT 0x0601 /* XNS Address Translation (3Mb only) */
#define ETHERTYPE_DLOG1 0x0660 /* DLOG (?) */
#define ETHERTYPE_DLOG2 0x0661 /* DLOG (?) */
#define ETHERTYPE_IP 0x0800 /* IP protocol */
#define ETHERTYPE_X75 0x0801 /* X.75 Internet */
#define ETHERTYPE_NBS 0x0802 /* NBS Internet */
#define ETHERTYPE_ECMA 0x0803 /* ECMA Internet */
#define ETHERTYPE_CHAOS 0x0804 /* CHAOSnet */
#define ETHERTYPE_X25 0x0805 /* X.25 Level 3 */
#define ETHERTYPE_ARP 0x0806 /* Address resolution protocol */
#define ETHERTYPE_NSCOMPAT 0x0807 /* XNS Compatibility */
#define ETHERTYPE_FRARP 0x0808 /* Frame Relay ARP (RFC1701) */
/* 0x081C Symbolics Private */
/* 0x0888 - 0x088A Xyplex */
#define ETHERTYPE_UBDEBUG 0x0900 /* Ungermann-Bass network debugger */
#define ETHERTYPE_IEEEPUP 0x0A00 /* Xerox IEEE802.3 PUP */
#define ETHERTYPE_IEEEPUPAT 0x0A01 /* Xerox IEEE802.3 PUP Address Translation */
#define ETHERTYPE_VINES 0x0BAD /* Banyan VINES */
#define ETHERTYPE_VINESLOOP 0x0BAE /* Banyan VINES Loopback */
#define ETHERTYPE_VINESECHO 0x0BAF /* Banyan VINES Echo */
/* 0x1000 - 0x100F Berkeley Trailer */
/*
* The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
* (type-ETHERTYPE_TRAIL)*512 bytes of data followed
* by an ETHER type (as given above) and then the (variable-length) header.
*/
#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
#define ETHERTYPE_NTRAILER 16
#define ETHERTYPE_DCA 0x1234 /* DCA - Multicast */
#define ETHERTYPE_VALID 0x1600 /* VALID system protocol */
#define ETHERTYPE_DOGFIGHT 0x1989 /* Artificial Horizons ("Aviator" dogfight simulator [on Sun]) */
#define ETHERTYPE_RCL 0x1995 /* Datapoint Corporation (RCL lan protocol) */
/* The following 3C0x types
are unregistered: */
#define ETHERTYPE_NBPVCD 0x3C00 /* 3Com NBP virtual circuit datagram (like XNS SPP) not registered */
#define ETHERTYPE_NBPSCD 0x3C01 /* 3Com NBP System control datagram not registered */
#define ETHERTYPE_NBPCREQ 0x3C02 /* 3Com NBP Connect request (virtual cct) not registered */
#define ETHERTYPE_NBPCRSP 0x3C03 /* 3Com NBP Connect repsonse not registered */
#define ETHERTYPE_NBPCC 0x3C04 /* 3Com NBP Connect complete not registered */
#define ETHERTYPE_NBPCLREQ 0x3C05 /* 3Com NBP Close request (virtual cct) not registered */
#define ETHERTYPE_NBPCLRSP 0x3C06 /* 3Com NBP Close response not registered */
#define ETHERTYPE_NBPDG 0x3C07 /* 3Com NBP Datagram (like XNS IDP) not registered */
#define ETHERTYPE_NBPDGB 0x3C08 /* 3Com NBP Datagram broadcast not registered */
#define ETHERTYPE_NBPCLAIM 0x3C09 /* 3Com NBP Claim NetBIOS name not registered */
#define ETHERTYPE_NBPDLTE 0x3C0A /* 3Com NBP Delete Netbios name not registered */
#define ETHERTYPE_NBPRAS 0x3C0B /* 3Com NBP Remote adaptor status request not registered */
#define ETHERTYPE_NBPRAR 0x3C0C /* 3Com NBP Remote adaptor response not registered */
#define ETHERTYPE_NBPRST 0x3C0D /* 3Com NBP Reset not registered */
#define ETHERTYPE_PCS 0x4242 /* PCS Basic Block Protocol */
#define ETHERTYPE_IMLBLDIAG 0x424C /* Information Modes Little Big LAN diagnostic */
#define ETHERTYPE_DIDDLE 0x4321 /* THD - Diddle */
#define ETHERTYPE_IMLBL 0x4C42 /* Information Modes Little Big LAN */
#define ETHERTYPE_SIMNET 0x5208 /* BBN Simnet Private */
#define ETHERTYPE_DECEXPER 0x6000 /* DEC Unassigned, experimental */
#define ETHERTYPE_MOPDL 0x6001 /* DEC MOP dump/load */
#define ETHERTYPE_MOPRC 0x6002 /* DEC MOP remote console */
#define ETHERTYPE_DECnet 0x6003 /* DEC DECNET Phase IV route */
#define ETHERTYPE_DN ETHERTYPE_DECnet /* libpcap, tcpdump */
#define ETHERTYPE_LAT 0x6004 /* DEC LAT */
#define ETHERTYPE_DECDIAG 0x6005 /* DEC diagnostic protocol (at interface initialization?) */
#define ETHERTYPE_DECCUST 0x6006 /* DEC customer protocol */
#define ETHERTYPE_SCA 0x6007 /* DEC LAVC, SCA */
#define ETHERTYPE_AMBER 0x6008 /* DEC AMBER */
#define ETHERTYPE_DECMUMPS 0x6009 /* DEC MUMPS */
/* 0x6010 - 0x6014 3Com Corporation */
#define ETHERTYPE_TRANSETHER 0x6558 /* Trans Ether Bridging (RFC1701)*/
#define ETHERTYPE_RAWFR 0x6559 /* Raw Frame Relay (RFC1701) */
#define ETHERTYPE_UBDL 0x7000 /* Ungermann-Bass download */
#define ETHERTYPE_UBNIU 0x7001 /* Ungermann-Bass NIUs */
#define ETHERTYPE_UBDIAGLOOP 0x7002 /* Ungermann-Bass diagnostic/loopback */
#define ETHERTYPE_UBNMC 0x7003 /* Ungermann-Bass ??? (NMC to/from UB Bridge) */
#define ETHERTYPE_UBBST 0x7005 /* Ungermann-Bass Bridge Spanning Tree */
#define ETHERTYPE_OS9 0x7007 /* OS/9 Microware */
#define ETHERTYPE_OS9NET 0x7009 /* OS/9 Net? */
/* 0x7020 - 0x7029 LRT (England) (now Sintrom) */
#define ETHERTYPE_RACAL 0x7030 /* Racal-Interlan */
#define ETHERTYPE_PRIMENTS 0x7031 /* Prime NTS (Network Terminal Service) */
#define ETHERTYPE_CABLETRON 0x7034 /* Cabletron */
#define ETHERTYPE_CRONUSVLN 0x8003 /* Cronus VLN */
#define ETHERTYPE_CRONUS 0x8004 /* Cronus Direct */
#define ETHERTYPE_HP 0x8005 /* HP Probe */
#define ETHERTYPE_NESTAR 0x8006 /* Nestar */
#define ETHERTYPE_ATTSTANFORD 0x8008 /* AT&T/Stanford (local use) */
#define ETHERTYPE_EXCELAN 0x8010 /* Excelan */
#define ETHERTYPE_SG_DIAG 0x8013 /* SGI diagnostic type */
#define ETHERTYPE_SG_NETGAMES 0x8014 /* SGI network games */
#define ETHERTYPE_SG_RESV 0x8015 /* SGI reserved type */
#define ETHERTYPE_SG_BOUNCE 0x8016 /* SGI bounce server */
#define ETHERTYPE_APOLLODOMAIN 0x8019 /* Apollo DOMAIN */
#define ETHERTYPE_TYMSHARE 0x802E /* Tymeshare */
#define ETHERTYPE_TIGAN 0x802F /* Tigan, Inc. */
#define ETHERTYPE_REVARP 0x8035 /* Reverse addr resolution protocol */
#define ETHERTYPE_AEONIC 0x8036 /* Aeonic Systems */
#define ETHERTYPE_IPXNEW 0x8037 /* IPX (Novell Netware?) */
#define ETHERTYPE_LANBRIDGE 0x8038 /* DEC LANBridge */
#define ETHERTYPE_DSMD 0x8039 /* DEC DSM/DDP */
#define ETHERTYPE_ARGONAUT 0x803A /* DEC Argonaut Console */
#define ETHERTYPE_VAXELN 0x803B /* DEC VAXELN */
#define ETHERTYPE_DECDNS 0x803C /* DEC DNS Naming Service */
#define ETHERTYPE_ENCRYPT 0x803D /* DEC Ethernet Encryption */
#define ETHERTYPE_DECDTS 0x803E /* DEC Distributed Time Service */
#define ETHERTYPE_DECLTM 0x803F /* DEC LAN Traffic Monitor */
#define ETHERTYPE_DECNETBIOS 0x8040 /* DEC PATHWORKS DECnet NETBIOS Emulation */
#define ETHERTYPE_DECLAST 0x8041 /* DEC Local Area System Transport */
/* 0x8042 DEC Unassigned */
#define ETHERTYPE_PLANNING 0x8044 /* Planning Research Corp. */
/* 0x8046 - 0x8047 AT&T */
#define ETHERTYPE_DECAM 0x8048 /* DEC Availability Manager for Distributed Systems DECamds (but someone at DEC says not) */
#define ETHERTYPE_EXPERDATA 0x8049 /* ExperData */
#define ETHERTYPE_VEXP 0x805B /* Stanford V Kernel exp. */
#define ETHERTYPE_VPROD 0x805C /* Stanford V Kernel prod. */
#define ETHERTYPE_ES 0x805D /* Evans & Sutherland */
#define ETHERTYPE_LITTLE 0x8060 /* Little Machines */
#define ETHERTYPE_COUNTERPOINT 0x8062 /* Counterpoint Computers */
/* 0x8065 - 0x8066 Univ. of Mass @ Amherst */
#define ETHERTYPE_VEECO 0x8067 /* Veeco Integrated Auto. */
#define ETHERTYPE_GENDYN 0x8068 /* General Dynamics */
#define ETHERTYPE_ATT 0x8069 /* AT&T */
#define ETHERTYPE_AUTOPHON 0x806A /* Autophon */
#define ETHERTYPE_COMDESIGN 0x806C /* ComDesign */
#define ETHERTYPE_COMPUGRAPHIC 0x806D /* Compugraphic Corporation */
/* 0x806E - 0x8077 Landmark Graphics Corp. */
#define ETHERTYPE_MATRA 0x807A /* Matra */
#define ETHERTYPE_DDE 0x807B /* Dansk Data Elektronik */
#define ETHERTYPE_MERIT 0x807C /* Merit Internodal (or Univ of Michigan?) */
/* 0x807D - 0x807F Vitalink Communications */
#define ETHERTYPE_VLTLMAN 0x8080 /* Vitalink TransLAN III Management */
/* 0x8081 - 0x8083 Counterpoint Computers */
/* 0x8088 - 0x808A Xyplex */
#define ETHERTYPE_ATALK 0x809B /* AppleTalk */
#define ETHERTYPE_AT ETHERTYPE_ATALK /* old NetBSD */
#define ETHERTYPE_APPLETALK ETHERTYPE_ATALK /* HP-UX */
/* 0x809C - 0x809E Datability */
#define ETHERTYPE_SPIDER 0x809F /* Spider Systems Ltd. */
/* 0x80A3 Nixdorf */
/* 0x80A4 - 0x80B3 Siemens Gammasonics Inc. */
/* 0x80C0 - 0x80C3 DCA (Digital Comm. Assoc.) Data Exchange Cluster */
/* 0x80C4 - 0x80C5 Banyan Systems */
#define ETHERTYPE_PACER 0x80C6 /* Pacer Software */
#define ETHERTYPE_APPLITEK 0x80C7 /* Applitek Corporation */
/* 0x80C8 - 0x80CC Intergraph Corporation */
/* 0x80CD - 0x80CE Harris Corporation */
/* 0x80CF - 0x80D2 Taylor Instrument */
/* 0x80D3 - 0x80D4 Rosemount Corporation */
#define ETHERTYPE_SNA 0x80D5 /* IBM SNA Services over Ethernet */
#define ETHERTYPE_VARIAN 0x80DD /* Varian Associates */
/* 0x80DE - 0x80DF TRFS (Integrated Solutions Transparent Remote File System) */
/* 0x80E0 - 0x80E3 Allen-Bradley */
/* 0x80E4 - 0x80F0 Datability */
#define ETHERTYPE_RETIX 0x80F2 /* Retix */
#define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */
/* 0x80F4 - 0x80F5 Kinetics */
#define ETHERTYPE_APOLLO 0x80F7 /* Apollo Computer */
#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging (XXX conflicts) */
/* 0x80FF - 0x8101 Wellfleet Communications (XXX conflicts) */
#define ETHERTYPE_BOFL 0x8102 /* Wellfleet; BOFL (Breath OF Life) pkts [every 5-10 secs.] */
#define ETHERTYPE_WELLFLEET 0x8103 /* Wellfleet Communications */
/* 0x8107 - 0x8109 Symbolics Private */
#define ETHERTYPE_TALARIS 0x812B /* Talaris */
#define ETHERTYPE_WATERLOO 0x8130 /* Waterloo Microsystems Inc. (XXX which?) */
#define ETHERTYPE_HAYES 0x8130 /* Hayes Microcomputers (XXX which?) */
#define ETHERTYPE_VGLAB 0x8131 /* VG Laboratory Systems */
/* 0x8132 - 0x8137 Bridge Communications */
#define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */
#define ETHERTYPE_NOVELL 0x8138 /* Novell, Inc. */
/* 0x8139 - 0x813D KTI */
#define ETHERTYPE_MUMPS 0x813F /* M/MUMPS data sharing */
#define ETHERTYPE_AMOEBA 0x8145 /* Vrije Universiteit (NL) Amoeba 4 RPC (obsolete) */
#define ETHERTYPE_FLIP 0x8146 /* Vrije Universiteit (NL) FLIP (Fast Local Internet Protocol) */
#define ETHERTYPE_VURESERVED 0x8147 /* Vrije Universiteit (NL) [reserved] */
#define ETHERTYPE_LOGICRAFT 0x8148 /* Logicraft */
#define ETHERTYPE_NCD 0x8149 /* Network Computing Devices */
#define ETHERTYPE_ALPHA 0x814A /* Alpha Micro */
#define ETHERTYPE_SNMP 0x814C /* SNMP over Ethernet (see RFC1089) */
/* 0x814D - 0x814E BIIN */
#define ETHERTYPE_TEC 0x814F /* Technically Elite Concepts */
#define ETHERTYPE_RATIONAL 0x8150 /* Rational Corp */
/* 0x8151 - 0x8153 Qualcomm */
/* 0x815C - 0x815E Computer Protocol Pty Ltd */
/* 0x8164 - 0x8166 Charles River Data Systems */
#define ETHERTYPE_XTP 0x817D /* Protocol Engines XTP */
#define ETHERTYPE_SGITW 0x817E /* SGI/Time Warner prop. */
#define ETHERTYPE_HIPPI_FP 0x8180 /* HIPPI-FP encapsulation */
#define ETHERTYPE_STP 0x8181 /* Scheduled Transfer STP, HIPPI-ST */
/* 0x8182 - 0x8183 Reserved for HIPPI-6400 */
/* 0x8184 - 0x818C SGI prop. */
#define ETHERTYPE_MOTOROLA 0x818D /* Motorola */
#define ETHERTYPE_NETBEUI 0x8191 /* PowerLAN NetBIOS/NetBEUI (PC) */
/* 0x819A - 0x81A3 RAD Network Devices */
/* 0x81B7 - 0x81B9 Xyplex */
/* 0x81CC - 0x81D5 Apricot Computers */
/* 0x81D6 - 0x81DD Artisoft Lantastic */
/* 0x81E6 - 0x81EF Polygon */
/* 0x81F0 - 0x81F2 Comsat Labs */
/* 0x81F3 - 0x81F5 SAIC */
/* 0x81F6 - 0x81F8 VG Analytical */
/* 0x8203 - 0x8205 QNX Software Systems Ltd. */
/* 0x8221 - 0x8222 Ascom Banking Systems */
/* 0x823E - 0x8240 Advanced Encryption Systems */
/* 0x8263 - 0x826A Charles River Data Systems */
/* 0x827F - 0x8282 Athena Programming */
/* 0x829A - 0x829B Inst Ind Info Tech */
/* 0x829C - 0x82AB Taurus Controls */
/* 0x82AC - 0x8693 Walker Richer & Quinn */
#define ETHERTYPE_ACCTON 0x8390 /* Accton Technologies (unregistered) */
#define ETHERTYPE_TALARISMC 0x852B /* Talaris multicast */
#define ETHERTYPE_KALPANA 0x8582 /* Kalpana */
/* 0x8694 - 0x869D Idea Courier */
/* 0x869E - 0x86A1 Computer Network Tech */
/* 0x86A3 - 0x86AC Gateway Communications */
#define ETHERTYPE_SECTRA 0x86DB /* SECTRA */
#define ETHERTYPE_IPV6 0x86DD /* IP protocol version 6 */
#define ETHERTYPE_DELTACON 0x86DE /* Delta Controls */
#define ETHERTYPE_ATOMIC 0x86DF /* ATOMIC */
/* 0x86E0 - 0x86EF Landis & Gyr Powers */
/* 0x8700 - 0x8710 Motorola */
#define ETHERTYPE_RDP 0x8739 /* Control Technology Inc. RDP Without IP */
#define ETHERTYPE_MICP 0x873A /* Control Technology Inc. Mcast Industrial Ctrl Proto. */
/* 0x873B - 0x873C Control Technology Inc. Proprietary */
#define ETHERTYPE_TCPCOMP 0x876B /* TCP/IP Compression (RFC1701) */
#define ETHERTYPE_IPAS 0x876C /* IP Autonomous Systems (RFC1701) */
#define ETHERTYPE_SECUREDATA 0x876D /* Secure Data (RFC1701) */
#define ETHERTYPE_FLOWCONTROL 0x8808 /* 802.3x flow control packet */
#define ETHERTYPE_PPP 0x880B /* PPP (obsolete by PPPOE) */
#define ETHERTYPE_HITACHI 0x8820 /* Hitachi Cable (Optoelectronic Systems Laboratory) */
#define ETHERTYPE_MPLS 0x8847 /* MPLS Unicast */
#define ETHERTYPE_MPLS_MCAST 0x8848 /* MPLS Multicast */
#define ETHERTYPE_AXIS 0x8856 /* Axis Communications AB proprietary bootstrap/config */
#define ETHERTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
#define ETHERTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
#define ETHERTYPE_LANPROBE 0x8888 /* HP LanProbe test? */
#define ETHERTYPE_PAE 0x888e /* EAPOL PAE/802.1x */
#define ETHERTYPE_LOOPBACK 0x9000 /* Loopback: used to test interfaces */
#define ETHERTYPE_LBACK ETHERTYPE_LOOPBACK /* DEC MOP loopback */
#define ETHERTYPE_XNSSM 0x9001 /* 3Com (Formerly Bridge Communications), XNS Systems Management */
#define ETHERTYPE_TCPSM 0x9002 /* 3Com (Formerly Bridge Communications), TCP/IP Systems Management */
#define ETHERTYPE_BCLOOP 0x9003 /* 3Com (Formerly Bridge Communications), loopback detection */
#define ETHERTYPE_DEBNI 0xAAAA /* DECNET? Used by VAX 6220 DEBNI */
#define ETHERTYPE_SONIX 0xFAF5 /* Sonix Arpeggio */
#define ETHERTYPE_VITAL 0xFF00 /* BBN VITAL-LanBridge cache wakeups */
/* 0xFF00 - 0xFFOF ISC Bunker Ramo */
#define ETHERTYPE_MAX 0xFFFF /* Maximum valid ethernet type, reserved */
/*
* The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
* (type-ETHERTYPE_TRAIL)*512 bytes of data followed
* by an ETHER type (as given above) and then the (variable-length) header.
*/
#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
#define ETHERTYPE_NTRAILER 16
#define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
#define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
#define ETHERMTU_JUMBO (ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN)
#ifdef _KERNEL
struct ifnet;
struct mbuf;
struct rtentry;
struct sockaddr;
extern uint32_t ether_crc32_le(const uint8_t *, size_t);
extern uint32_t ether_crc32_be(const uint8_t *, size_t);
extern void ether_demux(struct ifnet *, struct mbuf *);
extern void ether_ifattach(struct ifnet *, const u_int8_t *);
extern void ether_ifdetach(struct ifnet *);
extern int ether_ioctl(struct ifnet *, int, caddr_t);
extern int ether_output(struct ifnet *,
struct mbuf *, struct sockaddr *, struct rtentry *);
extern int ether_output_frame(struct ifnet *, struct mbuf *);
extern char *ether_sprintf(const u_int8_t *);
#else /* _KERNEL */
#include <sys/cdefs.h>
/*
* Ethernet address conversion/parsing routines.
*/
__BEGIN_DECLS
struct ether_addr *ether_aton(const char *);
int ether_hostton(const char *, struct ether_addr *);
int ether_line(const char *, struct ether_addr *, char *);
char *ether_ntoa(const struct ether_addr *);
int ether_ntohost(char *, const struct ether_addr *);
__END_DECLS
#endif /* !_KERNEL */
#endif /* !_NET_ETHERNET_H_ */
@@ -0,0 +1,73 @@
#ifndef _FBSD_COMPAT_NET_IF_H_
#define _FBSD_COMPAT_NET_IF_H_
#include <posix/net/if.h>
#include <sys/time.h> /* for timeval */
/* Capabilities that interfaces can advertise. */
#define IFCAP_RXCSUM 0x0001 /* can offload checksum on RX */
#define IFCAP_TXCSUM 0x0002 /* can offload checksum on TX */
#define IFCAP_NETCONS 0x0004 /* can be a network console */
#define IFCAP_VLAN_MTU 0x0008 /* VLAN-compatible MTU */
#define IFCAP_VLAN_HWTAGGING 0x0010 /* hardware VLAN tag support */
#define IFCAP_JUMBO_MTU 0x0020 /* 9000 byte MTU supported */
#define IFCAP_POLLING 0x0040 /* driver supports polling */
#define IFCAP_HWCSUM (IFCAP_RXCSUM | IFCAP_TXCSUM)
#define IFF_DRV_RUNNING 0x10000
#define IFF_DRV_OACTIVE 0x20000
#define IFF_LINK0 0x40000
struct ifmediareq {
char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
int ifm_current; /* current media options */
int ifm_mask; /* don't care mask */
int ifm_status; /* media status */
int ifm_active; /* active options */
int ifm_count; /* # entries in ifm_ulist array */
int *ifm_ulist; /* media words */
};
/*
* Structure describing information about an interface
* which may be of interest to management entities.
*/
struct if_data {
/* generic interface information */
u_char ifi_type; /* ethernet, tokenring, etc */
u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
u_char ifi_addrlen; /* media address length */
u_char ifi_hdrlen; /* media header length */
u_char ifi_link_state; /* current link state */
u_char ifi_recvquota; /* polling quota for receive intrs */
u_char ifi_xmitquota; /* polling quota for xmit intrs */
u_char ifi_datalen; /* length of this data struct */
u_long ifi_mtu; /* maximum transmission unit */
u_long ifi_metric; /* routing metric (external only) */
u_long ifi_baudrate; /* linespeed */
/* volatile statistics */
u_long ifi_ipackets; /* packets received on interface */
u_long ifi_ierrors; /* input errors on interface */
u_long ifi_opackets; /* packets sent on interface */
u_long ifi_oerrors; /* output errors on interface */
u_long ifi_collisions; /* collisions on csma interfaces */
u_long ifi_ibytes; /* total number of octets received */
u_long ifi_obytes; /* total number of octets sent */
u_long ifi_imcasts; /* packets received via multicast */
u_long ifi_omcasts; /* packets sent via multicast */
u_long ifi_iqdrops; /* dropped on input, this interface */
u_long ifi_noproto; /* destined for unsupported protocol */
u_long ifi_hwassist; /* HW offload capabilities */
time_t ifi_epoch; /* uptime at attach or stat reset */
#ifdef __alpha__
u_int ifi_timepad; /* time_t is int, not long on alpha */
#endif
struct timeval ifi_lastchange; /* time of last administrative change */
};
#endif
@@ -0,0 +1,115 @@
/*-
* Copyright (c) 1986, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)if_arp.h 8.1 (Berkeley) 6/10/93
* $FreeBSD: src/sys/net/if_arp.h,v 1.22 2005/06/10 16:49:18 brooks Exp $
*/
#ifndef _NET_IF_ARP_H_
#define _NET_IF_ARP_H_
/*
* Address Resolution Protocol.
*
* See RFC 826 for protocol description. ARP packets are variable
* in size; the arphdr structure defines the fixed-length portion.
* Protocol type values are the same as those for 10 Mb/s Ethernet.
* It is followed by the variable-sized fields ar_sha, arp_spa,
* arp_tha and arp_tpa in that order, according to the lengths
* specified. Field names used correspond to RFC 826.
*/
struct arphdr {
u_short ar_hrd; /* format of hardware address */
#define ARPHRD_ETHER 1 /* ethernet hardware format */
#define ARPHRD_IEEE802 6 /* token-ring hardware format */
#define ARPHRD_ARCNET 7 /* arcnet hardware format */
#define ARPHRD_FRELAY 15 /* frame relay hardware format */
#define ARPHRD_IEEE1394 24 /* firewire hardware format */
u_short ar_pro; /* format of protocol address */
u_char ar_hln; /* length of hardware address */
u_char ar_pln; /* length of protocol address */
u_short ar_op; /* one of: */
#define ARPOP_REQUEST 1 /* request to resolve address */
#define ARPOP_REPLY 2 /* response to previous request */
#define ARPOP_REVREQUEST 3 /* request protocol address given hardware */
#define ARPOP_REVREPLY 4 /* response giving protocol address */
#define ARPOP_INVREQUEST 8 /* request to identify peer */
#define ARPOP_INVREPLY 9 /* response identifying peer */
/*
* The remaining fields are variable in size,
* according to the sizes above.
*/
#ifdef COMMENT_ONLY
u_char ar_sha[]; /* sender hardware address */
u_char ar_spa[]; /* sender protocol address */
u_char ar_tha[]; /* target hardware address */
u_char ar_tpa[]; /* target protocol address */
#endif
};
#define ar_sha(ap) (((caddr_t)((ap)+1)) + 0)
#define ar_spa(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln)
#define ar_tha(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln + (ap)->ar_pln)
#define ar_tpa(ap) (((caddr_t)((ap)+1)) + 2*(ap)->ar_hln + (ap)->ar_pln)
#define arphdr_len2(ar_hln, ar_pln) \
(sizeof(struct arphdr) + 2*(ar_hln) + 2*(ar_pln))
#define arphdr_len(ap) (arphdr_len2((ap)->ar_hln, (ap)->ar_pln))
/*
* ARP ioctl request
*/
struct arpreq {
struct sockaddr arp_pa; /* protocol address */
struct sockaddr arp_ha; /* hardware address */
int arp_flags; /* flags */
};
/* arp_flags and at_flags field values */
#define ATF_INUSE 0x01 /* entry in use */
#define ATF_COM 0x02 /* completed entry (enaddr valid) */
#define ATF_PERM 0x04 /* permanent entry */
#define ATF_PUBL 0x08 /* publish entry (respond for other host) */
#define ATF_USETRAILERS 0x10 /* has requested trailers */
#ifdef _KERNEL
/*
* Structure shared between the ethernet driver modules and
* the address resolution code.
*/
struct arpcom {
struct ifnet *ac_ifp; /* network-visible interface */
u_char _ac_enaddr[6]; /* ethernet hardware address */
void *ac_netgraph; /* ng_ether(4) netgraph node info */
};
#define IFP2AC(ifp) ((struct arpcom *)(ifp->if_l2com))
#define IFP2ENADDR(ifp) (IFP2AC(ifp)->_ac_enaddr)
#define AC2IFP(ac) ((ac)->ac_ifp)
#endif
#endif /* !_NET_IF_ARP_H_ */
@@ -0,0 +1,646 @@
/* $NetBSD: if_media.h,v 1.3 1997/03/26 01:19:27 thorpej Exp $ */
/* $FreeBSD: src/sys/net/if_media.h,v 1.30.2.3 2006/08/10 10:21:00 glebius Exp $ */
/*-
* Copyright (c) 1997
* Jonathan Stone and Jason R. Thorpe. All rights reserved.
*
* This software is derived from information provided by Matt Thomas.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Jonathan Stone
* and Jason R. Thorpe for the NetBSD Project.
* 4. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _NET_IF_MEDIA_H_
#define _NET_IF_MEDIA_H_
/*
* Prototypes and definitions for BSD/OS-compatible network interface
* media selection.
*
* Where it is safe to do so, this code strays slightly from the BSD/OS
* design. Software which uses the API (device drivers, basically)
* shouldn't notice any difference.
*
* Many thanks to Matt Thomas for providing the information necessary
* to implement this interface.
*/
#ifdef _KERNEL
#include <sys/queue.h>
/*
* Driver callbacks for media status and change requests.
*/
typedef int (*ifm_change_cb_t)(struct ifnet *ifp);
typedef void (*ifm_stat_cb_t)(struct ifnet *ifp, struct ifmediareq *req);
/*
* In-kernel representation of a single supported media type.
*/
struct ifmedia_entry {
LIST_ENTRY(ifmedia_entry) ifm_list;
int ifm_media; /* description of this media attachment */
int ifm_data; /* for driver-specific use */
void *ifm_aux; /* for driver-specific use */
};
/*
* One of these goes into a network interface's softc structure.
* It is used to keep general media state.
*/
struct ifmedia {
int ifm_mask; /* mask of changes we don't care about */
int ifm_media; /* current user-set media word */
struct ifmedia_entry *ifm_cur; /* currently selected media */
LIST_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */
ifm_change_cb_t ifm_change; /* media change driver callback */
ifm_stat_cb_t ifm_status; /* media status driver callback */
};
/* Initialize an interface's struct if_media field. */
void ifmedia_init(struct ifmedia *ifm, int dontcare_mask,
ifm_change_cb_t change_callback, ifm_stat_cb_t status_callback);
/* Remove all mediums from a struct ifmedia. */
void ifmedia_removeall( struct ifmedia *ifm);
/* Add one supported medium to a struct ifmedia. */
void ifmedia_add(struct ifmedia *ifm, int mword, int data, void *aux);
/* Add an array (of ifmedia_entry) media to a struct ifmedia. */
void ifmedia_list_add(struct ifmedia *mp, struct ifmedia_entry *lp,
int count);
/* Set default media type on initialization. */
void ifmedia_set(struct ifmedia *ifm, int mword);
/* Common ioctl function for getting/setting media, called by driver. */
int ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr,
struct ifmedia *ifm, u_long cmd);
/* Compute baudrate for a given media. */
uint64_t ifmedia_baudrate(int);
#endif /*_KERNEL */
/*
* if_media Options word:
* Bits Use
* ---- -------
* 0-4 Media variant
* 5-7 Media type
* 8-15 Type specific options
* 16-18 Mode (for multi-mode devices)
* 19 RFU
* 20-27 Shared (global) options
* 28-31 Instance
*/
/*
* Ethernet
*/
#define IFM_ETHER 0x00000020
#define IFM_10_T 3 /* 10BaseT - RJ45 */
#define IFM_10_2 4 /* 10Base2 - Thinnet */
#define IFM_10_5 5 /* 10Base5 - AUI */
#define IFM_100_TX 6 /* 100BaseTX - RJ45 */
#define IFM_100_FX 7 /* 100BaseFX - Fiber */
#define IFM_100_T4 8 /* 100BaseT4 - 4 pair cat 3 */
#define IFM_100_VG 9 /* 100VG-AnyLAN */
#define IFM_100_T2 10 /* 100BaseT2 */
#define IFM_1000_SX 11 /* 1000BaseSX - multi-mode fiber */
#define IFM_10_STP 12 /* 10BaseT over shielded TP */
#define IFM_10_FL 13 /* 10BaseFL - Fiber */
#define IFM_1000_LX 14 /* 1000baseLX - single-mode fiber */
#define IFM_1000_CX 15 /* 1000baseCX - 150ohm STP */
#define IFM_1000_T 16 /* 1000baseT - 4 pair cat 5 */
#define IFM_HPNA_1 17 /* HomePNA 1.0 (1Mb/s) */
#define IFM_10G_LR 18 /* 10GBase-LR 1310nm Single-mode */
#define IFM_10G_SR 19 /* 10GBase-SR 850nm Multi-mode */
#define IFM_10G_CX4 20 /* 10GBase CX4 copper */
/* note 31 is the max! */
#define IFM_ETH_MASTER 0x00000100 /* master mode (1000baseT) */
/*
* Token ring
*/
#define IFM_TOKEN 0x00000040
#define IFM_TOK_STP4 3 /* Shielded twisted pair 4m - DB9 */
#define IFM_TOK_STP16 4 /* Shielded twisted pair 16m - DB9 */
#define IFM_TOK_UTP4 5 /* Unshielded twisted pair 4m - RJ45 */
#define IFM_TOK_UTP16 6 /* Unshielded twisted pair 16m - RJ45 */
#define IFM_TOK_STP100 7 /* Shielded twisted pair 100m - DB9 */
#define IFM_TOK_UTP100 8 /* Unshielded twisted pair 100m - RJ45 */
#define IFM_TOK_ETR 0x00000200 /* Early token release */
#define IFM_TOK_SRCRT 0x00000400 /* Enable source routing features */
#define IFM_TOK_ALLR 0x00000800 /* All routes / Single route bcast */
#define IFM_TOK_DTR 0x00002000 /* Dedicated token ring */
#define IFM_TOK_CLASSIC 0x00004000 /* Classic token ring */
#define IFM_TOK_AUTO 0x00008000 /* Automatic Dedicate/Classic token ring */
/*
* FDDI
*/
#define IFM_FDDI 0x00000060
#define IFM_FDDI_SMF 3 /* Single-mode fiber */
#define IFM_FDDI_MMF 4 /* Multi-mode fiber */
#define IFM_FDDI_UTP 5 /* CDDI / UTP */
#define IFM_FDDI_DA 0x00000100 /* Dual attach / single attach */
/*
* IEEE 802.11 Wireless
*/
#define IFM_IEEE80211 0x00000080
/* NB: 0,1,2 are auto, manual, none defined below */
#define IFM_IEEE80211_FH1 3 /* Frequency Hopping 1Mbps */
#define IFM_IEEE80211_FH2 4 /* Frequency Hopping 2Mbps */
#define IFM_IEEE80211_DS1 5 /* Direct Sequence 1Mbps */
#define IFM_IEEE80211_DS2 6 /* Direct Sequence 2Mbps */
#define IFM_IEEE80211_DS5 7 /* Direct Sequence 5.5Mbps */
#define IFM_IEEE80211_DS11 8 /* Direct Sequence 11Mbps */
#define IFM_IEEE80211_DS22 9 /* Direct Sequence 22Mbps */
#define IFM_IEEE80211_OFDM6 10 /* OFDM 6Mbps */
#define IFM_IEEE80211_OFDM9 11 /* OFDM 9Mbps */
#define IFM_IEEE80211_OFDM12 12 /* OFDM 12Mbps */
#define IFM_IEEE80211_OFDM18 13 /* OFDM 18Mbps */
#define IFM_IEEE80211_OFDM24 14 /* OFDM 24Mbps */
#define IFM_IEEE80211_OFDM36 15 /* OFDM 36Mbps */
#define IFM_IEEE80211_OFDM48 16 /* OFDM 48Mbps */
#define IFM_IEEE80211_OFDM54 17 /* OFDM 54Mbps */
#define IFM_IEEE80211_OFDM72 18 /* OFDM 72Mbps */
#define IFM_IEEE80211_DS354k 19 /* Direct Sequence 354Kbps */
#define IFM_IEEE80211_DS512k 20 /* Direct Sequence 512Kbps */
#define IFM_IEEE80211_ADHOC 0x00000100 /* Operate in Adhoc mode */
#define IFM_IEEE80211_HOSTAP 0x00000200 /* Operate in Host AP mode */
#define IFM_IEEE80211_IBSS 0x00000400 /* Operate in IBSS mode */
#define IFM_IEEE80211_IBSSMASTER 0x00000800 /* Operate as an IBSS master */
#define IFM_IEEE80211_TURBO 0x00001000 /* Operate in turbo mode */
#define IFM_IEEE80211_MONITOR 0x00002000 /* Operate in monitor mode */
/* operating mode for multi-mode devices */
#define IFM_IEEE80211_11A 0x00010000 /* 5Ghz, OFDM mode */
#define IFM_IEEE80211_11B 0x00020000 /* Direct Sequence mode */
#define IFM_IEEE80211_11G 0x00030000 /* 2Ghz, CCK mode */
#define IFM_IEEE80211_FH 0x00040000 /* 2Ghz, GFSK mode */
/*
* ATM
*/
#define IFM_ATM 0x000000a0
#define IFM_ATM_UNKNOWN 3
#define IFM_ATM_UTP_25 4
#define IFM_ATM_TAXI_100 5
#define IFM_ATM_TAXI_140 6
#define IFM_ATM_MM_155 7
#define IFM_ATM_SM_155 8
#define IFM_ATM_UTP_155 9
#define IFM_ATM_MM_622 10
#define IFM_ATM_SM_622 11
#define IFM_ATM_VIRTUAL 12
#define IFM_ATM_SDH 0x00000100 /* SDH instead of SONET */
#define IFM_ATM_NOSCRAMB 0x00000200 /* no scrambling */
#define IFM_ATM_UNASSIGNED 0x00000400 /* unassigned cells */
/*
* CARP Common Address Redundancy Protocol
*/
#define IFM_CARP 0x000000c0
/*
* Shared media sub-types
*/
#define IFM_AUTO 0 /* Autoselect best media */
#define IFM_MANUAL 1 /* Jumper/dipswitch selects media */
#define IFM_NONE 2 /* Deselect all media */
/*
* Shared options
*/
#define IFM_FDX 0x00100000 /* Force full duplex */
#define IFM_HDX 0x00200000 /* Force half duplex */
#define IFM_FLAG0 0x01000000 /* Driver defined flag */
#define IFM_FLAG1 0x02000000 /* Driver defined flag */
#define IFM_FLAG2 0x04000000 /* Driver defined flag */
#define IFM_LOOP 0x08000000 /* Put hardware in loopback */
/*
* Masks
*/
#define IFM_NMASK 0x000000e0 /* Network type */
#define IFM_TMASK 0x0000001f /* Media sub-type */
#define IFM_IMASK 0xf0000000 /* Instance */
#define IFM_ISHIFT 28 /* Instance shift */
#define IFM_OMASK 0x0000ff00 /* Type specific options */
#define IFM_MMASK 0x00070000 /* Mode */
#define IFM_MSHIFT 16 /* Mode shift */
#define IFM_GMASK 0x0ff00000 /* Global options */
/*
* Status bits
*/
#define IFM_AVALID 0x00000001 /* Active bit valid */
#define IFM_ACTIVE 0x00000002 /* Interface attached to working net */
/* Mask of "status valid" bits, for ifconfig(8). */
#define IFM_STATUS_VALID IFM_AVALID
/* List of "status valid" bits, for ifconfig(8). */
#define IFM_STATUS_VALID_LIST { \
IFM_AVALID, \
0 \
}
/*
* Macros to extract various bits of information from the media word.
*/
#define IFM_TYPE(x) ((x) & IFM_NMASK)
#define IFM_SUBTYPE(x) ((x) & IFM_TMASK)
#define IFM_TYPE_OPTIONS(x) ((x) & IFM_OMASK)
#define IFM_INST(x) (((x) & IFM_IMASK) >> IFM_ISHIFT)
#define IFM_OPTIONS(x) ((x) & (IFM_OMASK|IFM_GMASK))
#define IFM_MODE(x) ((x) & IFM_MMASK)
#define IFM_INST_MAX IFM_INST(IFM_IMASK)
/*
* Macro to create a media word.
*/
#define IFM_MAKEWORD(type, subtype, options, instance) \
((type) | (subtype) | (options) | ((instance) << IFM_ISHIFT))
#define IFM_MAKEMODE(mode) \
(((mode) << IFM_MSHIFT) & IFM_MMASK)
/*
* NetBSD extension not defined in the BSDI API. This is used in various
* places to get the canonical description for a given type/subtype.
*
* NOTE: all but the top-level type descriptions must contain NO whitespace!
* Otherwise, parsing these in ifconfig(8) would be a nightmare.
*/
struct ifmedia_description {
int ifmt_word; /* word value; may be masked */
const char *ifmt_string; /* description */
};
#define IFM_TYPE_DESCRIPTIONS { \
{ IFM_ETHER, "Ethernet" }, \
{ IFM_TOKEN, "Token ring" }, \
{ IFM_FDDI, "FDDI" }, \
{ IFM_IEEE80211, "IEEE 802.11 Wireless Ethernet" }, \
{ IFM_ATM, "ATM" }, \
{ IFM_CARP, "Common Address Redundancy Protocol" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_ETHERNET_DESCRIPTIONS { \
{ IFM_10_T, "10baseT/UTP" }, \
{ IFM_10_2, "10base2/BNC" }, \
{ IFM_10_5, "10base5/AUI" }, \
{ IFM_100_TX, "100baseTX" }, \
{ IFM_100_FX, "100baseFX" }, \
{ IFM_100_T4, "100baseT4" }, \
{ IFM_100_VG, "100baseVG" }, \
{ IFM_100_T2, "100baseT2" }, \
{ IFM_10_STP, "10baseSTP" }, \
{ IFM_10_FL, "10baseFL" }, \
{ IFM_1000_SX, "1000baseSX" }, \
{ IFM_1000_LX, "1000baseLX" }, \
{ IFM_1000_CX, "1000baseCX" }, \
{ IFM_1000_T, "1000baseTX" }, \
{ IFM_1000_T, "1000baseT" }, \
{ IFM_HPNA_1, "homePNA" }, \
{ IFM_10G_LR, "10Gbase-LR" }, \
{ IFM_10G_SR, "10Gbase-SR" }, \
{ IFM_10G_CX4, "10Gbase-CX4" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_ETHERNET_ALIASES { \
{ IFM_10_T, "UTP" }, \
{ IFM_10_T, "10UTP" }, \
{ IFM_10_2, "BNC" }, \
{ IFM_10_2, "10BNC" }, \
{ IFM_10_5, "AUI" }, \
{ IFM_10_5, "10AUI" }, \
{ IFM_100_TX, "100TX" }, \
{ IFM_100_T4, "100T4" }, \
{ IFM_100_VG, "100VG" }, \
{ IFM_100_T2, "100T2" }, \
{ IFM_10_STP, "10STP" }, \
{ IFM_10_FL, "10FL" }, \
{ IFM_1000_SX, "1000SX" }, \
{ IFM_1000_LX, "1000LX" }, \
{ IFM_1000_CX, "1000CX" }, \
{ IFM_1000_T, "1000TX" }, \
{ IFM_1000_T, "1000T" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS { \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_TOKENRING_DESCRIPTIONS { \
{ IFM_TOK_STP4, "DB9/4Mbit" }, \
{ IFM_TOK_STP16, "DB9/16Mbit" }, \
{ IFM_TOK_UTP4, "UTP/4Mbit" }, \
{ IFM_TOK_UTP16, "UTP/16Mbit" }, \
{ IFM_TOK_STP100, "STP/100Mbit" }, \
{ IFM_TOK_UTP100, "UTP/100Mbit" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_TOKENRING_ALIASES { \
{ IFM_TOK_STP4, "4STP" }, \
{ IFM_TOK_STP16, "16STP" }, \
{ IFM_TOK_UTP4, "4UTP" }, \
{ IFM_TOK_UTP16, "16UTP" }, \
{ IFM_TOK_STP100, "100STP" }, \
{ IFM_TOK_UTP100, "100UTP" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS { \
{ IFM_TOK_ETR, "EarlyTokenRelease" }, \
{ IFM_TOK_SRCRT, "SourceRouting" }, \
{ IFM_TOK_ALLR, "AllRoutes" }, \
{ IFM_TOK_DTR, "Dedicated" }, \
{ IFM_TOK_CLASSIC,"Classic" }, \
{ IFM_TOK_AUTO, " " }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_FDDI_DESCRIPTIONS { \
{ IFM_FDDI_SMF, "Single-mode" }, \
{ IFM_FDDI_MMF, "Multi-mode" }, \
{ IFM_FDDI_UTP, "UTP" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_FDDI_ALIASES { \
{ IFM_FDDI_SMF, "SMF" }, \
{ IFM_FDDI_MMF, "MMF" }, \
{ IFM_FDDI_UTP, "CDDI" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS { \
{ IFM_FDDI_DA, "Dual-attach" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_IEEE80211_DESCRIPTIONS { \
{ IFM_IEEE80211_FH1, "FH/1Mbps" }, \
{ IFM_IEEE80211_FH2, "FH/2Mbps" }, \
{ IFM_IEEE80211_DS1, "DS/1Mbps" }, \
{ IFM_IEEE80211_DS2, "DS/2Mbps" }, \
{ IFM_IEEE80211_DS5, "DS/5.5Mbps" }, \
{ IFM_IEEE80211_DS11, "DS/11Mbps" }, \
{ IFM_IEEE80211_DS22, "DS/22Mbps" }, \
{ IFM_IEEE80211_OFDM6, "OFDM/6Mbps" }, \
{ IFM_IEEE80211_OFDM9, "OFDM/9Mbps" }, \
{ IFM_IEEE80211_OFDM12, "OFDM/12Mbps" }, \
{ IFM_IEEE80211_OFDM18, "OFDM/18Mbps" }, \
{ IFM_IEEE80211_OFDM24, "OFDM/24Mbps" }, \
{ IFM_IEEE80211_OFDM36, "OFDM/36Mbps" }, \
{ IFM_IEEE80211_OFDM48, "OFDM/48Mbps" }, \
{ IFM_IEEE80211_OFDM54, "OFDM/54Mbps" }, \
{ IFM_IEEE80211_OFDM72, "OFDM/72Mbps" }, \
{ IFM_IEEE80211_DS354k, "DS/354Kbps" }, \
{ IFM_IEEE80211_DS512k, "DS/512Kbps" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_IEEE80211_ALIASES { \
{ IFM_IEEE80211_FH1, "FH1" }, \
{ IFM_IEEE80211_FH2, "FH2" }, \
{ IFM_IEEE80211_FH1, "FrequencyHopping/1Mbps" }, \
{ IFM_IEEE80211_FH2, "FrequencyHopping/2Mbps" }, \
{ IFM_IEEE80211_DS1, "DS1" }, \
{ IFM_IEEE80211_DS2, "DS2" }, \
{ IFM_IEEE80211_DS5, "DS5.5" }, \
{ IFM_IEEE80211_DS11, "DS11" }, \
{ IFM_IEEE80211_DS22, "DS22" }, \
{ IFM_IEEE80211_DS1, "DirectSequence/1Mbps" }, \
{ IFM_IEEE80211_DS2, "DirectSequence/2Mbps" }, \
{ IFM_IEEE80211_DS5, "DirectSequence/5.5Mbps" }, \
{ IFM_IEEE80211_DS11, "DirectSequence/11Mbps" }, \
{ IFM_IEEE80211_DS22, "DirectSequence/22Mbps" }, \
{ IFM_IEEE80211_OFDM6, "OFDM6" }, \
{ IFM_IEEE80211_OFDM9, "OFDM9" }, \
{ IFM_IEEE80211_OFDM12, "OFDM12" }, \
{ IFM_IEEE80211_OFDM18, "OFDM18" }, \
{ IFM_IEEE80211_OFDM24, "OFDM24" }, \
{ IFM_IEEE80211_OFDM36, "OFDM36" }, \
{ IFM_IEEE80211_OFDM48, "OFDM48" }, \
{ IFM_IEEE80211_OFDM54, "OFDM54" }, \
{ IFM_IEEE80211_OFDM72, "OFDM72" }, \
{ IFM_IEEE80211_DS1, "CCK1" }, \
{ IFM_IEEE80211_DS2, "CCK2" }, \
{ IFM_IEEE80211_DS5, "CCK5.5" }, \
{ IFM_IEEE80211_DS11, "CCK11" }, \
{ IFM_IEEE80211_DS354k, "DS354K" }, \
{ IFM_IEEE80211_DS354k, "DirectSequence/354Kbps" }, \
{ IFM_IEEE80211_DS512k, "DS512K" }, \
{ IFM_IEEE80211_DS512k, "DirectSequence/512Kbps" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_IEEE80211_OPTION_DESCRIPTIONS { \
{ IFM_IEEE80211_ADHOC, "adhoc" }, \
{ IFM_IEEE80211_HOSTAP, "hostap" }, \
{ IFM_IEEE80211_IBSS, "ibss" }, \
{ IFM_IEEE80211_IBSSMASTER, "ibss-master" }, \
{ IFM_IEEE80211_TURBO, "turbo" }, \
{ IFM_IEEE80211_MONITOR, "monitor" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_IEEE80211_MODE_DESCRIPTIONS { \
{ IFM_AUTO, "autoselect" }, \
{ IFM_IEEE80211_11A, "11a" }, \
{ IFM_IEEE80211_11B, "11b" }, \
{ IFM_IEEE80211_11G, "11g" }, \
{ IFM_IEEE80211_FH, "fh" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_IEEE80211_MODE_ALIASES { \
{ IFM_AUTO, "auto" }, \
{ 0, NULL }, \
}
# define IFM_SUBTYPE_ATM_DESCRIPTIONS { \
{ IFM_ATM_UNKNOWN, "Unknown" }, \
{ IFM_ATM_UTP_25, "UTP/25.6MBit" }, \
{ IFM_ATM_TAXI_100, "Taxi/100MBit" }, \
{ IFM_ATM_TAXI_140, "Taxi/140MBit" }, \
{ IFM_ATM_MM_155, "Multi-mode/155MBit" }, \
{ IFM_ATM_SM_155, "Single-mode/155MBit" }, \
{ IFM_ATM_UTP_155, "UTP/155MBit" }, \
{ IFM_ATM_MM_622, "Multi-mode/622MBit" }, \
{ IFM_ATM_SM_622, "Single-mode/622MBit" }, \
{ IFM_ATM_VIRTUAL, "Virtual" }, \
{ 0, NULL }, \
}
# define IFM_SUBTYPE_ATM_ALIASES { \
{ IFM_ATM_UNKNOWN, "UNKNOWN" }, \
{ IFM_ATM_UTP_25, "UTP-25" }, \
{ IFM_ATM_TAXI_100, "TAXI-100" }, \
{ IFM_ATM_TAXI_140, "TAXI-140" }, \
{ IFM_ATM_MM_155, "MM-155" }, \
{ IFM_ATM_SM_155, "SM-155" }, \
{ IFM_ATM_UTP_155, "UTP-155" }, \
{ IFM_ATM_MM_622, "MM-622" }, \
{ IFM_ATM_SM_622, "SM-622" }, \
{ IFM_ATM_VIRTUAL, "VIRTUAL" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_ATM_OPTION_DESCRIPTIONS { \
{ IFM_ATM_SDH, "SDH" }, \
{ IFM_ATM_NOSCRAMB, "Noscramb" }, \
{ IFM_ATM_UNASSIGNED, "Unassigned" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_SHARED_DESCRIPTIONS { \
{ IFM_AUTO, "autoselect" }, \
{ IFM_MANUAL, "manual" }, \
{ IFM_NONE, "none" }, \
{ 0, NULL }, \
}
#define IFM_SUBTYPE_SHARED_ALIASES { \
{ IFM_AUTO, "auto" }, \
{ 0, NULL }, \
}
#define IFM_SHARED_OPTION_DESCRIPTIONS { \
{ IFM_FDX, "full-duplex" }, \
{ IFM_HDX, "half-duplex" }, \
{ IFM_FLAG0, "flag0" }, \
{ IFM_FLAG1, "flag1" }, \
{ IFM_FLAG2, "flag2" }, \
{ IFM_LOOP, "hw-loopback" }, \
{ 0, NULL }, \
}
/*
* Baudrate descriptions for the various media types.
*/
struct ifmedia_baudrate {
int ifmb_word; /* media word */
uint64_t ifmb_baudrate; /* corresponding baudrate */
};
#define IFM_BAUDRATE_DESCRIPTIONS { \
{ IFM_ETHER | IFM_10_T, IF_Mbps(10) }, \
{ IFM_ETHER | IFM_10_2, IF_Mbps(10) }, \
{ IFM_ETHER | IFM_10_5, IF_Mbps(10) }, \
{ IFM_ETHER | IFM_100_TX, IF_Mbps(100) }, \
{ IFM_ETHER | IFM_100_FX, IF_Mbps(100) }, \
{ IFM_ETHER | IFM_100_T4, IF_Mbps(100) }, \
{ IFM_ETHER | IFM_100_VG, IF_Mbps(100) }, \
{ IFM_ETHER | IFM_100_T2, IF_Mbps(100) }, \
{ IFM_ETHER | IFM_1000_SX, IF_Mbps(1000) }, \
{ IFM_ETHER | IFM_10_STP, IF_Mbps(10) }, \
{ IFM_ETHER | IFM_10_FL, IF_Mbps(10) }, \
{ IFM_ETHER | IFM_1000_LX, IF_Mbps(1000) }, \
{ IFM_ETHER | IFM_1000_CX, IF_Mbps(1000) }, \
{ IFM_ETHER | IFM_1000_T, IF_Mbps(1000) }, \
{ IFM_ETHER | IFM_HPNA_1, IF_Mbps(1) }, \
{ IFM_ETHER | IFM_10G_LR, IF_Gbps(10ULL) }, \
{ IFM_ETHER | IFM_10G_SR, IF_Gbps(10ULL) }, \
{ IFM_ETHER | IFM_10G_CX4, IF_Gbps(10ULL) }, \
\
{ IFM_TOKEN | IFM_TOK_STP4, IF_Mbps(4) }, \
{ IFM_TOKEN | IFM_TOK_STP16, IF_Mbps(16) }, \
{ IFM_TOKEN | IFM_TOK_UTP4, IF_Mbps(4) }, \
{ IFM_TOKEN | IFM_TOK_UTP16, IF_Mbps(16) }, \
\
{ IFM_FDDI | IFM_FDDI_SMF, IF_Mbps(100) }, \
{ IFM_FDDI | IFM_FDDI_MMF, IF_Mbps(100) }, \
{ IFM_FDDI | IFM_FDDI_UTP, IF_Mbps(100) }, \
\
{ IFM_IEEE80211 | IFM_IEEE80211_FH1, IF_Mbps(1) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_FH2, IF_Mbps(2) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_DS2, IF_Mbps(2) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_DS5, IF_Kbps(5500) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_DS11, IF_Mbps(11) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_DS1, IF_Mbps(1) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_DS22, IF_Mbps(22) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_OFDM6, IF_Mbps(6) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_OFDM9, IF_Mbps(9) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_OFDM12, IF_Mbps(12) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_OFDM18, IF_Mbps(18) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_OFDM24, IF_Mbps(24) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_OFDM36, IF_Mbps(36) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_OFDM48, IF_Mbps(48) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_OFDM54, IF_Mbps(54) }, \
{ IFM_IEEE80211 | IFM_IEEE80211_OFDM72, IF_Mbps(72) }, \
\
{ 0, 0 }, \
}
/*
* Status descriptions for the various media types.
*/
struct ifmedia_status_description {
int ifms_type;
int ifms_valid;
int ifms_bit;
const char *ifms_string[2];
};
#define IFM_STATUS_DESC(ifms, bit) \
(ifms)->ifms_string[((ifms)->ifms_bit & (bit)) ? 1 : 0]
#define IFM_STATUS_DESCRIPTIONS { \
{ IFM_ETHER, IFM_AVALID, IFM_ACTIVE, \
{ "no carrier", "active" } }, \
{ IFM_FDDI, IFM_AVALID, IFM_ACTIVE, \
{ "no ring", "inserted" } }, \
{ IFM_TOKEN, IFM_AVALID, IFM_ACTIVE, \
{ "no ring", "inserted" } }, \
{ IFM_IEEE80211, IFM_AVALID, IFM_ACTIVE, \
{ "no network", "active" } }, \
{ IFM_ATM, IFM_AVALID, IFM_ACTIVE, \
{ "no network", "active" } }, \
{ IFM_CARP, IFM_AVALID, IFM_ACTIVE, \
{ "backup", "master" } }, \
{ 0, 0, 0, \
{ NULL, NULL } } \
}
#endif /* _NET_IF_MEDIA_H_ */
@@ -0,0 +1,673 @@
/*-
* Copyright (c) 1982, 1986, 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* From: @(#)if.h 8.1 (Berkeley) 6/10/93
* $FreeBSD: src/sys/net/if_var.h,v 1.98.2.6 2006/10/06 20:26:05 andre Exp $
*/
#ifndef _NET_IF_VAR_H_
#define _NET_IF_VAR_H_
/*
* Structures defining a network interface, providing a packet
* transport mechanism (ala level 0 of the PUP protocols).
*
* Each interface accepts output datagrams of a specified maximum
* length, and provides higher level routines with input datagrams
* received from its medium.
*
* Output occurs when the routine if_output is called, with three parameters:
* (*ifp->if_output)(ifp, m, dst, rt)
* Here m is the mbuf chain to be sent and dst is the destination address.
* The output routine encapsulates the supplied datagram if necessary,
* and then transmits it on its medium.
*
* On input, each interface unwraps the data received by it, and either
* places it on the input queue of an internetwork datagram routine
* and posts the associated software interrupt, or passes the datagram to a raw
* packet input routine.
*
* Routines exist for locating interfaces by their addresses
* or for locating an interface on a certain network, as well as more general
* routing and gateway routines maintaining information used to locate
* interfaces. These routines live in the files if.c and route.c
*/
#ifdef __STDC__
/*
* Forward structure declarations for function prototypes [sic].
*/
struct mbuf;
struct thread;
struct rtentry;
struct rt_addrinfo;
struct socket;
struct ether_header;
struct carp_if;
#endif
#include <sys/queue.h> /* get TAILQ macros */
#ifdef _KERNEL
#include <sys/mbuf.h>
#include <sys/eventhandler.h>
#endif /* _KERNEL */
#include <sys/lock.h> /* XXX */
#include <sys/mutex.h> /* XXX */
#include <sys/event.h> /* XXX */
#include <sys/_task.h>
#define IF_DUNIT_NONE -1
#include <altq/if_altq.h>
TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */
TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */
TAILQ_HEAD(ifprefixhead, ifprefix);
TAILQ_HEAD(ifmultihead, ifmultiaddr);
/*
* Structure defining a queue for a network interface.
*/
struct ifqueue {
struct mbuf *ifq_head;
struct mbuf *ifq_tail;
int ifq_len;
int ifq_maxlen;
int ifq_drops;
struct mtx ifq_mtx;
};
/*
* Structure defining a network interface.
*
* (Would like to call this struct ``if'', but C isn't PL/1.)
*/
struct ifnet {
void *if_softc; /* pointer to driver state */
void *if_l2com; /* pointer to protocol bits */
TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */
char if_xname[IFNAMSIZ]; /* external name (name + unit) */
const char *if_dname; /* driver name */
int if_dunit; /* unit or IF_DUNIT_NONE */
struct ifaddrhead if_addrhead; /* linked list of addresses per if */
/*
* if_addrhead is the list of all addresses associated to
* an interface.
* Some code in the kernel assumes that first element
* of the list has type AF_LINK, and contains sockaddr_dl
* addresses which store the link-level address and the name
* of the interface.
* However, access to the AF_LINK address through this
* field is deprecated. Use ifaddr_byindex() instead.
*/
struct knlist if_klist; /* events attached to this if */
int if_pcount; /* number of promiscuous listeners */
struct carp_if *if_carp; /* carp interface structure */
struct bpf_if *if_bpf; /* packet filter structure */
u_short if_index; /* numeric abbreviation for this if */
short if_timer; /* time 'til if_watchdog called */
u_short if_nvlans; /* number of active vlans */
int if_flags; /* up/down, broadcast, etc. */
int if_capabilities; /* interface capabilities */
int if_capenable; /* enabled features */
void *if_linkmib; /* link-type-specific MIB data */
size_t if_linkmiblen; /* length of above data */
struct if_data if_data;
struct ifmultihead if_multiaddrs; /* multicast addresses configured */
int if_amcount; /* number of all-multicast requests */
/* procedure handles */
int (*if_output) /* output routine (enqueue) */
(struct ifnet *, struct mbuf *, struct sockaddr *,
struct rtentry *);
void (*if_input) /* input routine (from h/w driver) */
(struct ifnet *, struct mbuf *);
void (*if_start) /* initiate output routine */
(struct ifnet *);
int (*if_ioctl) /* ioctl routine */
(struct ifnet *, u_long, caddr_t);
void (*if_watchdog) /* timer routine */
(struct ifnet *);
void (*if_init) /* Init routine */
(void *);
int (*if_resolvemulti) /* validate/resolve multicast */
(struct ifnet *, struct sockaddr **, struct sockaddr *);
void *if_spare1; /* spare pointer 1 */
void *if_spare2; /* spare pointer 2 */
void *if_spare3; /* spare pointer 3 */
int if_drv_flags; /* driver-managed status flags */
u_int if_spare_flags2; /* spare flags 2 */
struct ifaltq if_snd; /* output queue (includes altq) */
const u_int8_t *if_broadcastaddr; /* linklevel broadcast bytestring */
void *if_bridge; /* bridge glue */
struct lltable *lltables; /* list of L3-L2 resolution tables */
struct label *if_label; /* interface MAC label */
/* these are only used by IPv6 */
struct ifprefixhead if_prefixhead; /* list of prefixes per if */
void *if_afdata[AF_MAX];
int if_afdata_initialized;
struct mtx if_afdata_mtx;
struct task if_starttask; /* task for IFF_NEEDSGIANT */
struct task if_linktask; /* task for link change events */
struct mtx if_addr_mtx; /* mutex to protect address lists */
};
typedef void if_init_f_t(void *);
/*
* XXX These aliases are terribly dangerous because they could apply
* to anything.
*/
#define if_mtu if_data.ifi_mtu
#define if_type if_data.ifi_type
#define if_physical if_data.ifi_physical
#define if_addrlen if_data.ifi_addrlen
#define if_hdrlen if_data.ifi_hdrlen
#define if_metric if_data.ifi_metric
#define if_link_state if_data.ifi_link_state
#define if_baudrate if_data.ifi_baudrate
#define if_hwassist if_data.ifi_hwassist
#define if_ipackets if_data.ifi_ipackets
#define if_ierrors if_data.ifi_ierrors
#define if_opackets if_data.ifi_opackets
#define if_oerrors if_data.ifi_oerrors
#define if_collisions if_data.ifi_collisions
#define if_ibytes if_data.ifi_ibytes
#define if_obytes if_data.ifi_obytes
#define if_imcasts if_data.ifi_imcasts
#define if_omcasts if_data.ifi_omcasts
#define if_iqdrops if_data.ifi_iqdrops
#define if_noproto if_data.ifi_noproto
#define if_lastchange if_data.ifi_lastchange
#define if_recvquota if_data.ifi_recvquota
#define if_xmitquota if_data.ifi_xmitquota
#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)NULL)
/* for compatibility with other BSDs */
#define if_addrlist if_addrhead
#define if_list if_link
/*
* Locks for address lists on the network interface.
*/
#define IF_ADDR_LOCK_INIT(if) mtx_init(&(if)->if_addr_mtx, \
"if_addr_mtx", NULL, MTX_DEF)
#define IF_ADDR_LOCK_DESTROY(if) mtx_destroy(&(if)->if_addr_mtx)
#define IF_ADDR_LOCK(if) mtx_lock(&(if)->if_addr_mtx)
#define IF_ADDR_UNLOCK(if) mtx_unlock(&(if)->if_addr_mtx)
#define IF_ADDR_LOCK_ASSERT(if) mtx_assert(&(if)->if_addr_mtx, MA_OWNED)
/*
* Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
* are queues of messages stored on ifqueue structures
* (defined above). Entries are added to and deleted from these structures
* by these macros, which should be called with ipl raised to splimp().
*/
#define IF_LOCK(ifq) mtx_lock(&(ifq)->ifq_mtx)
#define IF_UNLOCK(ifq) mtx_unlock(&(ifq)->ifq_mtx)
#define IF_LOCK_ASSERT(ifq) mtx_assert(&(ifq)->ifq_mtx, MA_OWNED)
#define _IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
#define _IF_DROP(ifq) ((ifq)->ifq_drops++)
#define _IF_QLEN(ifq) ((ifq)->ifq_len)
#define _IF_ENQUEUE(ifq, m) do { \
(m)->m_nextpkt = NULL; \
if ((ifq)->ifq_tail == NULL) \
(ifq)->ifq_head = m; \
else \
(ifq)->ifq_tail->m_nextpkt = m; \
(ifq)->ifq_tail = m; \
(ifq)->ifq_len++; \
} while (0)
#define IF_ENQUEUE(ifq, m) do { \
IF_LOCK(ifq); \
_IF_ENQUEUE(ifq, m); \
IF_UNLOCK(ifq); \
} while (0)
#define _IF_PREPEND(ifq, m) do { \
(m)->m_nextpkt = (ifq)->ifq_head; \
if ((ifq)->ifq_tail == NULL) \
(ifq)->ifq_tail = (m); \
(ifq)->ifq_head = (m); \
(ifq)->ifq_len++; \
} while (0)
#define IF_PREPEND(ifq, m) do { \
IF_LOCK(ifq); \
_IF_PREPEND(ifq, m); \
IF_UNLOCK(ifq); \
} while (0)
#define _IF_DEQUEUE(ifq, m) do { \
(m) = (ifq)->ifq_head; \
if (m) { \
if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \
(ifq)->ifq_tail = NULL; \
(m)->m_nextpkt = NULL; \
(ifq)->ifq_len--; \
} \
} while (0)
#define IF_DEQUEUE(ifq, m) do { \
IF_LOCK(ifq); \
_IF_DEQUEUE(ifq, m); \
IF_UNLOCK(ifq); \
} while (0)
#define _IF_POLL(ifq, m) ((m) = (ifq)->ifq_head)
#define IF_POLL(ifq, m) _IF_POLL(ifq, m)
#define _IF_DRAIN(ifq) do { \
struct mbuf *m; \
for (;;) { \
_IF_DEQUEUE(ifq, m); \
if (m == NULL) \
break; \
m_freem(m); \
} \
} while (0)
#define IF_DRAIN(ifq) do { \
IF_LOCK(ifq); \
_IF_DRAIN(ifq); \
IF_UNLOCK(ifq); \
} while(0)
#ifdef _KERNEL
/* interface address change event */
typedef void (*ifaddr_event_handler_t)(void *, struct ifnet *);
EVENTHANDLER_DECLARE(ifaddr_event, ifaddr_event_handler_t);
/* new interface arrival event */
typedef void (*ifnet_arrival_event_handler_t)(void *, struct ifnet *);
EVENTHANDLER_DECLARE(ifnet_arrival_event, ifnet_arrival_event_handler_t);
/* interface departure event */
typedef void (*ifnet_departure_event_handler_t)(void *, struct ifnet *);
EVENTHANDLER_DECLARE(ifnet_departure_event, ifnet_departure_event_handler_t);
#define IF_AFDATA_LOCK_INIT(ifp) \
mtx_init(&(ifp)->if_afdata_mtx, "if_afdata", NULL, MTX_DEF)
#define IF_AFDATA_LOCK(ifp) mtx_lock(&(ifp)->if_afdata_mtx)
#define IF_AFDATA_TRYLOCK(ifp) mtx_trylock(&(ifp)->if_afdata_mtx)
#define IF_AFDATA_UNLOCK(ifp) mtx_unlock(&(ifp)->if_afdata_mtx)
#define IF_AFDATA_DESTROY(ifp) mtx_destroy(&(ifp)->if_afdata_mtx)
#define IFF_LOCKGIANT(ifp) do { \
if ((ifp)->if_flags & IFF_NEEDSGIANT) \
mtx_lock(&Giant); \
} while (0)
#define IFF_UNLOCKGIANT(ifp) do { \
if ((ifp)->if_flags & IFF_NEEDSGIANT) \
mtx_unlock(&Giant); \
} while (0)
int if_handoff(struct ifqueue *ifq, struct mbuf *m, struct ifnet *ifp,
int adjust);
#define IF_HANDOFF(ifq, m, ifp) \
if_handoff((struct ifqueue *)ifq, m, ifp, 0)
#define IF_HANDOFF_ADJ(ifq, m, ifp, adj) \
if_handoff((struct ifqueue *)ifq, m, ifp, adj)
void if_start(struct ifnet *);
#define IFQ_ENQUEUE(ifq, m, err) \
do { \
IF_LOCK(ifq); \
if (ALTQ_IS_ENABLED(ifq)) \
ALTQ_ENQUEUE(ifq, m, NULL, err); \
else { \
if (_IF_QFULL(ifq)) { \
m_freem(m); \
(err) = ENOBUFS; \
} else { \
_IF_ENQUEUE(ifq, m); \
(err) = 0; \
} \
} \
if (err) \
(ifq)->ifq_drops++; \
IF_UNLOCK(ifq); \
} while (0)
#define IFQ_DEQUEUE_NOLOCK(ifq, m) \
do { \
if (TBR_IS_ENABLED(ifq)) \
(m) = tbr_dequeue_ptr(ifq, ALTDQ_REMOVE); \
else if (ALTQ_IS_ENABLED(ifq)) \
ALTQ_DEQUEUE(ifq, m); \
else \
_IF_DEQUEUE(ifq, m); \
} while (0)
#define IFQ_DEQUEUE(ifq, m) \
do { \
IF_LOCK(ifq); \
IFQ_DEQUEUE_NOLOCK(ifq, m); \
IF_UNLOCK(ifq); \
} while (0)
#define IFQ_POLL_NOLOCK(ifq, m) \
do { \
if (TBR_IS_ENABLED(ifq)) \
(m) = tbr_dequeue_ptr(ifq, ALTDQ_POLL); \
else if (ALTQ_IS_ENABLED(ifq)) \
ALTQ_POLL(ifq, m); \
else \
_IF_POLL(ifq, m); \
} while (0)
#define IFQ_POLL(ifq, m) \
do { \
IF_LOCK(ifq); \
IFQ_POLL_NOLOCK(ifq, m); \
IF_UNLOCK(ifq); \
} while (0)
#define IFQ_PURGE_NOLOCK(ifq) \
do { \
if (ALTQ_IS_ENABLED(ifq)) { \
ALTQ_PURGE(ifq); \
} else \
_IF_DRAIN(ifq); \
} while (0)
#define IFQ_PURGE(ifq) \
do { \
IF_LOCK(ifq); \
IFQ_PURGE_NOLOCK(ifq); \
IF_UNLOCK(ifq); \
} while (0)
#define IFQ_SET_READY(ifq) \
do { ((ifq)->altq_flags |= ALTQF_READY); } while (0)
#define IFQ_LOCK(ifq) IF_LOCK(ifq)
#define IFQ_UNLOCK(ifq) IF_UNLOCK(ifq)
#define IFQ_LOCK_ASSERT(ifq) IF_LOCK_ASSERT(ifq)
#define IFQ_IS_EMPTY(ifq) ((ifq)->ifq_len == 0)
#define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++)
#define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len)
#define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++)
#define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len))
/*
* The IFF_DRV_OACTIVE test should really occur in the device driver, not in
* the handoff logic, as that flag is locked by the device driver.
*/
#define IFQ_HANDOFF_ADJ(ifp, m, adj, err) \
do { \
int len; \
short mflags; \
\
len = (m)->m_pkthdr.len; \
mflags = (m)->m_flags; \
IFQ_ENQUEUE(&(ifp)->if_snd, m, err); \
if ((err) == 0) { \
(ifp)->if_obytes += len + (adj); \
if (mflags & M_MCAST) \
(ifp)->if_omcasts++; \
if (((ifp)->if_drv_flags & IFF_DRV_OACTIVE) == 0) \
if_start(ifp); \
} \
} while (0)
#define IFQ_HANDOFF(ifp, m, err) \
IFQ_HANDOFF_ADJ(ifp, m, 0, err)
#define IFQ_DRV_DEQUEUE(ifq, m) \
do { \
(m) = (ifq)->ifq_drv_head; \
if (m) { \
if (((ifq)->ifq_drv_head = (m)->m_nextpkt) == NULL) \
(ifq)->ifq_drv_tail = NULL; \
(m)->m_nextpkt = NULL; \
(ifq)->ifq_drv_len--; \
} else { \
IFQ_LOCK(ifq); \
IFQ_DEQUEUE_NOLOCK(ifq, m); \
while ((ifq)->ifq_drv_len < (ifq)->ifq_drv_maxlen) { \
struct mbuf *m0; \
IFQ_DEQUEUE_NOLOCK(ifq, m0); \
if (m0 == NULL) \
break; \
m0->m_nextpkt = NULL; \
if ((ifq)->ifq_drv_tail == NULL) \
(ifq)->ifq_drv_head = m0; \
else \
(ifq)->ifq_drv_tail->m_nextpkt = m0; \
(ifq)->ifq_drv_tail = m0; \
(ifq)->ifq_drv_len++; \
} \
IFQ_UNLOCK(ifq); \
} \
} while (0)
#define IFQ_DRV_PREPEND(ifq, m) \
do { \
(m)->m_nextpkt = (ifq)->ifq_drv_head; \
if ((ifq)->ifq_drv_tail == NULL) \
(ifq)->ifq_drv_tail = (m); \
(ifq)->ifq_drv_head = (m); \
(ifq)->ifq_drv_len++; \
} while (0)
#define IFQ_DRV_IS_EMPTY(ifq) \
(((ifq)->ifq_drv_len == 0) && ((ifq)->ifq_len == 0))
#define IFQ_DRV_PURGE(ifq) \
do { \
struct mbuf *m, *n = (ifq)->ifq_drv_head; \
while((m = n) != NULL) { \
n = m->m_nextpkt; \
m_freem(m); \
} \
(ifq)->ifq_drv_head = (ifq)->ifq_drv_tail = NULL; \
(ifq)->ifq_drv_len = 0; \
IFQ_PURGE(ifq); \
} while (0)
/*
* 72 was chosen below because it is the size of a TCP/IP
* header (40) + the minimum mss (32).
*/
#define IF_MINMTU 72
#define IF_MAXMTU 65535
#endif /* _KERNEL */
/*
* The ifaddr structure contains information about one address
* of an interface. They are maintained by the different address families,
* are allocated and attached when an address is set, and are linked
* together so all addresses for an interface can be located.
*
* NOTE: a 'struct ifaddr' is always at the beginning of a larger
* chunk of malloc'ed memory, where we store the three addresses
* (ifa_addr, ifa_dstaddr and ifa_netmask) referenced here.
*/
struct ifaddr {
struct sockaddr *ifa_addr; /* address of interface */
struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
struct sockaddr *ifa_netmask; /* used to determine subnet */
struct if_data if_data; /* not all members are meaningful */
struct ifnet *ifa_ifp; /* back-pointer to interface */
TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */
void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
(int, struct rtentry *, struct rt_addrinfo *);
u_short ifa_flags; /* mostly rt_flags for cloning */
u_int ifa_refcnt; /* references to this structure */
int ifa_metric; /* cost of going out this interface */
int (*ifa_claim_addr) /* check if an addr goes to this if */
(struct ifaddr *, struct sockaddr *);
struct mtx ifa_mtx;
};
#define IFA_ROUTE RTF_UP /* route installed */
/* for compatibility with other BSDs */
#define ifa_list ifa_link
#define IFA_LOCK_INIT(ifa) \
mtx_init(&(ifa)->ifa_mtx, "ifaddr", NULL, MTX_DEF)
#define IFA_LOCK(ifa) mtx_lock(&(ifa)->ifa_mtx)
#define IFA_UNLOCK(ifa) mtx_unlock(&(ifa)->ifa_mtx)
#define IFA_DESTROY(ifa) mtx_destroy(&(ifa)->ifa_mtx)
/*
* The prefix structure contains information about one prefix
* of an interface. They are maintained by the different address families,
* are allocated and attached when a prefix or an address is set,
* and are linked together so all prefixes for an interface can be located.
*/
struct ifprefix {
struct sockaddr *ifpr_prefix; /* prefix of interface */
struct ifnet *ifpr_ifp; /* back-pointer to interface */
TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */
u_char ifpr_plen; /* prefix length in bits */
u_char ifpr_type; /* protocol dependent prefix type */
};
/*
* Multicast address structure. This is analogous to the ifaddr
* structure except that it keeps track of multicast addresses.
* Also, the reference count here is a count of requests for this
* address, not a count of pointers to this structure.
*/
struct ifmultiaddr {
TAILQ_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
struct sockaddr *ifma_addr; /* address this membership is for */
struct sockaddr *ifma_lladdr; /* link-layer translation, if any */
struct ifnet *ifma_ifp; /* back-pointer to interface */
u_int ifma_refcount; /* reference count */
void *ifma_protospec; /* protocol-specific state, if any */
};
#ifdef _KERNEL
#define IFAFREE(ifa) \
do { \
IFA_LOCK(ifa); \
KASSERT((ifa)->ifa_refcnt > 0, \
("ifa %p !(ifa_refcnt > 0)", ifa)); \
if (--(ifa)->ifa_refcnt == 0) { \
IFA_DESTROY(ifa); \
free(ifa, M_IFADDR); \
} else \
IFA_UNLOCK(ifa); \
} while (0)
#define IFAREF(ifa) \
do { \
IFA_LOCK(ifa); \
++(ifa)->ifa_refcnt; \
IFA_UNLOCK(ifa); \
} while (0)
extern struct mtx ifnet_lock;
#define IFNET_LOCK_INIT() \
mtx_init(&ifnet_lock, "ifnet", NULL, MTX_DEF | MTX_RECURSE)
#define IFNET_WLOCK() mtx_lock(&ifnet_lock)
#define IFNET_WUNLOCK() mtx_unlock(&ifnet_lock)
#define IFNET_RLOCK() IFNET_WLOCK()
#define IFNET_RUNLOCK() IFNET_WUNLOCK()
struct ifindex_entry {
struct ifnet *ife_ifnet;
struct ifaddr *ife_ifnet_addr;
struct cdev *ife_dev;
};
#define ifnet_byindex(idx) ifindex_table[(idx)].ife_ifnet
/*
* Given the index, ifaddr_byindex() returns the one and only
* link-level ifaddr for the interface. You are not supposed to use
* it to traverse the list of addresses associated to the interface.
*/
#define ifaddr_byindex(idx) ifindex_table[(idx)].ife_ifnet_addr
#define ifdev_byindex(idx) ifindex_table[(idx)].ife_dev
extern struct ifnethead ifnet;
extern struct ifindex_entry *ifindex_table;
extern int ifqmaxlen;
extern struct ifnet *loif; /* first loopback interface */
extern int if_index;
int if_addmulti(struct ifnet *, struct sockaddr *, struct ifmultiaddr **);
int if_allmulti(struct ifnet *, int);
struct ifnet* if_alloc(u_char);
void if_attach(struct ifnet *);
int if_delmulti(struct ifnet *, struct sockaddr *);
void if_detach(struct ifnet *);
void if_purgeaddrs(struct ifnet *);
void if_down(struct ifnet *);
void if_free(struct ifnet *);
void if_free_type(struct ifnet *, u_char);
void if_initname(struct ifnet *, const char *, int);
void if_link_state_change(struct ifnet *, int);
int if_printf(struct ifnet *, const char *, ...) __printflike(2, 3);
int if_setlladdr(struct ifnet *, const u_char *, int);
void if_up(struct ifnet *);
/*void ifinit(void);*/ /* declared in systm.h for main() */
int ifioctl(struct socket *, u_long, caddr_t, struct thread *);
int ifpromisc(struct ifnet *, int);
struct ifnet *ifunit(const char *);
struct ifaddr *ifa_ifwithaddr(struct sockaddr *);
struct ifaddr *ifa_ifwithbroadaddr(struct sockaddr *);
struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
struct ifaddr *ifa_ifwithnet(struct sockaddr *);
struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, struct sockaddr *);
struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);
int if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen);
typedef void *if_com_alloc_t(u_char type, struct ifnet *ifp);
typedef void if_com_free_t(void *com, u_char type);
void if_register_com_alloc(u_char type, if_com_alloc_t *a, if_com_free_t *f);
void if_deregister_com_alloc(u_char type);
#define IF_LLADDR(ifp) \
LLADDR((struct sockaddr_dl *) ifaddr_byindex((ifp)->if_index)->ifa_addr)
#ifdef DEVICE_POLLING
enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS };
typedef void poll_handler_t(struct ifnet *ifp, enum poll_cmd cmd, int count);
int ether_poll_register(poll_handler_t *h, struct ifnet *ifp);
int ether_poll_deregister(struct ifnet *ifp);
#endif /* DEVICE_POLLING */
#endif /* _KERNEL */
#endif /* !_NET_IF_VAR_H_ */
@@ -0,0 +1,146 @@
/*-
* Copyright 1998 Massachusetts Institute of Technology
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that both the above copyright notice and this
* permission notice appear in all copies, that both the above
* copyright notice and this permission notice appear in all
* supporting documentation, and that the name of M.I.T. not be used
* in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. M.I.T. makes
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
* ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
* SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/sys/net/if_vlan_var.h,v 1.21.2.2 2006/01/13 19:21:45 glebius Exp $
*/
#ifndef _NET_IF_VLAN_VAR_H_
#define _NET_IF_VLAN_VAR_H_ 1
struct ether_vlan_header {
u_char evl_dhost[ETHER_ADDR_LEN];
u_char evl_shost[ETHER_ADDR_LEN];
u_int16_t evl_encap_proto;
u_int16_t evl_tag;
u_int16_t evl_proto;
};
#define EVL_VLID_MASK 0x0FFF
#define EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK)
#define EVL_PRIOFTAG(tag) (((tag) >> 13) & 7)
/* sysctl(3) tags, for compatibility purposes */
#define VLANCTL_PROTO 1
#define VLANCTL_MAX 2
/*
* Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls.
*/
struct vlanreq {
char vlr_parent[IFNAMSIZ];
u_short vlr_tag;
};
#define SIOCSETVLAN SIOCSIFGENERIC
#define SIOCGETVLAN SIOCGIFGENERIC
#ifdef _KERNEL
/*
* Drivers that are capable of adding and removing the VLAN header
* in hardware indicate they support this by marking IFCAP_VLAN_HWTAGGING
* in if_capabilities. Drivers for hardware that is capable
* of handling larger MTU's that may include a software-appended
* VLAN header w/o lowering the normal MTU should mark IFCAP_VLAN_MTU
* in if_capabilities; this notifies the VLAN code it can leave the
* MTU on the vlan interface at the normal setting.
*/
/*
* Drivers that support hardware VLAN tagging pass a packet's tag
* up through the stack by appending a packet tag with this value.
* Output is handled likewise, the driver must locate the packet
* tag to extract the VLAN tag. The following macros are used to
* do this work. On input, do:
*
* VLAN_INPUT_TAG(ifp, m, tag,);
*
* to mark the packet m with the specified VLAN tag. The last
* parameter provides code to execute in case of an error. On
* output the driver should check mbuf to see if a VLAN tag is
* present and only then check for a tag; this is done with:
*
* struct m_tag *mtag;
* mtag = VLAN_OUTPUT_TAG(ifp, m);
* if (mtag != NULL) {
* ... = VLAN_TAG_VALUE(mtag);
* ... pass tag to hardware ...
* }
*
* Note that a driver must indicate it supports hardware VLAN
* tagging by marking IFCAP_VLAN_HWTAGGING in if_capabilities.
*/
#define MTAG_VLAN 1035328035
#define MTAG_VLAN_TAG 0 /* tag of VLAN interface */
/*
* This macro must expand to a lvalue so that it can be used
* to set a tag with a simple assignment.
*/
#define VLAN_TAG_VALUE(_mt) (*(u_int *)((_mt) + 1))
/*
* This macro is kept for API compatibility.
*/
#define VLAN_INPUT_TAG(_ifp, _m, _t, _errcase) do { \
struct m_tag *mtag; \
mtag = m_tag_alloc(MTAG_VLAN, MTAG_VLAN_TAG, \
sizeof (u_int), M_NOWAIT); \
if (mtag != NULL) { \
VLAN_TAG_VALUE(mtag) = (_t); \
m_tag_prepend((_m), mtag); \
(_m)->m_flags |= M_VLANTAG; \
} else { \
(_ifp)->if_ierrors++; \
m_freem(_m); \
_errcase; \
} \
} while (0)
/*
* This macro is equal to VLAN_INPUT_TAG() in HEAD.
*/
#define VLAN_INPUT_TAG_NEW(_ifp, _m, _t) do { \
struct m_tag *mtag; \
mtag = m_tag_alloc(MTAG_VLAN, MTAG_VLAN_TAG, \
sizeof (u_int), M_NOWAIT); \
if (mtag != NULL) { \
VLAN_TAG_VALUE(mtag) = (_t); \
m_tag_prepend((_m), mtag); \
(_m)->m_flags |= M_VLANTAG; \
} else { \
(_ifp)->if_ierrors++; \
m_freem(_m); \
_m = NULL; \
} \
} while (0)
#define VLAN_OUTPUT_TAG(_ifp, _m) \
((_m)->m_flags & M_VLANTAG ? \
m_tag_locate((_m), MTAG_VLAN, MTAG_VLAN_TAG, NULL) : NULL)
#endif /* _KERNEL */
#endif /* _NET_IF_VLAN_VAR_H_ */
@@ -0,0 +1,7 @@
#ifndef _FBSD_COMPAT_SYS__TASK_H_
#define _FBSD_COMPAT_SYS__TASK_H_
struct task {
};
#endif
@@ -0,0 +1,151 @@
#ifndef _FBSD_COMPAT_SYS_BUS_H_
#define _FBSD_COMPAT_SYS_BUS_H_
#include <arch/x86/arch_cpu.h>
#include <sys/systm.h>
// TODO per platform, these are x86
typedef uint32_t bus_addr_t;
typedef uint32_t bus_size_t;
typedef int bus_space_tag_t;
typedef unsigned int bus_space_handle_t;
#define I386_BUS_SPACE_IO 0
#define I386_BUS_SPACE_MEM 1
#define BUS_SPACE_MAXADDR_32BIT 0xffffffff
#define BUS_SPACE_MAXADDR 0xffffffff
#define BUS_SPACE_MAXSIZE_32BIT 0xffffffff
#define BUS_SPACE_MAXSIZE 0xffffffff
static inline uint8_t
bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
bus_size_t offset)
{
if (tag == I386_BUS_SPACE_IO)
return in8(handle + offset);
return *(volatile uint8_t *)(handle + offset);
}
static inline void
bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t handle,
bus_size_t offset, uint8_t value)
{
if (tag == I386_BUS_SPACE_IO)
out8(handle + offset, value);
else
*(volatile uint8_t *)(handle + offset) = value;
}
static inline uint16_t
bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
bus_size_t offset)
{
if (tag == I386_BUS_SPACE_IO)
return in16(handle + offset);
return *(volatile uint16_t *)(handle + offset);
}
static inline void
bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t handle,
bus_size_t offset, uint16_t value)
{
if (tag == I386_BUS_SPACE_IO)
out16(handle + offset, value);
else
*(volatile uint16_t *)(handle + offset) = value;
}
static inline uint32_t
bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
bus_size_t offset)
{
if (tag == I386_BUS_SPACE_IO)
return in32(handle + offset);
return *(volatile uint32_t *)(handle + offset);
}
static inline void
bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t handle,
bus_size_t offset, uint32_t value)
{
if (tag == I386_BUS_SPACE_IO)
out32(handle + offset, value);
else
*(volatile uint32_t *)(handle + offset) = value;
}
typedef struct device *device_t;
typedef struct devclass *devclass_t;
typedef int (*device_method_signature_t)(device_t dev);
struct device_method {
const char *name;
device_method_signature_t method;
};
typedef struct device_method device_method_t;
#define DEVMETHOD(name, func) { #name, (device_method_signature_t)func }
typedef struct {
const char *name;
device_method_t *methods;
size_t size;
} driver_t;
enum intr_type {
INTR_TYPE_NET = 4,
INTR_MPSAFE = 512,
};
int bus_generic_detach(device_t dev);
typedef void driver_intr_t(void *);
struct resource;
int resource_int_value(const char *name, int unit, const char *resname,
int *result);
struct resource *bus_alloc_resource(device_t dev, int type, int *rid,
unsigned long start, unsigned long end, unsigned long count, uint32 flags);
int bus_release_resource(device_t dev, int type, int rid, struct resource *r);
static inline struct resource *
bus_alloc_resource_any(device_t dev, int type, int *rid, uint32 flags)
{
return bus_alloc_resource(dev, type, rid, 0, ~0, 1, flags);
}
int bus_setup_intr(device_t dev, struct resource *r, int flags,
driver_intr_t handler, void *arg, void **cookiep);
int bus_teardown_intr(device_t dev, struct resource *r, void *cookie);
#define BUS_PROBE_DEFAULT -20
#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg)
const char *device_get_name(device_t dev);
const char *device_get_nameunit(device_t dev);
int device_get_unit(device_t dev);
void *device_get_softc(device_t dev);
int device_printf(device_t dev, const char *, ...) __printflike(2, 3);
void device_set_desc(device_t dev, const char *desc);
device_t device_add_child(device_t dev, const char *name, int unit);
int device_delete_child(device_t dev, device_t child);
#include <sys/bus_dma.h>
#endif
@@ -0,0 +1,298 @@
/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*-
* Copyright (c) 1996 Charles M. Hannum. All rights reserved.
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Christopher G. Demetriou
* for the NetBSD Project.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* $FreeBSD: src/sys/sys/bus_dma.h,v 1.29 2005/03/15 14:57:29 jmg Exp $ */
#ifndef _BUS_DMA_H_
#define _BUS_DMA_H_
/*
* Machine independent interface for mapping physical addresses to peripheral
* bus 'physical' addresses, and assisting with DMA operations.
*
* XXX This file is always included from <machine/bus_dma.h> and should not
* (yet) be included directly.
*/
/*
* Flags used in various bus DMA methods.
*/
#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */
#define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */
#define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */
#define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */
#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */
#define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */
#define BUS_DMA_BUS2 0x20
#define BUS_DMA_BUS3 0x40
#define BUS_DMA_BUS4 0x80
/*
* The following two flags are non-standard or specific to only certain
* architectures
*/
#define BUS_DMA_NOWRITE 0x100
#define BUS_DMA_NOCACHE 0x200
#define BUS_DMA_ISA 0x400 /* map memory for AXP ISA dma */
/* Forwards needed by prototypes below. */
struct mbuf;
struct uio;
/*
* Operations performed by bus_dmamap_sync().
*/
typedef int bus_dmasync_op_t;
#define BUS_DMASYNC_PREREAD 1
#define BUS_DMASYNC_POSTREAD 2
#define BUS_DMASYNC_PREWRITE 4
#define BUS_DMASYNC_POSTWRITE 8
/*
* bus_dma_tag_t
*
* A machine-dependent opaque type describing the characteristics
* of how to perform DMA mappings. This structure encapsultes
* information concerning address and alignment restrictions, number
* of S/G segments, amount of data per S/G segment, etc.
*/
typedef struct bus_dma_tag *bus_dma_tag_t;
/*
* bus_dmamap_t
*
* DMA mapping instance information.
*/
typedef struct bus_dmamap *bus_dmamap_t;
/*
* bus_dma_segment_t
*
* Describes a single contiguous DMA transaction. Values
* are suitable for programming into DMA registers.
*/
typedef struct bus_dma_segment {
bus_addr_t ds_addr; /* DMA address */
bus_size_t ds_len; /* length of transfer */
} bus_dma_segment_t;
/*
* A function that returns 1 if the address cannot be accessed by
* a device and 0 if it can be.
*/
typedef int bus_dma_filter_t(void *, bus_addr_t);
/*
* A function that performs driver-specific synchronization on behalf of
* busdma.
*/
typedef enum {
BUS_DMA_LOCK = 0x01,
BUS_DMA_UNLOCK = 0x02,
} bus_dma_lock_op_t;
typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t);
/*
* Generic helper function for manipulating mutexes.
*/
void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op);
/*
* Allocate a device specific dma_tag encapsulating the constraints of
* the parent tag in addition to other restrictions specified:
*
* alignment: Alignment for segments.
* boundary: Boundary that segments cannot cross.
* lowaddr: Low restricted address that cannot appear in a mapping.
* highaddr: High restricted address that cannot appear in a mapping.
* filtfunc: An optional function to further test if an address
* within the range of lowaddr and highaddr cannot appear
* in a mapping.
* filtfuncarg: An argument that will be passed to filtfunc in addition
* to the address to test.
* maxsize: Maximum mapping size supported by this tag.
* nsegments: Number of discontinuities allowed in maps.
* maxsegsz: Maximum size of a segment in the map.
* flags: Bus DMA flags.
* lockfunc: An optional function to handle driver-defined lock
* operations.
* lockfuncarg: An argument that will be passed to lockfunc in addition
* to the lock operation.
* dmat: A pointer to set to a valid dma tag should the return
* value of this function indicate success.
*/
/* XXX Should probably allow specification of alignment */
int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
bus_size_t boundary, bus_addr_t lowaddr,
bus_addr_t highaddr, bus_dma_filter_t *filtfunc,
void *filtfuncarg, bus_size_t maxsize, int nsegments,
bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc,
void *lockfuncarg, bus_dma_tag_t *dmat);
int bus_dma_tag_destroy(bus_dma_tag_t dmat);
/*
* A function that processes a successfully loaded dma map or an error
* from a delayed load map.
*/
typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
/*
* Like bus_dmamap_callback but includes map size in bytes. This is
* defined as a separate interface to maintain compatibility for users
* of bus_dmamap_callback_t--at some point these interfaces should be merged.
*/
typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int);
/*
* XXX sparc64 uses the same interface, but a much different implementation.
* <machine/bus_dma.h> for the sparc64 arch contains the equivalent
* declarations.
*/
#if !defined(__sparc64__)
/*
* Allocate a handle for mapping from kva/uva/physical
* address space into bus device space.
*/
int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp);
/*
* Destroy a handle for mapping from kva/uva/physical
* address space into bus device space.
*/
int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
/*
* Allocate a piece of memory that can be efficiently mapped into
* bus device space based on the constraints listed in the dma tag.
* A dmamap to for use with dmamap_load is also allocated.
*/
int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp);
/*
* Free a piece of memory and its allocated dmamap, that was allocated
* via bus_dmamem_alloc.
*/
void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
/*
* Map the buffer buf into bus space using the dmamap map.
*/
int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
bus_size_t buflen, bus_dmamap_callback_t *callback,
void *callback_arg, int flags);
/*
* Like bus_dmamap_load but for mbufs. Note the use of the
* bus_dmamap_callback2_t interface.
*/
int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map,
struct mbuf *mbuf,
bus_dmamap_callback2_t *callback, void *callback_arg,
int flags);
int bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map,
struct mbuf *mbuf, bus_dma_segment_t *segs,
int *nsegs, int flags);
/*
* Like bus_dmamap_load but for uios. Note the use of the
* bus_dmamap_callback2_t interface.
*/
int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map,
struct uio *ui,
bus_dmamap_callback2_t *callback, void *callback_arg,
int flags);
/*
* Perform a synchronization operation on the given map.
*/
void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t);
#define bus_dmamap_sync(dmat, dmamap, op) \
do { \
if ((dmamap) != NULL) \
_bus_dmamap_sync(dmat, dmamap, op); \
} while (0)
/*
* Release the mapping held by map.
*/
void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map);
#define bus_dmamap_unload(dmat, dmamap) \
do { \
if ((dmamap) != NULL) \
_bus_dmamap_unload(dmat, dmamap); \
} while (0)
#endif /* __sparc64__ */
#endif /* _BUS_DMA_H_ */
@@ -0,0 +1,90 @@
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)callout.h 8.2 (Berkeley) 1/21/94
* $FreeBSD: src/sys/sys/callout.h,v 1.28.2.1 2005/09/12 13:43:34 glebius Exp $
*/
#ifndef _SYS_CALLOUT_H_
#define _SYS_CALLOUT_H_
#include <sys/queue.h>
struct mtx;
SLIST_HEAD(callout_list, callout);
TAILQ_HEAD(callout_tailq, callout);
struct callout {
union {
SLIST_ENTRY(callout) sle;
TAILQ_ENTRY(callout) tqe;
} c_links;
int c_time; /* ticks to the event */
void *c_arg; /* function argument */
void (*c_func)(void *); /* function to call */
struct mtx *c_mtx; /* mutex to lock */
int c_flags; /* state of this entry */
};
#define CALLOUT_LOCAL_ALLOC 0x0001 /* was allocated from callfree */
#define CALLOUT_ACTIVE 0x0002 /* callout is currently active */
#define CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */
#define CALLOUT_MPSAFE 0x0008 /* callout handler is mp safe */
#define CALLOUT_RETURNUNLOCKED 0x0010 /* handler returns with mtx unlocked */
struct callout_handle {
struct callout *callout;
};
#ifdef _KERNEL
extern struct callout_list callfree;
extern struct callout *callout;
extern int ncallout;
extern struct callout_tailq *callwheel;
extern int callwheelsize, callwheelbits, callwheelmask, softticks;
extern struct mtx callout_lock;
#define callout_active(c) ((c)->c_flags & CALLOUT_ACTIVE)
#define callout_deactivate(c) ((c)->c_flags &= ~CALLOUT_ACTIVE)
#define callout_drain(c) _callout_stop_safe(c, 1)
void callout_init(struct callout *, int);
void callout_init_mtx(struct callout *, struct mtx *, int);
#define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING)
int callout_reset(struct callout *, int, void (*)(void *), void *);
#define callout_stop(c) _callout_stop_safe(c, 0)
int _callout_stop_safe(struct callout *, int);
#endif
#endif /* _SYS_CALLOUT_H_ */
@@ -0,0 +1,6 @@
#ifndef _FBSD_COMPAT_SYS_CDEFS_H_
#define _FBSD_COMPAT_SYS_CDEFS_H_
#define __FBSDID(str) const char __fbsdid[] = str
#endif
@@ -0,0 +1,199 @@
/*-
* Copyright (c) 2002 Thomas Moestl <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/sys/sys/endian.h,v 1.6 2003/10/15 20:05:57 obrien Exp $
*/
#ifndef _FBSD_COMPAT_SYS_ENDIAN_H_
#define _FBSD_COMPAT_SYS_ENDIAN_H_
#include <stdint.h>
#include <posix/endian.h>
#include <support/ByteOrder.h>
#include <machine/endian.h>
#define _BYTE_ORDER BYTE_ORDER
#define _LITTLE_ENDIAN LITTLE_ENDIAN
#define _BIG_ENDIAN BIG_ENDIAN
#define __bswap16(x) __swap_int16(x)
#define __bswap32(x) __swap_int32(x)
#define __bswap64(x) __swap_int64(x)
/*
* General byte order swapping functions.
*/
#define bswap16(x) __bswap16(x)
#define bswap32(x) __bswap32(x)
#define bswap64(x) __bswap64(x)
/*
* Host to big endian, host to little endian, big endian to host, and little
* endian to host byte order functions as detailed in byteorder(9).
*/
#if _YTE_ORDER == _LITTLE_ENDIAN
#define htobe16(x) bswap16((x))
#define htobe32(x) bswap32((x))
#define htobe64(x) bswap64((x))
#define htole16(x) ((uint16_t)(x))
#define htole32(x) ((uint32_t)(x))
#define htole64(x) ((uint64_t)(x))
#define be16toh(x) bswap16((x))
#define be32toh(x) bswap32((x))
#define be64toh(x) bswap64((x))
#define le16toh(x) ((uint16_t)(x))
#define le32toh(x) ((uint32_t)(x))
#define le64toh(x) ((uint64_t)(x))
#else /* _BYTE_ORDER != _LITTLE_ENDIAN */
#define htobe16(x) ((uint16_t)(x))
#define htobe32(x) ((uint32_t)(x))
#define htobe64(x) ((uint64_t)(x))
#define htole16(x) bswap16((x))
#define htole32(x) bswap32((x))
#define htole64(x) bswap64((x))
#define be16toh(x) ((uint16_t)(x))
#define be32toh(x) ((uint32_t)(x))
#define be64toh(x) ((uint64_t)(x))
#define le16toh(x) bswap16((x))
#define le32toh(x) bswap32((x))
#define le64toh(x) bswap64((x))
#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
static __inline uint16_t
be16dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
return ((p[0] << 8) | p[1]);
}
static __inline uint32_t
be32dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
}
static __inline uint64_t
be64dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
}
static __inline uint16_t
le16dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
return ((p[1] << 8) | p[0]);
}
static __inline uint32_t
le32dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
}
static __inline uint64_t
le64dec(const void *pp)
{
unsigned char const *p = (unsigned char const *)pp;
return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p));
}
static __inline void
be16enc(void *pp, uint16_t u)
{
unsigned char *p = (unsigned char *)pp;
p[0] = (u >> 8) & 0xff;
p[1] = u & 0xff;
}
static __inline void
be32enc(void *pp, uint32_t u)
{
unsigned char *p = (unsigned char *)pp;
p[0] = (u >> 24) & 0xff;
p[1] = (u >> 16) & 0xff;
p[2] = (u >> 8) & 0xff;
p[3] = u & 0xff;
}
static __inline void
be64enc(void *pp, uint64_t u)
{
unsigned char *p = (unsigned char *)pp;
be32enc(p, u >> 32);
be32enc(p + 4, u & 0xffffffff);
}
static __inline void
le16enc(void *pp, uint16_t u)
{
unsigned char *p = (unsigned char *)pp;
p[0] = u & 0xff;
p[1] = (u >> 8) & 0xff;
}
static __inline void
le32enc(void *pp, uint32_t u)
{
unsigned char *p = (unsigned char *)pp;
p[0] = u & 0xff;
p[1] = (u >> 8) & 0xff;
p[2] = (u >> 16) & 0xff;
p[3] = (u >> 24) & 0xff;
}
static __inline void
le64enc(void *pp, uint64_t u)
{
unsigned char *p = (unsigned char *)pp;
le32enc(p, u & 0xffffffff);
le32enc(p + 4, u >> 32);
}
#endif /* _SYS_ENDIAN_H_ */
@@ -0,0 +1,7 @@
#ifndef _FBSD_COMPAT_SYS_EVENT_H_
#define _FBSD_COMPAT_SYS_EVENT_H_
struct knlist {
};
#endif
@@ -0,0 +1,177 @@
/*-
* Copyright (c) 1999 Michael Smith <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/sys/sys/eventhandler.h,v 1.33.2.1 2006/05/16 07:27:49 ps Exp $
*/
#ifndef SYS_EVENTHANDLER_H
#define SYS_EVENTHANDLER_H
#include <sys/lock.h>
#include <sys/ktr.h>
#include <sys/mutex.h>
#include <sys/queue.h>
struct eventhandler_entry {
TAILQ_ENTRY(eventhandler_entry) ee_link;
int ee_priority;
#define EHE_DEAD_PRIORITY (-1)
void *ee_arg;
};
struct eventhandler_list {
char *el_name;
int el_flags;
#define EHL_INITTED (1<<0)
u_int el_runcount;
struct mtx el_lock;
TAILQ_ENTRY(eventhandler_list) el_link;
TAILQ_HEAD(,eventhandler_entry) el_entries;
};
typedef struct eventhandler_entry *eventhandler_tag;
#define EHL_LOCK(p) mtx_lock(&(p)->el_lock)
#define EHL_UNLOCK(p) mtx_unlock(&(p)->el_lock)
#define EHL_LOCK_ASSERT(p, x) mtx_assert(&(p)->el_lock, x)
/*
* Macro to invoke the handlers for a given event.
*/
#define _EVENTHANDLER_INVOKE(name, list, ...) do { \
struct eventhandler_entry *_ep; \
struct eventhandler_entry_ ## name *_t; \
\
KASSERT((list)->el_flags & EHL_INITTED, \
("eventhandler_invoke: running non-inited list")); \
EHL_LOCK_ASSERT((list), MA_OWNED); \
(list)->el_runcount++; \
KASSERT((list)->el_runcount > 0, \
("eventhandler_invoke: runcount overflow")); \
CTR0(KTR_EVH, "eventhandler_invoke(\"" __STRING(name) "\")"); \
TAILQ_FOREACH(_ep, &((list)->el_entries), ee_link) { \
if (_ep->ee_priority != EHE_DEAD_PRIORITY) { \
EHL_UNLOCK((list)); \
_t = (struct eventhandler_entry_ ## name *)_ep; \
CTR1(KTR_EVH, "eventhandler_invoke: executing %p", \
(void *)_t->eh_func); \
_t->eh_func(_ep->ee_arg , ## __VA_ARGS__); \
EHL_LOCK((list)); \
} \
} \
KASSERT((list)->el_runcount > 0, \
("eventhandler_invoke: runcount underflow")); \
(list)->el_runcount--; \
if ((list)->el_runcount == 0) \
eventhandler_prune_list(list); \
EHL_UNLOCK((list)); \
} while (0)
/*
* Slow handlers are entirely dynamic; lists are created
* when entries are added to them, and thus have no concept of "owner",
*
* Slow handlers need to be declared, but do not need to be defined. The
* declaration must be in scope wherever the handler is to be invoked.
*/
#define EVENTHANDLER_DECLARE(name, type) \
struct eventhandler_entry_ ## name \
{ \
struct eventhandler_entry ee; \
type eh_func; \
}; \
struct __hack
#define EVENTHANDLER_INVOKE(name, ...) \
do { \
struct eventhandler_list *_el; \
\
if ((_el = eventhandler_find_list(#name)) != NULL) \
_EVENTHANDLER_INVOKE(name, _el , ## __VA_ARGS__); \
} while (0)
#define EVENTHANDLER_REGISTER(name, func, arg, priority) \
eventhandler_register(NULL, #name, func, arg, priority)
#define EVENTHANDLER_DEREGISTER(name, tag) \
do { \
struct eventhandler_list *_el; \
\
if ((_el = eventhandler_find_list(#name)) != NULL) \
eventhandler_deregister(_el, tag); \
} while(0)
eventhandler_tag eventhandler_register(struct eventhandler_list *list,
const char *name, void *func, void *arg, int priority);
void eventhandler_deregister(struct eventhandler_list *list,
eventhandler_tag tag);
struct eventhandler_list *eventhandler_find_list(const char *name);
void eventhandler_prune_list(struct eventhandler_list *list);
/*
* Standard system event queues.
*/
/* Generic priority levels */
#define EVENTHANDLER_PRI_FIRST 0
#define EVENTHANDLER_PRI_ANY 10000
#define EVENTHANDLER_PRI_LAST 20000
/* Shutdown events */
typedef void (*shutdown_fn)(void *, int);
#define SHUTDOWN_PRI_FIRST EVENTHANDLER_PRI_FIRST
#define SHUTDOWN_PRI_DEFAULT EVENTHANDLER_PRI_ANY
#define SHUTDOWN_PRI_LAST EVENTHANDLER_PRI_LAST
EVENTHANDLER_DECLARE(shutdown_pre_sync, shutdown_fn); /* before fs sync */
EVENTHANDLER_DECLARE(shutdown_post_sync, shutdown_fn); /* after fs sync */
EVENTHANDLER_DECLARE(shutdown_final, shutdown_fn);
/* Low memory event */
typedef void (*vm_lowmem_handler_t)(void *, int);
#define LOWMEM_PRI_DEFAULT EVENTHANDLER_PRI_FIRST
EVENTHANDLER_DECLARE(vm_lowmem, vm_lowmem_handler_t);
/*
* Process events
* process_fork and exit handlers are called without Giant.
* exec handlers are called with Giant, but that is by accident.
*/
struct proc;
typedef void (*exitlist_fn)(void *, struct proc *);
typedef void (*forklist_fn)(void *, struct proc *, struct proc *, int);
typedef void (*execlist_fn)(void *, struct proc *);
EVENTHANDLER_DECLARE(process_exit, exitlist_fn);
EVENTHANDLER_DECLARE(process_fork, forklist_fn);
EVENTHANDLER_DECLARE(process_exec, execlist_fn);
typedef void (*uma_zone_chfn)(void *);
EVENTHANDLER_DECLARE(nmbclusters_change, uma_zone_chfn);
EVENTHANDLER_DECLARE(maxsockets_change, uma_zone_chfn);
#endif /* SYS_EVENTHANDLER_H */
@@ -0,0 +1,25 @@
#ifndef _FBSD_COMPAT_SYS_KERNEL_H_
#define _FBSD_COMPAT_SYS_KERNEL_H_
#include <stddef.h>
#include <string.h>
#include <KernelExport.h>
#include <sys/module.h>
#define hz 1000000LL
#define bootverbose 1
#define KASSERT(cond,msg) do { \
if (!cond) \
panic msg; \
} while(0)
#define __printflike(a, b) __attribute__ ((format (__printf__, a, b)))
int printf(const char *format, ...) __printflike(1, 2);
#endif
@@ -0,0 +1,191 @@
/*-
* Copyright (c) 1996 Berkeley Software Design, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Berkeley Software Design Inc's name may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from BSDI $Id: ktr.h,v 1.10.2.7 2000/03/16 21:44:42 cp Exp $
* $FreeBSD: src/sys/sys/ktr.h,v 1.32.2.2 2006/01/23 14:56:33 marius Exp $
*/
/*
* Wraparound kernel trace buffer support.
*/
#ifndef _SYS_KTR_H_
#define _SYS_KTR_H_
/*
* Trace classes
*/
#define KTR_GEN 0x00000001 /* General (TR) */
#define KTR_NET 0x00000002 /* Network */
#define KTR_DEV 0x00000004 /* Device driver */
#define KTR_LOCK 0x00000008 /* MP locking */
#define KTR_SMP 0x00000010 /* MP general */
#define KTR_FS 0x00000020 /* Filesystem */
#define KTR_PMAP 0x00000040 /* Pmap tracing */
#define KTR_MALLOC 0x00000080 /* Malloc tracing */
#define KTR_TRAP 0x00000100 /* Trap processing */
#define KTR_INTR 0x00000200 /* Interrupt tracing */
#define KTR_SIG 0x00000400 /* Signal processing */
#define KTR_CLK 0x00000800 /* hardclock verbose */
#define KTR_PROC 0x00001000 /* Process scheduling */
#define KTR_SYSC 0x00002000 /* System call */
#define KTR_INIT 0x00004000 /* System initialization */
#define KTR_KGDB 0x00008000 /* Trace kgdb internals */
#define KTR_IO 0x00010000 /* Upper I/O */
#define KTR_EVH 0x00020000 /* Eventhandler */
#define KTR_VFS 0x00040000 /* VFS events */
#define KTR_VOP 0x00080000 /* Auto-generated vop events */
#define KTR_VM 0x00100000 /* The virtual memory system */
#define KTR_WITNESS 0x00200000
#define KTR_RUNQ 0x00400000 /* Run queue */
#define KTR_CONTENTION 0x00800000 /* Lock contention */
#define KTR_UMA 0x01000000 /* UMA slab allocator */
#define KTR_CALLOUT 0x02000000 /* Callouts and timeouts */
#define KTR_GEOM 0x04000000 /* GEOM I/O events */
#define KTR_BUSDMA 0x08000000 /* busdma(9) events */
#define KTR_CRITICAL 0x10000000 /* Critical sections */
#define KTR_SCHED 0x20000000 /* Machine parsed sched info. */
#define KTR_BUF 0x40000000 /* Buffer cache */
#define KTR_ALL 0x7fffffff
/*
* Trace classes which can be assigned to particular use at compile time
* These must remain in high 22 as some assembly code counts on it
*/
#define KTR_CT1 0x01000000
#define KTR_CT2 0x02000000
#define KTR_CT3 0x04000000
#define KTR_CT4 0x08000000
#define KTR_CT5 0x10000000
#define KTR_CT6 0x20000000
#define KTR_CT7 0x40000000
#define KTR_CT8 0x80000000
/* Trace classes to compile in */
#ifdef KTR
#ifndef KTR_COMPILE
#define KTR_COMPILE (KTR_ALL)
#endif
#else /* !KTR */
#undef KTR_COMPILE
#define KTR_COMPILE 0
#endif /* KTR */
/* Trace classes that can not be used with KTR_ALQ */
#define KTR_ALQ_MASK (KTR_WITNESS)
/*
* Version number for ktr_entry struct. Increment this when you break binary
* compatibility.
*/
#define KTR_VERSION 2
#define KTR_PARMS 6
#ifndef LOCORE
struct ktr_entry {
u_int64_t ktr_timestamp;
int ktr_cpu;
int ktr_line;
const char *ktr_file;
const char *ktr_desc;
struct thread *ktr_thread;
u_long ktr_parms[KTR_PARMS];
};
extern int ktr_cpumask;
extern int ktr_mask;
extern int ktr_entries;
extern int ktr_verbose;
extern volatile int ktr_idx;
extern struct ktr_entry ktr_buf[];
#ifdef KTR
void ktr_tracepoint(u_int mask, const char *file, int line,
const char *format, u_long arg1, u_long arg2, u_long arg3,
u_long arg4, u_long arg5, u_long arg6);
#define CTR6(m, format, p1, p2, p3, p4, p5, p6) do { \
if (KTR_COMPILE & (m)) \
ktr_tracepoint((m), __FILE__, __LINE__, format, \
(u_long)(p1), (u_long)(p2), (u_long)(p3), \
(u_long)(p4), (u_long)(p5), (u_long)(p6)); \
} while(0)
#define CTR0(m, format) CTR6(m, format, 0, 0, 0, 0, 0, 0)
#define CTR1(m, format, p1) CTR6(m, format, p1, 0, 0, 0, 0, 0)
#define CTR2(m, format, p1, p2) CTR6(m, format, p1, p2, 0, 0, 0, 0)
#define CTR3(m, format, p1, p2, p3) CTR6(m, format, p1, p2, p3, 0, 0, 0)
#define CTR4(m, format, p1, p2, p3, p4) CTR6(m, format, p1, p2, p3, p4, 0, 0)
#define CTR5(m, format, p1, p2, p3, p4, p5) CTR6(m, format, p1, p2, p3, p4, p5, 0)
#else /* KTR */
#define CTR0(m, d)
#define CTR1(m, d, p1)
#define CTR2(m, d, p1, p2)
#define CTR3(m, d, p1, p2, p3)
#define CTR4(m, d, p1, p2, p3, p4)
#define CTR5(m, d, p1, p2, p3, p4, p5)
#define CTR6(m, d, p1, p2, p3, p4, p5, p6)
#endif /* KTR */
#define TR0(d) CTR0(KTR_GEN, d)
#define TR1(d, p1) CTR1(KTR_GEN, d, p1)
#define TR2(d, p1, p2) CTR2(KTR_GEN, d, p1, p2)
#define TR3(d, p1, p2, p3) CTR3(KTR_GEN, d, p1, p2, p3)
#define TR4(d, p1, p2, p3, p4) CTR4(KTR_GEN, d, p1, p2, p3, p4)
#define TR5(d, p1, p2, p3, p4, p5) CTR5(KTR_GEN, d, p1, p2, p3, p4, p5)
#define TR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_GEN, d, p1, p2, p3, p4, p5, p6)
/*
* Trace initialization events, similar to CTR with KTR_INIT, but
* completely ifdef'ed out if KTR_INIT isn't in KTR_COMPILE (to
* save string space, the compiler doesn't optimize out strings
* for the conditional ones above).
*/
#if (KTR_COMPILE & KTR_INIT) != 0
#define ITR0(d) CTR0(KTR_INIT, d)
#define ITR1(d, p1) CTR1(KTR_INIT, d, p1)
#define ITR2(d, p1, p2) CTR2(KTR_INIT, d, p1, p2)
#define ITR3(d, p1, p2, p3) CTR3(KTR_INIT, d, p1, p2, p3)
#define ITR4(d, p1, p2, p3, p4) CTR4(KTR_INIT, d, p1, p2, p3, p4)
#define ITR5(d, p1, p2, p3, p4, p5) CTR5(KTR_INIT, d, p1, p2, p3, p4, p5)
#define ITR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_INIT, d, p1, p2, p3, p4, p5, p6)
#else
#define ITR0(d)
#define ITR1(d, p1)
#define ITR2(d, p1, p2)
#define ITR3(d, p1, p2, p3)
#define ITR4(d, p1, p2, p3, p4)
#define ITR5(d, p1, p2, p3, p4, p5)
#define ITR6(d, p1, p2, p3, p4, p5, p6)
#endif
#endif /* !LOCORE */
#endif /* !_SYS_KTR_H_ */
@@ -0,0 +1,8 @@
#ifndef _FBSD_COMPAT_SYS_MALLOC_H_
#define _FBSD_COMPAT_SYS_MALLOC_H_
#define M_NOWAIT 0x0001
#define M_WAITOK 0x0002
#define M_ZERO 0x0100
#endif
@@ -0,0 +1,53 @@
#ifndef _FBSD_COMPAT_SYS_MBUF_H_
#define _FBSD_COMPAT_SYS_MBUF_H_
#include <sys/malloc.h>
struct m_pkthdr {
int len;
int csum_flags;
uint16_t csum_data;
struct ifnet * rcvif;
};
struct m_ext {
void * ext_buf;
unsigned int ext_size;
};
struct mbuf {
struct mbuf * m_next;
struct mbuf * m_nextpkt;
int m_len;
int m_flags;
void * m_data;
struct m_pkthdr m_pkthdr;
struct m_ext m_ext;
};
#define M_DONTWAIT M_NOWAIT
#define M_TRYWAIT M_WAITOK
#define M_WAIT M_WAITOK
#define MT_DATA 1
#define M_EXT 0x0001
#define M_PKTHDR 0x0002
#define CSUM_IP 0x0001
#define CSUM_TCP 0x0002
#define CSUM_UDP 0x0004
#define CSUM_IP_CHECKED 0x0100
#define CSUM_IP_VALID 0x0200
#define CSUM_DATA_VALID 0x0400
#define CSUM_PSEUDO_HDR 0x0800
#define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP)
struct mbuf *m_getcl(int how, short type, int flags);
void m_freem(struct mbuf *mbuf);
struct mbuf *m_defrag(struct mbuf *m, int);
#define mtod(m, type) (type)((m)->m_data)
#endif
@@ -0,0 +1,8 @@
#ifndef _FBSD_COMPAT_SYS_MODULE_H_
#define _FBSD_COMPAT_SYS_MODULE_H_
#define DECLARE_MODULE(name, data, sub, order)
#define MODULE_DEPEND(module, mdepend, vmin, vpref, vmax)
#endif
@@ -0,0 +1,51 @@
#ifndef _FBSD_COMPAT_SYS_MUTEX_H_
#define _FBSD_COMPAT_SYS_MUTEX_H_
#include <lock.h>
struct mtx {
int type;
union {
mutex mutex;
int32 spinlock;
recursive_lock recursive;
} u;
};
#define MA_OWNED 0x1
#define MA_NOTOWNED 0x2
#define MA_RECURSED 0x4
#define MA_NOTRECURSED 0x8
#define mtx_assert(mtx, what)
#define MTX_DEF 0x0000
#define MTX_RECURSE 0x0004
#define MTX_NETWORK_LOCK "network driver"
static inline void mtx_lock(struct mtx *mtx)
{
if (mtx->type == MTX_DEF)
mutex_lock(&mtx->u.mutex);
else if (mtx->type == MTX_RECURSE)
recursive_lock_lock(&mtx->u.recursive);
}
static inline void mtx_unlock(struct mtx *mtx)
{
if (mtx->type == MTX_DEF)
mutex_unlock(&mtx->u.mutex);
else if (mtx->type == MTX_RECURSE)
recursive_lock_unlock(&mtx->u.recursive);
}
void mtx_init(struct mtx *m, const char *name, const char *type, int opts);
void mtx_destroy(struct mtx *m);
extern struct mutex Giant;
#endif
@@ -0,0 +1,19 @@
#ifndef _FBSD_COMPAT_SYS_PARAM_H_
#define _FBSD_COMPAT_SYS_PARAM_H_
#include <posix/sys/param.h>
#define MAXBSIZE 0x10000
#define PAGE_SIZE B_PAGE_SIZE
#ifndef MSIZE
#define MSIZE 256
#endif
#ifndef MCLSHIFT
#define MCLSHIFT 11
#endif
#define MCLBYTES (1 << MCLSHIFT)
#endif
@@ -0,0 +1,553 @@
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)queue.h 8.5 (Berkeley) 8/20/94
* $FreeBSD: src/sys/sys/queue.h,v 1.60.2.1 2005/08/16 22:41:39 phk Exp $
*/
#ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_
#include <sys/cdefs.h>
/*
* This file defines four types of data structures: singly-linked lists,
* singly-linked tail queues, lists and tail queues.
*
* A singly-linked list is headed by a single forward pointer. The elements
* are singly linked for minimum space and pointer manipulation overhead at
* the expense of O(n) removal for arbitrary elements. New elements can be
* added to the list after an existing element or at the head of the list.
* Elements being removed from the head of the list should use the explicit
* macro for this purpose for optimum efficiency. A singly-linked list may
* only be traversed in the forward direction. Singly-linked lists are ideal
* for applications with large datasets and few or no removals or for
* implementing a LIFO queue.
*
* A singly-linked tail queue is headed by a pair of pointers, one to the
* head of the list and the other to the tail of the list. The elements are
* singly linked for minimum space and pointer manipulation overhead at the
* expense of O(n) removal for arbitrary elements. New elements can be added
* to the list after an existing element, at the head of the list, or at the
* end of the list. Elements being removed from the head of the tail queue
* should use the explicit macro for this purpose for optimum efficiency.
* A singly-linked tail queue may only be traversed in the forward direction.
* Singly-linked tail queues are ideal for applications with large datasets
* and few or no removals or for implementing a FIFO queue.
*
* A list is headed by a single forward pointer (or an array of forward
* pointers for a hash table header). The elements are doubly linked
* so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before
* or after an existing element or at the head of the list. A list
* may only be traversed in the forward direction.
*
* A tail queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or
* after an existing element, at the head of the list, or at the end of
* the list. A tail queue may be traversed in either direction.
*
* For details on the use of these macros, see the queue(3) manual page.
*
*
* SLIST LIST STAILQ TAILQ
* _HEAD + + + +
* _HEAD_INITIALIZER + + + +
* _ENTRY + + + +
* _INIT + + + +
* _EMPTY + + + +
* _FIRST + + + +
* _NEXT + + + +
* _PREV - - - +
* _LAST - - + +
* _FOREACH + + + +
* _FOREACH_SAFE + + + +
* _FOREACH_REVERSE - - - +
* _FOREACH_REVERSE_SAFE - - - +
* _INSERT_HEAD + + + +
* _INSERT_BEFORE - + - +
* _INSERT_AFTER + + + +
* _INSERT_TAIL - - + +
* _CONCAT - - + +
* _REMOVE_HEAD + - + -
* _REMOVE + + + +
*
*/
#define QUEUE_MACRO_DEBUG 0
#if QUEUE_MACRO_DEBUG
/* Store the last 2 places the queue element or head was altered */
struct qm_trace {
char * lastfile;
int lastline;
char * prevfile;
int prevline;
};
#define TRACEBUF struct qm_trace trace;
#define TRASHIT(x) do {(x) = (void *)-1;} while (0)
#define QMD_TRACE_HEAD(head) do { \
(head)->trace.prevline = (head)->trace.lastline; \
(head)->trace.prevfile = (head)->trace.lastfile; \
(head)->trace.lastline = __LINE__; \
(head)->trace.lastfile = __FILE__; \
} while (0)
#define QMD_TRACE_ELEM(elem) do { \
(elem)->trace.prevline = (elem)->trace.lastline; \
(elem)->trace.prevfile = (elem)->trace.lastfile; \
(elem)->trace.lastline = __LINE__; \
(elem)->trace.lastfile = __FILE__; \
} while (0)
#else
#define QMD_TRACE_ELEM(elem)
#define QMD_TRACE_HEAD(head)
#define TRACEBUF
#define TRASHIT(x)
#endif /* QUEUE_MACRO_DEBUG */
/*
* Singly-linked List declarations.
*/
#define SLIST_HEAD(name, type) \
struct name { \
struct type *slh_first; /* first element */ \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#define SLIST_ENTRY(type) \
struct { \
struct type *sle_next; /* next element */ \
}
/*
* Singly-linked List functions.
*/
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
#define SLIST_FIRST(head) ((head)->slh_first)
#define SLIST_FOREACH(var, head, field) \
for ((var) = SLIST_FIRST((head)); \
(var); \
(var) = SLIST_NEXT((var), field))
#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = SLIST_FIRST((head)); \
(var) && ((tvar) = SLIST_NEXT((var), field), 1); \
(var) = (tvar))
#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
for ((varp) = &SLIST_FIRST((head)); \
((var) = *(varp)) != NULL; \
(varp) = &SLIST_NEXT((var), field))
#define SLIST_INIT(head) do { \
SLIST_FIRST((head)) = NULL; \
} while (0)
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \
SLIST_NEXT((slistelm), field) = (elm); \
} while (0)
#define SLIST_INSERT_HEAD(head, elm, field) do { \
SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \
SLIST_FIRST((head)) = (elm); \
} while (0)
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
#define SLIST_REMOVE(head, elm, type, field) do { \
if (SLIST_FIRST((head)) == (elm)) { \
SLIST_REMOVE_HEAD((head), field); \
} \
else { \
struct type *curelm = SLIST_FIRST((head)); \
while (SLIST_NEXT(curelm, field) != (elm)) \
curelm = SLIST_NEXT(curelm, field); \
SLIST_NEXT(curelm, field) = \
SLIST_NEXT(SLIST_NEXT(curelm, field), field); \
} \
} while (0)
#define SLIST_REMOVE_HEAD(head, field) do { \
SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
} while (0)
/*
* Singly-linked Tail queue declarations.
*/
#define STAILQ_HEAD(name, type) \
struct name { \
struct type *stqh_first;/* first element */ \
struct type **stqh_last;/* addr of last next element */ \
}
#define STAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).stqh_first }
#define STAILQ_ENTRY(type) \
struct { \
struct type *stqe_next; /* next element */ \
}
/*
* Singly-linked Tail queue functions.
*/
#define STAILQ_CONCAT(head1, head2) do { \
if (!STAILQ_EMPTY((head2))) { \
*(head1)->stqh_last = (head2)->stqh_first; \
(head1)->stqh_last = (head2)->stqh_last; \
STAILQ_INIT((head2)); \
} \
} while (0)
#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
#define STAILQ_FIRST(head) ((head)->stqh_first)
#define STAILQ_FOREACH(var, head, field) \
for((var) = STAILQ_FIRST((head)); \
(var); \
(var) = STAILQ_NEXT((var), field))
#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = STAILQ_FIRST((head)); \
(var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#define STAILQ_INIT(head) do { \
STAILQ_FIRST((head)) = NULL; \
(head)->stqh_last = &STAILQ_FIRST((head)); \
} while (0)
#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \
if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
STAILQ_NEXT((tqelm), field) = (elm); \
} while (0)
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
STAILQ_FIRST((head)) = (elm); \
} while (0)
#define STAILQ_INSERT_TAIL(head, elm, field) do { \
STAILQ_NEXT((elm), field) = NULL; \
*(head)->stqh_last = (elm); \
(head)->stqh_last = &STAILQ_NEXT((elm), field); \
} while (0)
#define STAILQ_LAST(head, type, field) \
(STAILQ_EMPTY((head)) ? \
NULL : \
((struct type *) \
((char *)((head)->stqh_last) - __offsetof(struct type, field))))
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
#define STAILQ_REMOVE(head, elm, type, field) do { \
if (STAILQ_FIRST((head)) == (elm)) { \
STAILQ_REMOVE_HEAD((head), field); \
} \
else { \
struct type *curelm = STAILQ_FIRST((head)); \
while (STAILQ_NEXT(curelm, field) != (elm)) \
curelm = STAILQ_NEXT(curelm, field); \
if ((STAILQ_NEXT(curelm, field) = \
STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
(head)->stqh_last = &STAILQ_NEXT((curelm), field);\
} \
} while (0)
#define STAILQ_REMOVE_HEAD(head, field) do { \
if ((STAILQ_FIRST((head)) = \
STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \
(head)->stqh_last = &STAILQ_FIRST((head)); \
} while (0)
#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \
if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \
(head)->stqh_last = &STAILQ_FIRST((head)); \
} while (0)
/*
* List declarations.
*/
#define LIST_HEAD(name, type) \
struct name { \
struct type *lh_first; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element */ \
struct type **le_prev; /* address of previous next element */ \
}
/*
* List functions.
*/
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
#define LIST_FIRST(head) ((head)->lh_first)
#define LIST_FOREACH(var, head, field) \
for ((var) = LIST_FIRST((head)); \
(var); \
(var) = LIST_NEXT((var), field))
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = LIST_FIRST((head)); \
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
(var) = (tvar))
#define LIST_INIT(head) do { \
LIST_FIRST((head)) = NULL; \
} while (0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\
LIST_NEXT((listelm), field)->field.le_prev = \
&LIST_NEXT((elm), field); \
LIST_NEXT((listelm), field) = (elm); \
(elm)->field.le_prev = &LIST_NEXT((listelm), field); \
} while (0)
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.le_prev = (listelm)->field.le_prev; \
LIST_NEXT((elm), field) = (listelm); \
*(listelm)->field.le_prev = (elm); \
(listelm)->field.le_prev = &LIST_NEXT((elm), field); \
} while (0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \
LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\
LIST_FIRST((head)) = (elm); \
(elm)->field.le_prev = &LIST_FIRST((head)); \
} while (0)
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
#define LIST_REMOVE(elm, field) do { \
if (LIST_NEXT((elm), field) != NULL) \
LIST_NEXT((elm), field)->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = LIST_NEXT((elm), field); \
} while (0)
/*
* Tail queue declarations.
*/
#define TAILQ_HEAD(name, type) \
struct name { \
struct type *tqh_first; /* first element */ \
struct type **tqh_last; /* addr of last next element */ \
TRACEBUF \
}
#define TAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).tqh_first }
#define TAILQ_ENTRY(type) \
struct { \
struct type *tqe_next; /* next element */ \
struct type **tqe_prev; /* address of previous next element */ \
TRACEBUF \
}
/*
* Tail queue functions.
*/
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
(head1)->tqh_last = (head2)->tqh_last; \
TAILQ_INIT((head2)); \
QMD_TRACE_HEAD(head1); \
QMD_TRACE_HEAD(head2); \
} \
} while (0)
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_FOREACH(var, head, field) \
for ((var) = TAILQ_FIRST((head)); \
(var); \
(var) = TAILQ_NEXT((var), field))
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
(var) = (tvar))
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for ((var) = TAILQ_LAST((head), headname); \
(var); \
(var) = TAILQ_PREV((var), headname, field))
#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
for ((var) = TAILQ_LAST((head), headname); \
(var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
(var) = (tvar))
#define TAILQ_INIT(head) do { \
TAILQ_FIRST((head)) = NULL; \
(head)->tqh_last = &TAILQ_FIRST((head)); \
QMD_TRACE_HEAD(head); \
} while (0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
TAILQ_NEXT((elm), field)->field.tqe_prev = \
&TAILQ_NEXT((elm), field); \
else { \
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
QMD_TRACE_HEAD(head); \
} \
TAILQ_NEXT((listelm), field) = (elm); \
(elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \
QMD_TRACE_ELEM(&(elm)->field); \
QMD_TRACE_ELEM(&listelm->field); \
} while (0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
TAILQ_NEXT((elm), field) = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \
QMD_TRACE_ELEM(&(elm)->field); \
QMD_TRACE_ELEM(&listelm->field); \
} while (0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \
TAILQ_FIRST((head))->field.tqe_prev = \
&TAILQ_NEXT((elm), field); \
else \
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
TAILQ_FIRST((head)) = (elm); \
(elm)->field.tqe_prev = &TAILQ_FIRST((head)); \
QMD_TRACE_HEAD(head); \
QMD_TRACE_ELEM(&(elm)->field); \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
TAILQ_NEXT((elm), field) = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &TAILQ_NEXT((elm), field); \
QMD_TRACE_HEAD(head); \
QMD_TRACE_ELEM(&(elm)->field); \
} while (0)
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
#define TAILQ_REMOVE(head, elm, field) do { \
if ((TAILQ_NEXT((elm), field)) != NULL) \
TAILQ_NEXT((elm), field)->field.tqe_prev = \
(elm)->field.tqe_prev; \
else { \
(head)->tqh_last = (elm)->field.tqe_prev; \
QMD_TRACE_HEAD(head); \
} \
*(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \
TRASHIT((elm)->field.tqe_next); \
TRASHIT((elm)->field.tqe_prev); \
QMD_TRACE_ELEM(&(elm)->field); \
} while (0)
#ifdef _KERNEL
/*
* XXX insque() and remque() are an old way of handling certain queues.
* They bogusly assumes that all queue heads look alike.
*/
struct quehead {
struct quehead *qh_link;
struct quehead *qh_rlink;
};
#ifdef __CC_SUPPORTS___INLINE
static __inline void
insque(void *a, void *b)
{
struct quehead *element = (struct quehead *)a,
*head = (struct quehead *)b;
element->qh_link = head->qh_link;
element->qh_rlink = head;
head->qh_link = element;
element->qh_link->qh_rlink = element;
}
static __inline void
remque(void *a)
{
struct quehead *element = (struct quehead *)a;
element->qh_link->qh_rlink = element->qh_rlink;
element->qh_rlink->qh_link = element->qh_link;
element->qh_rlink = 0;
}
#else /* !__CC_SUPPORTS___INLINE */
void insque(void *a, void *b);
void remque(void *a);
#endif /* __CC_SUPPORTS___INLINE */
#endif /* _KERNEL */
#endif /* !_SYS_QUEUE_H_ */
@@ -0,0 +1,12 @@
#ifndef _FBSD_COMPAT_SYS_RMAN_H_
#define _FBSD_COMPAT_SYS_RMAN_H_
#include <sys/bus.h>
#define RF_ACTIVE 0x0002
#define RF_SHAREABLE 0x0004
bus_space_handle_t rman_get_bushandle(struct resource *);
bus_space_tag_t rman_get_bustag(struct resource *);
#endif
@@ -0,0 +1,8 @@
#ifndef _FBSD_COMPAT_SYS_SOCKIO_H_
#define _FBSD_COMPAT_SYS_SOCKIO_H_
#include <posix/sys/sockio.h>
#define SIOCSIFCAP SIOCSPACKETCAP
#endif
@@ -0,0 +1,41 @@
#ifndef _FBSD_COMPAT_SYS_SYSCTL_H_
#define _FBSD_COMPAT_SYS_SYSCTL_H_
#ifdef _KERNEL
struct sysctl_req {
void *newptr;
};
#define SYSCTL_HANDLER_ARGS void *oidp, void *arg1, void *arg2, struct sysctl_req *req
#define OID_AUTO (-1)
#define CTLTYPE 0xf
#define CTLTYPE_NONE 1
#define CTLTYPE_INT 2
#define CTLTYPE_STRING 3
#define CTLFLAG_RD 0x80000000
#define CTLFLAG_WR 0x40000000
#define CTLFLAG_RW (CTLFLAG_RD | CTLFLAG_WR)
static void SYSCTL_ADD_PROC(void *a, void *b, int c, const char *d, int e,
void *f, int g, int (*h)(SYSCTL_HANDLER_ARGS), const char *i, const char *j)
{
}
#define SYSCTL_ADD_INT(...)
#define SYSCTL_CHILDREN(...) NULL
#define device_get_sysctl_ctx(dev) NULL
static inline int
sysctl_handle_int(SYSCTL_HANDLER_ARGS)
{
return 0;
}
#endif
#endif
@@ -0,0 +1,15 @@
#ifndef _FBSD_COMPAT_SYS_SYSTM_H_
#define _FBSD_COMPAT_SYS_SYSTM_H_
#include <stdint.h>
#include <sys/callout.h>
#include <sys/kernel.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_media.h>
#define DELAY(n) snooze(n)
#endif