diff --git a/devicemodel/hw/pci/core.c b/devicemodel/hw/pci/core.c index 82254efcd..9dfcac414 100644 --- a/devicemodel/hw/pci/core.c +++ b/devicemodel/hw/pci/core.c @@ -1019,7 +1019,7 @@ pci_emul_init(struct vmctx *ctx, struct pci_vdev_ops *ops, int bus, int slot, pci_set_cfgdata8(pdi, PCIR_INTPIN, 0); pci_set_cfgdata8(pdi, PCIR_COMMAND, - PCIM_CMD_PORTEN | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN); + PCIM_CMD_PORTEN | PCIM_CMD_MEMEN | PCIM_CMD_BUSHOSTEN); if (fi->fi_param_saved) fi->fi_param = strdup(fi->fi_param_saved); diff --git a/devicemodel/hw/pci/npk.c b/devicemodel/hw/pci/npk.c index 9b63ebb48..bbc5e016c 100644 --- a/devicemodel/hw/pci/npk.c +++ b/devicemodel/hw/pci/npk.c @@ -212,7 +212,7 @@ static int pci_npk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) * +--sw_bar for host +--sw_bar for UOS#x */ - /* get the master offset and the number for this guest */ + /* get the host offset and the number for this guest */ if ((opts == NULL) || dm_strtoui(opts, &cp, 10, &m_off) || *cp != '/' || dm_strtoui(cp + 1, &cp, 10, &m_num) || !valid_param(m_off, m_num)) { m_off = 256; diff --git a/devicemodel/hw/pci/virtio/virtio_console.c b/devicemodel/hw/pci/virtio/virtio_console.c index 202e43628..059395a34 100644 --- a/devicemodel/hw/pci/virtio/virtio_console.c +++ b/devicemodel/hw/pci/virtio/virtio_console.c @@ -692,7 +692,7 @@ virtio_console_config_backend(struct virtio_console_backend *be) { int fd, flags; char *pts_name = NULL; - int slave_fd = -1; + int client_fd = -1; struct termios tio, saved_tio; struct sockaddr_un addr; @@ -709,17 +709,17 @@ virtio_console_config_backend(struct virtio_console_backend *be) return -1; } - slave_fd = open(pts_name, O_RDWR); - if (slave_fd == -1) { - WPRINTF(("vtcon: slave_fd open failed, errno = %d\n", + client_fd = open(pts_name, O_RDWR); + if (client_fd == -1) { + WPRINTF(("vtcon: client_fd open failed, errno = %d\n", errno)); return -1; } - tcgetattr(slave_fd, &tio); + tcgetattr(client_fd, &tio); cfmakeraw(&tio); - tcsetattr(slave_fd, TCSAFLUSH, &tio); - be->pts_fd = slave_fd; + tcsetattr(client_fd, TCSAFLUSH, &tio); + be->pts_fd = client_fd; WPRINTF(("***********************************************\n")); WPRINTF(("virt-console backend redirected to %s\n", pts_name)); diff --git a/devicemodel/hw/pci/virtio/virtio_i2c.c b/devicemodel/hw/pci/virtio/virtio_i2c.c index 940ec1821..e93a34d38 100644 --- a/devicemodel/hw/pci/virtio/virtio_i2c.c +++ b/devicemodel/hw/pci/virtio/virtio_i2c.c @@ -52,9 +52,9 @@ * Hardware +----------+ * | | * bus 0v v .... - * +-----+---+ +----+----+ - * |i2c slave| |i2c slave| .... - * +---------+ +---------+ + * +-----+----+ +----+-----+ + * |i2c client| |i2c client| .... + * +----------+ +----------+ */ static int virtio_i2c_debug=0; @@ -91,7 +91,7 @@ static struct acpi_node acpi_node_table[] = { }; struct virtio_i2c_hdr { - uint16_t addr; /* slave address */ + uint16_t addr; /* client address */ uint16_t flags; uint16_t len; /*msg length*/ }__attribute__((packed)); @@ -366,13 +366,13 @@ acpi_add_default(struct pci_vdev *dev, int i2c_bus) } static bool -native_slave_access_ok(struct native_i2c_adapter *adapter, uint16_t addr) +native_client_access_ok(struct native_i2c_adapter *adapter, uint16_t addr) { if (ioctl(adapter->fd, I2C_SLAVE, addr) < 0) { if (errno == EBUSY) { - WPRINTF("i2c_core: slave device %x is busy!\n", addr); + WPRINTF("i2c_core: client device %x is busy!\n", addr); } else { - WPRINTF("i2c_core: slave device %d is not exsit!\n", addr); + WPRINTF("i2c_core: client device %d is not exsit!\n", addr); } return false; } @@ -427,7 +427,7 @@ native_adapter_proc(struct virtio_i2c *vi2c, struct i2c_msg *msg) } static struct native_i2c_adapter * -native_adapter_create(int bus, uint16_t slave_addr[], int n_slave) +native_adapter_create(int bus, uint16_t client_addr[], int n_client) { int fd; struct native_i2c_adapter *native_adapter; @@ -453,15 +453,15 @@ native_adapter_create(int bus, uint16_t slave_addr[], int n_slave) } native_adapter->fd = fd; native_adapter->bus = bus; - for (i = 0; i < n_slave; i++) { - if (slave_addr[i]) { - if (native_slave_access_ok(native_adapter, slave_addr[i])) { - if (native_adapter->i2cdev_enable[slave_addr[i]]) { - WPRINTF("slave addr 0x%x repeat, not allowed.\n", slave_addr[i]); + for (i = 0; i < n_client; i++) { + if (client_addr[i]) { + if (native_client_access_ok(native_adapter, client_addr[i])) { + if (native_adapter->i2cdev_enable[client_addr[i]]) { + WPRINTF("client addr 0x%x repeat, not allowed.\n", client_addr[i]); goto fail; } - native_adapter->i2cdev_enable[slave_addr[i]] = true; - DPRINTF("virtio_i2c: add slave 0x%x\n", slave_addr[i]); + native_adapter->i2cdev_enable[client_addr[i]] = true; + DPRINTF("virtio_i2c: add client 0x%x\n", client_addr[i]); } else { goto fail; } @@ -556,11 +556,11 @@ virtio_i2c_proc_thread(void *arg) static int virtio_i2c_map(struct virtio_i2c *vi2c) { - int i, slave_addr; + int i, client_addr; struct native_i2c_adapter *native_adapter; /* - * Flatten the map for slave address and native adapter to the array: + * Flatten the map for client address and native adapter to the array: * * adapter_map[MAX_I2C_VDEV]: * @@ -571,16 +571,16 @@ virtio_i2c_map(struct virtio_i2c *vi2c) */ for (i = 0; i < vi2c->native_adapter_num; i++) { native_adapter = vi2c->native_adapter[i]; - for (slave_addr = 0; slave_addr < MAX_I2C_VDEV; slave_addr++) { - if (native_adapter->i2cdev_enable[slave_addr]) { - if (vi2c->adapter_map[slave_addr]) { - WPRINTF("slave addr %x repeat, not support!\n", slave_addr); + for (client_addr = 0; client_addr < MAX_I2C_VDEV; client_addr++) { + if (native_adapter->i2cdev_enable[client_addr]) { + if (vi2c->adapter_map[client_addr]) { + WPRINTF("client addr %x repeat, not support!\n", client_addr); return -1; } /* As 0 is the initiate value, + 1 for index */ - vi2c->adapter_map[slave_addr] = i + 1; - DPRINTF("slave:%d -> native adapter: %d \n", - slave_addr, + vi2c->adapter_map[client_addr] = i + 1; + DPRINTF("client:%d -> native adapter: %d\n", + client_addr, native_adapter->bus); } } @@ -592,29 +592,29 @@ static int virtio_i2c_parse(struct virtio_i2c *vi2c, char *optstr) { char *cp, *t, *dsdt_str, *p; - uint16_t slave_addr[MAX_I2C_VDEV]; - int addr, bus, n_adapter, n_slave; + uint16_t client_addr[MAX_I2C_VDEV]; + int addr, bus, n_adapter, n_client; /* - * virtio-i2c,:]>[:]>], - * [:]>[:[@]]] + * virtio-i2c,:]>[:]>], + * [:]>[:[@]]] * * bus (dec): native adatper bus number. * e.g. 2 for /dev/i2c-2 - * slave_addr (hex): address for native slave device + * client_addr (hex): address for native client device * e.g. 0x1C or 1C * @: node is the acpi node name defined in acpi_node_table[] * e.g. @cam1 means adding 'cam1' node to dsdt table. * - * Note: slave address can not repeat. + * Note: client address can not repeat. */ n_adapter = 0; while (optstr != NULL) { cp = strsep(&optstr, ","); /* - * :[:]... + * :[:]... */ - n_slave = 0; + n_client = 0; bus = -1; while (cp != NULL && *cp !='\0') { if (*cp == ':') @@ -626,12 +626,12 @@ virtio_i2c_parse(struct virtio_i2c *vi2c, char *optstr) } else { if (dm_strtoi(cp, &t, 16, &addr) || addr < 0) return -1; - if (n_slave > MAX_I2C_VDEV) { + if (n_client > MAX_I2C_VDEV) { WPRINTF("too many devices, only support %d \n", MAX_I2C_VDEV); return -1; } - slave_addr[n_slave] = (uint16_t)(addr & (MAX_I2C_VDEV - 1)); - p = &vi2c->acpi_nodes[slave_addr[n_slave]][0]; + client_addr[n_client] = (uint16_t)(addr & (MAX_I2C_VDEV - 1)); + p = &vi2c->acpi_nodes[client_addr[n_client]][0]; if (t != NULL && *t == '@') { t++; dsdt_str = strsep(&t, ":,"); @@ -641,9 +641,9 @@ virtio_i2c_parse(struct virtio_i2c *vi2c, char *optstr) } DPRINTF("native i2c adapter %d:0x%x (%s)\n", bus, - slave_addr[n_slave], + client_addr[n_client], p); - n_slave++; + n_client++; } cp = t; } @@ -651,7 +651,7 @@ virtio_i2c_parse(struct virtio_i2c *vi2c, char *optstr) WPRINTF("too many adapter, only support %d \n", MAX_NATIVE_I2C_ADAPTER); return -1; } - vi2c->native_adapter[n_adapter] = native_adapter_create(bus, slave_addr, n_slave); + vi2c->native_adapter[n_adapter] = native_adapter_create(bus, client_addr, n_client); if (!vi2c->native_adapter[n_adapter]) return -1; n_adapter++; @@ -676,7 +676,7 @@ virtio_i2c_dsdt(struct pci_vdev *dev) acpi_add_i2c_adapter(dev, i2c_bus); DPRINTF("add dsdt for i2c adapter %d\n", i2c_bus); - /* add slave devices */ + /* add client devices */ node_num = sizeof(acpi_node_table) / sizeof(struct acpi_node); for (i = 0; i < MAX_I2C_VDEV; i++) { if (!native_adapter_find(vi2c, i)) diff --git a/devicemodel/hw/platform/ioc.c b/devicemodel/hw/platform/ioc.c index 7055016e3..a7e01842b 100644 --- a/devicemodel/hw/platform/ioc.c +++ b/devicemodel/hw/platform/ioc.c @@ -119,8 +119,8 @@ static uint8_t cbc_open_channel_command[] = {0xFD, 0x00, 0x00, 0x00}; static uint32_t ioc_boot_reason; /* - * Dummy pty slave fd is to maintain the pty active, - * to avoid EIO error when close the slave pty. + * Dummy pty client fd is to maintain the pty active, + * to avoid EIO error when close the client pty. */ static int dummy0_sfd = -1; static int dummy1_sfd = -1; diff --git a/devicemodel/hw/platform/pty_vuart.c b/devicemodel/hw/platform/pty_vuart.c index 44dd63061..5ff40737c 100644 --- a/devicemodel/hw/platform/pty_vuart.c +++ b/devicemodel/hw/platform/pty_vuart.c @@ -47,14 +47,14 @@ static int check_dir(const char *file) } /* - * Open PTY master device to used by caller and the PTY slave device for virtual - * UART. The pair(master/slave) can work as a communication channel between + * Open PTY host device to used by caller and the PTY client device for virtual + * UART. The pair(host/client) can work as a communication channel between * the caller and virtual UART. */ int pty_open_virtual_uart(const char *dev_name) { int fd; - char *slave_name; + char *client_name; struct termios attr; fd = open("/dev/ptmx", O_RDWR | O_NOCTTY | O_NONBLOCK); @@ -64,8 +64,8 @@ int pty_open_virtual_uart(const char *dev_name) goto pty_err; if (unlockpt(fd) < 0) goto pty_err; - slave_name = ptsname(fd); - if (!slave_name) + client_name = ptsname(fd); + if (!client_name) goto pty_err; if ((unlink(dev_name) < 0) && errno != ENOENT) goto pty_err; @@ -75,7 +75,7 @@ int pty_open_virtual_uart(const char *dev_name) */ if (check_dir(dev_name) < 0) goto pty_err; - if (symlink(slave_name, dev_name) < 0) + if (symlink(client_name, dev_name) < 0) goto pty_err; if (chmod(dev_name, 0660) < 0) goto attr_err; diff --git a/devicemodel/include/ata.h b/devicemodel/include/ata.h index f652f2be8..14f400f5e 100644 --- a/devicemodel/include/ata.h +++ b/devicemodel/include/ata.h @@ -197,7 +197,7 @@ struct ata_params { /*089*/ u_int16_t erase_time; /* time req'd in 2min units */ /*090*/ u_int16_t enhanced_erase_time; /* time req'd in 2min units */ /*091*/ u_int16_t apm_value; -/*092*/ u_int16_t master_passwd_revision; /* password revision code */ +/*092*/ u_int16_t host_passwd_revision; /* password revision code */ /*093*/ u_int16_t hwres; #define ATA_CABLE_ID 0x2000 @@ -301,8 +301,6 @@ struct ata_params { * bit 3-0 In LBA mode, 27-24 of address. In CHS mode, head number */ -#define ATA_DEV_MASTER 0x00 -#define ATA_DEV_SLAVE 0x10 #define ATA_DEV_LBA 0x40 /* ATA limits */ @@ -516,7 +514,7 @@ struct ata_params { #define ATAPI_SEND_OPC_INFO 0x54 /* send OPC structurek */ #define ATAPI_MODE_SELECT_BIG 0x55 /* set device parameters */ #define ATAPI_REPAIR_TRACK 0x58 /* repair track */ -#define ATAPI_READ_MASTER_CUE 0x59 /* read master CUE info */ +#define ATAPI_READ_HOST_CUE 0x59 /* read host CUE info */ #define ATAPI_MODE_SENSE_BIG 0x5a /* get device parameters */ #define ATAPI_CLOSE_TRACK 0x5b /* close track/session */ #define ATAPI_READ_BUFFER_CAPACITY 0x5c /* get buffer capicity */ @@ -943,7 +941,7 @@ struct ata_ioc_request { struct ata_security_password { u_int16_t ctrl; #define ATA_SECURITY_PASSWORD_USER 0x0000 -#define ATA_SECURITY_PASSWORD_MASTER 0x0001 +#define ATA_SECURITY_PASSWORD_HOST 0x0001 #define ATA_SECURITY_ERASE_NORMAL 0x0000 #define ATA_SECURITY_ERASE_ENHANCED 0x0002 #define ATA_SECURITY_LEVEL_HIGH 0x0000 diff --git a/devicemodel/include/netmap.h b/devicemodel/include/netmap.h deleted file mode 100644 index 4647224d0..000000000 --- a/devicemodel/include/netmap.h +++ /dev/null @@ -1,642 +0,0 @@ -/* - * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. 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 ``S 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$ - * - * Definitions of constants and the structures used by the netmap - * framework, for the part visible to both kernel and userspace. - * Detailed info on netmap is available with "man netmap" or at - * - * http://info.iet.unipi.it/~luigi/netmap/ - * - * This API is also used to communicate with the VALE software switch - */ - -#ifndef _NET_NETMAP_H_ -#define _NET_NETMAP_H_ - -#define NETMAP_API 11 /* current API version */ - -#define NETMAP_MIN_API 11 /* min and max versions accepted */ -#define NETMAP_MAX_API 15 -/* - * Some fields should be cache-aligned to reduce contention. - * The alignment is architecture and OS dependent, but rather than - * digging into OS headers to find the exact value we use an estimate - * that should cover most architectures. - */ -#define NM_CACHE_ALIGN 128 - -/* - * --- Netmap data structures --- - * - * The userspace data structures used by netmap are shown below. - * They are allocated by the kernel and mmap()ed by userspace threads. - * Pointers are implemented as memory offsets or indexes, - * so that they can be easily dereferenced in kernel and userspace. - - KERNEL (opaque, obviously) - - ==================================================================== - | - USERSPACE | struct netmap_ring - +---->+---------------+ - / | head,cur,tail | - struct netmap_if (nifp, 1 per fd) / | buf_ofs | - +---------------+ / | other fields | - | ni_tx_rings | / +===============+ - | ni_rx_rings | / | buf_idx, len | slot[0] - | | / | flags, ptr | - | | / +---------------+ - +===============+ / | buf_idx, len | slot[1] - | txring_ofs[0] | (rel.to nifp)--' | flags, ptr | - | txring_ofs[1] | +---------------+ - (tx+1 entries) (num_slots entries) - | txring_ofs[t] | | buf_idx, len | slot[n-1] - +---------------+ | flags, ptr | - | rxring_ofs[0] | +---------------+ - | rxring_ofs[1] | - (rx+1 entries) - | rxring_ofs[r] | - +---------------+ - - * For each "interface" (NIC, host stack, PIPE, VALE switch port) bound to - * a file descriptor, the mmap()ed region contains a (logically readonly) - * struct netmap_if pointing to struct netmap_ring's. - * - * There is one netmap_ring per physical NIC ring, plus one tx/rx ring - * pair attached to the host stack (this pair is unused for non-NIC ports). - * - * All physical/host stack ports share the same memory region, - * so that zero-copy can be implemented between them. - * VALE switch ports instead have separate memory regions. - * - * The netmap_ring is the userspace-visible replica of the NIC ring. - * Each slot has the index of a buffer (MTU-sized and residing in the - * mmapped region), its length and some flags. An extra 64-bit pointer - * is provided for user-supplied buffers in the tx path. - * - * In user space, the buffer address is computed as - * (char *)ring + buf_ofs + index * NETMAP_BUF_SIZE - * - * Added in NETMAP_API 11: - * - * + NIOCREGIF can request the allocation of extra spare buffers from - * the same memory pool. The desired number of buffers must be in - * nr_arg3. The ioctl may return fewer buffers, depending on memory - * availability. nr_arg3 will return the actual value, and, once - * mapped, nifp->ni_bufs_head will be the index of the first buffer. - * - * The buffers are linked to each other using the first uint32_t - * as the index. On close, ni_bufs_head must point to the list of - * buffers to be released. - * - * + NIOCREGIF can request space for extra rings (and buffers) - * allocated in the same memory space. The number of extra rings - * is in nr_arg1, and is advisory. This is a no-op on NICs where - * the size of the memory space is fixed. - * - * + NIOCREGIF can attach to PIPE rings sharing the same memory - * space with a parent device. The ifname indicates the parent device, - * which must already exist. Flags in nr_flags indicate if we want to - * bind the master or slave side, the index (from nr_ringid) - * is just a cookie and does not need to be sequential. - * - * + NIOCREGIF can also attach to 'monitor' rings that replicate - * the content of specific rings, also from the same memory space. - * - * Extra flags in nr_flags support the above functions. - * Application libraries may use the following naming scheme: - * netmap:foo all NIC ring pairs - * netmap:foo^ only host ring pair - * netmap:foo+ all NIC ring + host ring pairs - * netmap:foo-k the k-th NIC ring pair - * netmap:foo{k PIPE ring pair k, master side - * netmap:foo}k PIPE ring pair k, slave side - * - * Some notes about host rings: - * - * + The RX host ring is used to store those packets that the host network - * stack is trying to transmit through a NIC queue, but only if that queue - * is currently in netmap mode. Netmap will not intercept host stack mbufs - * designated to NIC queues that are not in netmap mode. As a consequence, - * registering a netmap port with netmap:foo^ is not enough to intercept - * mbufs in the RX host ring; the netmap port should be registered with - * netmap:foo*, or another registration should be done to open at least a - * NIC TX queue in netmap mode. - * - * + Netmap is not currently able to deal with intercepted trasmit mbufs which - * require offloadings like TSO, UFO, checksumming offloadings, etc. It is - * responsibility of the user to disable those offloadings (e.g. using - * ifconfig on FreeBSD or ethtool -K on Linux) for an interface that is being - * used in netmap mode. If the offloadings are not disabled, GSO and/or - * unchecksummed packets may be dropped immediately or end up in the host RX - * ring, and will be dropped as soon as the packet reaches another netmap - * adapter. - */ - -/* - * struct netmap_slot is a buffer descriptor - */ -struct netmap_slot { - uint32_t buf_idx; /* buffer index */ - uint16_t len; /* length for this slot */ - uint16_t flags; /* buf changed, etc. */ - uint64_t ptr; /* pointer for indirect buffers */ -}; - -/* - * The following flags control how the slot is used - */ - -#define NS_BUF_CHANGED 0x0001 /* buf_idx changed */ - /* - * must be set whenever buf_idx is changed (as it might be - * necessary to recompute the physical address and mapping) - * - * It is also set by the kernel whenever the buf_idx is - * changed internally (e.g., by pipes). Applications may - * use this information to know when they can reuse the - * contents of previously prepared buffers. - */ - -#define NS_REPORT 0x0002 /* ask the hardware to report results */ - /* - * Request notification when slot is used by the hardware. - * Normally transmit completions are handled lazily and - * may be unreported. This flag lets us know when a slot - * has been sent (e.g. to terminate the sender). - */ - -#define NS_FORWARD 0x0004 /* pass packet 'forward' */ - /* - * (Only for physical ports, rx rings with NR_FORWARD set). - * Slot released to the kernel (i.e. before ring->head) with - * this flag set are passed to the peer ring (host/NIC), - * thus restoring the host-NIC connection for these slots. - * This supports efficient traffic monitoring or firewalling. - */ - -#define NS_NO_LEARN 0x0008 /* disable bridge learning */ - /* - * On a VALE switch, do not 'learn' the source port for - * this buffer. - */ - -#define NS_INDIRECT 0x0010 /* userspace buffer */ - /* - * (VALE tx rings only) data is in a userspace buffer, - * whose address is in the 'ptr' field in the slot. - */ - -#define NS_MOREFRAG 0x0020 /* packet has more fragments */ - /* - * (VALE ports only) - * Set on all but the last slot of a multi-segment packet. - * The 'len' field refers to the individual fragment. - */ - -#define NS_PORT_SHIFT 8 -#define NS_PORT_MASK (0xff << NS_PORT_SHIFT) - /* - * The high 8 bits of the flag, if not zero, indicate the - * destination port for the VALE switch, overriding - * the lookup table. - */ - -#define NS_RFRAGS(_slot) (((_slot)->flags >> 8) & 0xff) - /* - * (VALE rx rings only) the high 8 bits - * are the number of fragments. - */ - -/* - * struct netmap_ring - * - * Netmap representation of a TX or RX ring (also known as "queue"). - * This is a queue implemented as a fixed-size circular array. - * At the software level the important fields are: head, cur, tail. - * - * In TX rings: - * - * head first slot available for transmission. - * cur wakeup point. select() and poll() will unblock - * when 'tail' moves past 'cur' - * tail (readonly) first slot reserved to the kernel - * - * [head .. tail-1] can be used for new packets to send; - * 'head' and 'cur' must be incremented as slots are filled - * with new packets to be sent; - * 'cur' can be moved further ahead if we need more space - * for new transmissions. XXX todo (2014-03-12) - * - * In RX rings: - * - * head first valid received packet - * cur wakeup point. select() and poll() will unblock - * when 'tail' moves past 'cur' - * tail (readonly) first slot reserved to the kernel - * - * [head .. tail-1] contain received packets; - * 'head' and 'cur' must be incremented as slots are consumed - * and can be returned to the kernel; - * 'cur' can be moved further ahead if we want to wait for - * new packets without returning the previous ones. - * - * DATA OWNERSHIP/LOCKING: - * The netmap_ring, and all slots and buffers in the range - * [head .. tail-1] are owned by the user program; - * the kernel only accesses them during a netmap system call - * and in the user thread context. - * - * Other slots and buffers are reserved for use by the kernel - */ -struct netmap_ring { - /* - * buf_ofs is meant to be used through macros. - * It contains the offset of the buffer region from this - * descriptor. - */ - const int64_t buf_ofs; - const uint32_t num_slots; /* number of slots in the ring. */ - const uint32_t nr_buf_size; - const uint16_t ringid; - const uint16_t dir; /* 0: tx, 1: rx */ - - uint32_t head; /* (u) first user slot */ - uint32_t cur; /* (u) wakeup point */ - uint32_t tail; /* (k) first kernel slot */ - - uint32_t flags; - - struct timeval ts; /* (k) time of last *sync() */ - - /* opaque room for a mutex or similar object */ -#if !defined(_WIN32) || defined(__CYGWIN__) - uint8_t __attribute__((__aligned__(NM_CACHE_ALIGN))) sem[128]; -#else - uint8_t __declspec(align(NM_CACHE_ALIGN)) sem[128]; -#endif - - /* the slots follow. This struct has variable size */ - struct netmap_slot slot[0]; /* array of slots. */ -}; - -/* - * RING FLAGS - */ -#define NR_TIMESTAMP 0x0002 /* set timestamp on *sync() */ - /* - * updates the 'ts' field on each netmap syscall. This saves - * saves a separate gettimeofday(), and is not much worse than - * software timestamps generated in the interrupt handler. - */ - -#define NR_FORWARD 0x0004 /* enable NS_FORWARD for ring */ - /* - * Enables the NS_FORWARD slot flag for the ring. - */ - -/* - * Netmap representation of an interface and its queue(s). - * This is initialized by the kernel when binding a file - * descriptor to a port, and should be considered as readonly - * by user programs. The kernel never uses it. - * - * There is one netmap_if for each file descriptor on which we want - * to select/poll. - * select/poll operates on one or all pairs depending on the value of - * nmr_queueid passed on the ioctl. - */ -struct netmap_if { - char ni_name[IFNAMSIZ]; /* name of the interface. */ - const uint32_t ni_version; /* API version, currently unused */ - const uint32_t ni_flags; /* properties */ -#define NI_PRIV_MEM 0x1 /* private memory region */ - - /* - * The number of packet rings available in netmap mode. - * Physical NICs can have different numbers of tx and rx rings. - * Physical NICs also have a 'host' ring pair. - * Additionally, clients can request additional ring pairs to - * be used for internal communication. - */ - const uint32_t ni_tx_rings; /* number of HW tx rings */ - const uint32_t ni_rx_rings; /* number of HW rx rings */ - - uint32_t ni_bufs_head; /* head index for extra bufs */ - uint32_t ni_spare1[5]; - /* - * The following array contains the offset of each netmap ring - * from this structure, in the following order: - * NIC tx rings (ni_tx_rings); host tx ring (1); extra tx rings; - * NIC rx rings (ni_rx_rings); host tx ring (1); extra rx rings. - * - * The area is filled up by the kernel on NIOCREGIF, - * and then only read by userspace code. - */ - const ssize_t ring_ofs[0]; -}; - -#ifndef NIOCREGIF -/* - * ioctl names and related fields - * - * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues, - * whose identity is set in NIOCREGIF through nr_ringid. - * These are non blocking and take no argument. - * - * NIOCGINFO takes a struct ifreq, the interface name is the input, - * the outputs are number of queues and number of descriptor - * for each queue (useful to set number of threads etc.). - * The info returned is only advisory and may change before - * the interface is bound to a file descriptor. - * - * NIOCREGIF takes an interface name within a struct nmre, - * and activates netmap mode on the interface (if possible). - * - * The argument to NIOCGINFO/NIOCREGIF overlays struct ifreq so we - * can pass it down to other NIC-related ioctls. - * - * The actual argument (struct nmreq) has a number of options to request - * different functions. - * The following are used in NIOCREGIF when nr_cmd == 0: - * - * nr_name (in) - * The name of the port (em0, valeXXX:YYY, etc.) - * limited to IFNAMSIZ for backward compatibility. - * - * nr_version (in/out) - * Must match NETMAP_API as used in the kernel, error otherwise. - * Always returns the desired value on output. - * - * nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings (in/out) - * On input, non-zero values may be used to reconfigure the port - * according to the requested values, but this is not guaranteed. - * On output the actual values in use are reported. - * - * nr_ringid (in) - * Indicates how rings should be bound to the file descriptors. - * If nr_flags != 0, then the low bits (in NETMAP_RING_MASK) - * are used to indicate the ring number, and nr_flags specifies - * the actual rings to bind. NETMAP_NO_TX_POLL is unaffected. - * - * NOTE: THE FOLLOWING (nr_flags == 0) IS DEPRECATED: - * If nr_flags == 0, NETMAP_HW_RING and NETMAP_SW_RING control - * the binding as follows: - * 0 (default) binds all physical rings - * NETMAP_HW_RING | ring number binds a single ring pair - * NETMAP_SW_RING binds only the host tx/rx rings - * - * NETMAP_NO_TX_POLL can be OR-ed to make select()/poll() push - * packets on tx rings only if POLLOUT is set. - * The default is to push any pending packet. - * - * NETMAP_DO_RX_POLL can be OR-ed to make select()/poll() release - * packets on rx rings also when POLLIN is NOT set. - * The default is to touch the rx ring only with POLLIN. - * Note that this is the opposite of TX because it - * reflects the common usage. - * - * NOTE: NETMAP_PRIV_MEM IS DEPRECATED, use nr_arg2 instead. - * NETMAP_PRIV_MEM is set on return for ports that do not use - * the global memory allocator. - * This information is not significant and applications - * should look at the region id in nr_arg2 - * - * nr_flags is the recommended mode to indicate which rings should - * be bound to a file descriptor. Values are NR_REG_* - * - * nr_arg1 (in) The number of extra rings to be reserved. - * Especially when allocating a VALE port the system only - * allocates the amount of memory needed for the port. - * If more shared memory rings are desired (e.g. for pipes), - * the first invocation for the same basename/allocator - * should specify a suitable number. Memory cannot be - * extended after the first allocation without closing - * all ports on the same region. - * - * nr_arg2 (in/out) The identity of the memory region used. - * On input, 0 means the system decides autonomously, - * other values may try to select a specific region. - * On return the actual value is reported. - * Region '1' is the global allocator, normally shared - * by all interfaces. Other values are private regions. - * If two ports the same region zero-copy is possible. - * - * nr_arg3 (in/out) number of extra buffers to be allocated. - * - * - * - * nr_cmd (in) if non-zero indicates a special command: - * NETMAP_BDG_ATTACH and nr_name = vale*:ifname - * attaches the NIC to the switch; nr_ringid specifies - * which rings to use. Used by vale-ctl -a ... - * nr_arg1 = NETMAP_BDG_HOST also attaches the host port - * as in vale-ctl -h ... - * - * NETMAP_BDG_DETACH and nr_name = vale*:ifname - * disconnects a previously attached NIC. - * Used by vale-ctl -d ... - * - * NETMAP_BDG_LIST - * list the configuration of VALE switches. - * - * NETMAP_BDG_VNET_HDR - * Set the virtio-net header length used by the client - * of a VALE switch port. - * - * NETMAP_BDG_NEWIF - * create a persistent VALE port with name nr_name. - * Used by vale-ctl -n ... - * - * NETMAP_BDG_DELIF - * delete a persistent VALE port. Used by vale-ctl -d ... - * - * nr_arg1, nr_arg2, nr_arg3 (in/out) command specific - * - * - * - */ - -/* - * struct nmreq overlays a struct ifreq (just the name) - */ -struct nmreq { - char nr_name[IFNAMSIZ]; - uint32_t nr_version; /* API version */ - uint32_t nr_offset; /* nifp offset in the shared region */ - uint32_t nr_memsize; /* size of the shared region */ - uint32_t nr_tx_slots; /* slots in tx rings */ - uint32_t nr_rx_slots; /* slots in rx rings */ - uint16_t nr_tx_rings; /* number of tx rings */ - uint16_t nr_rx_rings; /* number of rx rings */ - - uint16_t nr_ringid; /* ring(s) we care about */ -#define NETMAP_HW_RING 0x4000 /* single NIC ring pair */ -#define NETMAP_SW_RING 0x2000 /* only host ring pair */ - -#define NETMAP_RING_MASK 0x0fff /* the ring number */ - -#define NETMAP_NO_TX_POLL 0x1000 /* no automatic txsync on poll */ - -#define NETMAP_DO_RX_POLL 0x8000 /* DO automatic rxsync on poll */ - - uint16_t nr_cmd; -#define NETMAP_BDG_ATTACH 1 /* attach the NIC */ -#define NETMAP_BDG_DETACH 2 /* detach the NIC */ -#define NETMAP_BDG_REGOPS 3 /* register bridge callbacks */ -#define NETMAP_BDG_LIST 4 /* get bridge's info */ -#define NETMAP_BDG_VNET_HDR 5 /* set the port virtio-net-hdr length */ -#define NETMAP_BDG_OFFSET NETMAP_BDG_VNET_HDR /* deprecated alias */ -#define NETMAP_BDG_NEWIF 6 /* create a virtual port */ -#define NETMAP_BDG_DELIF 7 /* destroy a virtual port */ -#define NETMAP_PT_HOST_CREATE 8 /* create ptnetmap kthreads */ -#define NETMAP_PT_HOST_DELETE 9 /* delete ptnetmap kthreads */ -#define NETMAP_BDG_POLLING_ON 10 /* delete polling kthread */ -#define NETMAP_BDG_POLLING_OFF 11 /* delete polling kthread */ -#define NETMAP_VNET_HDR_GET 12 /* get the port virtio-net-hdr length */ -#define NETMAP_POOLS_INFO_GET 13 /* get memory allocator pools info */ - uint16_t nr_arg1; /* reserve extra rings in NIOCREGIF */ -#define NETMAP_BDG_HOST 1 /* attach the host stack on ATTACH */ - - uint16_t nr_arg2; - uint32_t nr_arg3; /* req. extra buffers in NIOCREGIF */ - uint32_t nr_flags; - /* various modes, extends nr_ringid */ - uint32_t spare2[1]; -}; - -#define NR_REG_MASK 0xf /* values for nr_flags */ -enum { NR_REG_DEFAULT = 0, /* backward compat, should not be used. */ - NR_REG_ALL_NIC = 1, - NR_REG_SW = 2, - NR_REG_NIC_SW = 3, - NR_REG_ONE_NIC = 4, - NR_REG_PIPE_MASTER = 5, - NR_REG_PIPE_SLAVE = 6, -}; -/* monitor uses the NR_REG to select the rings to monitor */ -#define NR_MONITOR_TX 0x100 -#define NR_MONITOR_RX 0x200 -#define NR_ZCOPY_MON 0x400 -/* request exclusive access to the selected rings */ -#define NR_EXCLUSIVE 0x800 -/* request ptnetmap host support */ -#define NR_PASSTHROUGH_HOST NR_PTNETMAP_HOST /* deprecated */ -#define NR_PTNETMAP_HOST 0x1000 -#define NR_RX_RINGS_ONLY 0x2000 -#define NR_TX_RINGS_ONLY 0x4000 -/* Applications set this flag if they are able to deal with virtio-net headers, - * that is send/receive frames that start with a virtio-net header. - * If not set, NIOCREGIF will fail with netmap ports that require applications - * to use those headers. If the flag is set, the application can use the - * NETMAP_VNET_HDR_GET command to figure out the header length. - */ -#define NR_ACCEPT_VNET_HDR 0x8000 - -#define NM_BDG_NAME "vale" /* prefix for bridge port name */ - -/* - * Windows does not have _IOWR(). _IO(), _IOW() and _IOR() are defined - * in ws2def.h but not sure if they are in the form we need. - * XXX so we redefine them - * in a convenient way to use for DeviceIoControl signatures - */ -#ifdef _WIN32 -#undef _IO /* ws2def.h */ -#define _WIN_NM_IOCTL_TYPE 40000 -#define _IO(_c, _n) CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800), \ - METHOD_BUFFERED, FILE_ANY_ACCESS) -#define _IO_direct(_c, _n) CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800), \ - METHOD_OUT_DIRECT, FILE_ANY_ACCESS) - -#define _IOWR(_c, _n, _s) _IO(_c, _n) - -/* We havesome internal sysctl in addition to the externally visible ones */ -#define NETMAP_MMAP _IO_direct('i', 160) /* note METHOD_OUT_DIRECT */ -#define NETMAP_POLL _IO('i', 162) - -/* and also two setsockopt for sysctl emulation */ -#define NETMAP_SETSOCKOPT _IO('i', 140) -#define NETMAP_GETSOCKOPT _IO('i', 141) - -/* These linknames are for the Netmap Core Driver */ -#define NETMAP_NT_DEVICE_NAME L"\\Device\\NETMAP" -#define NETMAP_DOS_DEVICE_NAME L"\\DosDevices\\netmap" - -/* Definition of a structure used to pass a virtual address within an IOCTL */ -typedef struct _MEMORY_ENTRY { - PVOID pUsermodeVirtualAddress; -} MEMORY_ENTRY, *PMEMORY_ENTRY; - -typedef struct _POLL_REQUEST_DATA { - int events; - int timeout; - int revents; -} POLL_REQUEST_DATA; - -#endif /* _WIN32 */ - -/* - * FreeBSD uses the size value embedded in the _IOWR to determine - * how much to copy in/out. So we need it to match the actual - * data structure we pass. We put some spares in the structure - * to ease compatibility with other versions - */ -#define NIOCGINFO _IOWR('i', 145, struct nmreq) /* return IF info */ -#define NIOCREGIF _IOWR('i', 146, struct nmreq) /* interface register */ -#define NIOCTXSYNC _IO('i', 148) /* sync tx queues */ -#define NIOCRXSYNC _IO('i', 149) /* sync rx queues */ -#define NIOCCONFIG _IOWR('i', 150, struct nm_ifreq) /* for ext. modules */ -#endif /* !NIOCREGIF */ - -/* - * Helper functions for kernel and userspace - */ - -/* - * check if space is available in the ring. - */ -static inline int -nm_ring_empty(struct netmap_ring *ring) -{ - return (ring->cur == ring->tail); -} - -/* - * Opaque structure that is passed to an external kernel - * module via ioctl(fd, NIOCCONFIG, req) for a user-owned - * bridge port (at this point ephemeral VALE interface). - */ -#define NM_IFRDATA_LEN 256 -struct nm_ifreq { - char nifr_name[IFNAMSIZ]; - char data[NM_IFRDATA_LEN]; -}; - -#endif /* _NET_NETMAP_H_ */ diff --git a/devicemodel/include/netmap_user.h b/devicemodel/include/netmap_user.h deleted file mode 100644 index 77deb483f..000000000 --- a/devicemodel/include/netmap_user.h +++ /dev/null @@ -1,1078 +0,0 @@ -/* - * Copyright (C) 2011-2016 Universita` di Pisa - * 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$ - * - * Functions and macros to manipulate netmap structures and packets - * in userspace. See netmap(4) for more information. - * - * The address of the struct netmap_if, say nifp, is computed from the - * value returned from ioctl(.., NIOCREG, ...) and the mmap region: - * ioctl(fd, NIOCREG, &req); - * mem = mmap(0, ... ); - * nifp = NETMAP_IF(mem, req.nr_nifp); - * (so simple, we could just do it manually) - * - * From there: - * struct netmap_ring *NETMAP_TXRING(nifp, index) - * struct netmap_ring *NETMAP_RXRING(nifp, index) - * we can access ring->cur, ring->head, ring->tail, etc. - * - * ring->slot[i] gives us the i-th slot (we can access - * directly len, flags, buf_idx) - * - * char *buf = NETMAP_BUF(ring, x) returns a pointer to - * the buffer numbered x - * - * All ring indexes (head, cur, tail) should always move forward. - * To compute the next index in a circular ring you can use - * i = nm_ring_next(ring, i); - * - * To ease porting apps from pcap to netmap we supply a few fuctions - * that can be called to open, close, read and write on netmap in a way - * similar to libpcap. Note that the read/write function depend on - * an ioctl()/select()/poll() being issued to refill rings or push - * packets out. - * - * In order to use these, include #define NETMAP_WITH_LIBS - * in the source file that invokes these functions. - */ - -#ifndef _NETMAP_USER_H_ -#define _NETMAP_USER_H_ - -#define NETMAP_DEVICE_NAME "/dev/netmap" - -#ifdef __CYGWIN__ -/* - * we can compile userspace apps with either cygwin or msvc, - * and we use _WIN32 to identify windows specific code - */ -#ifndef _WIN32 -#define _WIN32 -#endif /* _WIN32 */ - -#endif /* __CYGWIN__ */ - -#ifdef _WIN32 -#undef NETMAP_DEVICE_NAME -#define NETMAP_DEVICE_NAME "/proc/sys/DosDevices/Global/netmap" -#include -#include -#include -#endif /* _WIN32 */ - -#include -#include /* apple needs sockaddr */ -#include /* IFNAMSIZ */ -#include - -#ifndef likely -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) -#endif /* likely and unlikely */ - -#include "netmap.h" - -/* helper macro */ -#define _NETMAP_OFFSET(type, ptr, offset) \ - ((type)(void *)((char *)(ptr) + (offset))) - -#define NETMAP_IF(_base, _ofs) _NETMAP_OFFSET(struct netmap_if *, _base, _ofs) - -#define NETMAP_TXRING(nifp, index) _NETMAP_OFFSET(struct netmap_ring *, \ - nifp, (nifp)->ring_ofs[index]) - -#define NETMAP_RXRING(nifp, index) _NETMAP_OFFSET(struct netmap_ring *, \ - nifp, (nifp)->ring_ofs[index + (nifp)->ni_tx_rings + 1]) - -#define NETMAP_BUF(ring, index) \ - ((char *)(ring) + (ring)->buf_ofs + ((index)*(ring)->nr_buf_size)) - -#define NETMAP_BUF_IDX(ring, buf) \ - (((char *)(buf) - ((char *)(ring) + (ring)->buf_ofs)) / \ - (ring)->nr_buf_size) - -static inline uint32_t -nm_ring_next(struct netmap_ring *r, uint32_t i) -{ - return unlikely(i + 1 == r->num_slots) ? 0 : i + 1; -} - -/* - * Return 1 if we have pending transmissions in the tx ring. - * When everything is complete ring->head = ring->tail + 1 (modulo ring size) - */ -static inline int -nm_tx_pending(struct netmap_ring *r) -{ - return nm_ring_next(r, r->tail) != r->head; -} - -static inline uint32_t -nm_ring_space(struct netmap_ring *ring) -{ - int ret = ring->tail - ring->cur; - - if (ret < 0) - ret += ring->num_slots; - return ret; -} - -#ifdef NETMAP_WITH_LIBS -/* - * Support for simple I/O libraries. - * Include other system headers required for compiling this. - */ - -#ifndef HAVE_NETMAP_WITH_LIBS -#define HAVE_NETMAP_WITH_LIBS - -#include -#include -#include -#include /* memset */ -#include -#include /* EINVAL */ -#include /* O_RDWR */ -#include /* close() */ -#include -#include - -#ifndef ND /* debug macros */ -/* debug support */ -#define ND(_fmt, ...) do {} while (0) -#define D(_fmt, ...) \ - do { \ - struct timeval _t0; \ - gettimeofday(&_t0, NULL); \ - fprintf(stderr, "%03d.%06d %s [%d] " _fmt "\n", \ - (int)(_t0.tv_sec % 1000), (int)_t0.tv_usec, \ - __func__, __LINE__, ##__VA_ARGS__); \ - } while (0) - -/* Rate limited version of "D", lps indicates how many per second */ -#define RD(lps, format, ...) \ - do { \ - static int __t0, __cnt; \ - struct timeval __xxts; \ - gettimeofday(&__xxts, NULL); \ - if (__t0 != __xxts.tv_sec) { \ - __t0 = __xxts.tv_sec; \ - __cnt = 0; \ - } \ - if (__cnt++ < lps) { \ - D(format, ##__VA_ARGS__); \ - } \ - } while (0) -#endif - -struct nm_pkthdr { /* first part is the same as pcap_pkthdr */ - struct timeval ts; - uint32_t caplen; - uint32_t len; - - uint64_t flags; /* NM_MORE_PKTS etc */ -#define NM_MORE_PKTS 1 - struct nm_desc *d; - struct netmap_slot *slot; - uint8_t *buf; -}; - -struct nm_stat { /* same as pcap_stat */ - u_int ps_recv; - u_int ps_drop; - u_int ps_ifdrop; -#ifdef WIN32 /* XXX or _WIN32 ? */ - u_int bs_capt; -#endif /* WIN32 */ -}; - -#define NM_ERRBUF_SIZE 512 - -struct nm_desc { - struct nm_desc *self; /* point to self if netmap. */ - int fd; - void *mem; - uint32_t memsize; - int done_mmap; /* set if mem is the result of mmap */ - struct netmap_if * const nifp; - uint16_t first_tx_ring, last_tx_ring, cur_tx_ring; - uint16_t first_rx_ring, last_rx_ring, cur_rx_ring; - struct nmreq req; /* also contains the nr_name = ifname */ - struct nm_pkthdr hdr; - - /* - * The memory contains netmap_if, rings and then buffers. - * Given a pointer (e.g. to nm_inject) we can compare with - * mem/buf_start/buf_end to tell if it is a buffer or - * some other descriptor in our region. - * We also store a pointer to some ring as it helps in the - * translation from buffer indexes to addresses. - */ - struct netmap_ring * const some_ring; - void * const buf_start; - void * const buf_end; - /* parameters from pcap_open_live */ - int snaplen; - int promisc; - int to_ms; - char *errbuf; - - /* save flags so we can restore them on close */ - uint32_t if_flags; - uint32_t if_reqcap; - uint32_t if_curcap; - - struct nm_stat st; - char msg[NM_ERRBUF_SIZE]; -}; - -/* - * when the descriptor is open correctly, d->self == d - * Eventually we should also use some magic number. - */ -#define P2NMD(p) ((struct nm_desc *)(p)) -#define IS_NETMAP_DESC(d) ((d) && P2NMD(d)->self == P2NMD(d)) -#define NETMAP_FD(d) (P2NMD(d)->fd) - -/* - * this is a slightly optimized copy routine which rounds - * to multiple of 64 bytes and is often faster than dealing - * with other odd sizes. We assume there is enough room - * in the source and destination buffers. - * - * XXX only for multiples of 64 bytes, non overlapped. - */ -static inline void -nm_pkt_copy(const void *_src, void *_dst, int l) -{ - const uint64_t *src = (const uint64_t *)_src; - uint64_t *dst = (uint64_t *)_dst; - - if (unlikely(l >= 1024)) { - memcpy(dst, src, l); - return; - } - for (; likely(l > 0); l -= 64) { - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - } -} - -/* - * The callback, invoked on each received packet. Same as libpcap - */ -typedef void (*nm_cb_t)(u_char *, const struct nm_pkthdr *, const u_char *d); - -/* - *--- the pcap-like API --- - * - * nm_open() opens a file descriptor, binds to a port and maps memory. - * - * ifname (netmap:foo or vale:foo) is the port name - * a suffix can indicate the follwing: - * ^ bind the host (sw) ring pair - * * bind host and NIC ring pairs (transparent) - * -NN bind individual NIC ring pair - * {NN bind master side of pipe NN - * }NN bind slave side of pipe NN - * a suffix starting with / and the following flags, - * in any order: - * x exclusive access - * z zero copy monitor - * t monitor tx side - * r monitor rx side - * R bind only RX ring(s) - * T bind only TX ring(s) - * - * req provides the initial values of nmreq before parsing ifname. - * Remember that the ifname parsing will override the ring - * number in nm_ringid, and part of nm_flags; - * flags special functions, normally 0 - * indicates which fields of *arg are significant - * arg special functions, normally NULL - * if passed a netmap_desc with mem != NULL, - * use that memory instead of mmap. - */ -static struct nm_desc *nm_open(const char *ifname, const struct nmreq *req, - uint64_t flags, const struct nm_desc *arg); - -/* - * nm_open can import some fields from the parent descriptor. - * These flags control which ones. - * Also in flags you can specify NETMAP_NO_TX_POLL and NETMAP_DO_RX_POLL, - * which set the initial value for these flags. - * Note that the 16 low bits of the flags are reserved for data - * that may go into the nmreq. - */ -enum { - NM_OPEN_NO_MMAP = 0x040000, /* reuse mmap from parent */ - NM_OPEN_IFNAME = 0x080000, /* nr_name, nr_ringid, nr_flags */ - NM_OPEN_ARG1 = 0x100000, - NM_OPEN_ARG2 = 0x200000, - NM_OPEN_ARG3 = 0x400000, - NM_OPEN_RING_CFG = 0x800000, /* tx|rx rings|slots */ -}; - - -/* - * nm_close() closes and restores the port to its previous state - */ -static int nm_close(struct nm_desc *); - -/* - * nm_mmap() do mmap or inherit from parent if the nr_arg2 - * (memory block) matches. - */ -static int nm_mmap(struct nm_desc *, const struct nm_desc *); - -/* - * nm_inject() is the same as pcap_inject() - * nm_dispatch() is the same as pcap_dispatch() - * nm_nextpkt() is the same as pcap_next() - */ -static int nm_inject(struct nm_desc *, const void *, size_t); -static int nm_dispatch(struct nm_desc *, int, nm_cb_t, u_char *); -static u_char *nm_nextpkt(struct nm_desc *, struct nm_pkthdr *); - -#ifdef _WIN32 - -intptr_t _get_osfhandle(int); /* defined in io.h in windows */ - -/* - * In windows we do not have yet native poll support, so we keep track - * of file descriptors associated to netmap ports to emulate poll on - * them and fall back on regular poll on other file descriptors. - */ -struct win_netmap_fd_list { - struct win_netmap_fd_list *next; - int win_netmap_fd; - HANDLE win_netmap_handle; -}; - -/* - * list head containing all the netmap opened fd and their - * windows HANDLE counterparts - */ -static struct win_netmap_fd_list *win_netmap_fd_list_head; - -static void -win_insert_fd_record(int fd) -{ - struct win_netmap_fd_list *curr; - - for (curr = win_netmap_fd_list_head; curr; curr = curr->next) { - if (fd == curr->win_netmap_fd) - return; - } - curr = calloc(1, sizeof(*curr)); - curr->next = win_netmap_fd_list_head; - curr->win_netmap_fd = fd; - curr->win_netmap_handle = IntToPtr(_get_osfhandle(fd)); - win_netmap_fd_list_head = curr; -} - -void -win_remove_fd_record(int fd) -{ - struct win_netmap_fd_list *curr = win_netmap_fd_list_head; - struct win_netmap_fd_list *prev = NULL; - - for (; curr ; prev = curr, curr = curr->next) { - if (fd != curr->win_netmap_fd) - continue; - /* found the entry */ - if (prev == NULL) { /* we are freeing the first entry */ - win_netmap_fd_list_head = curr->next; - } else { - prev->next = curr->next; - } - free(curr); - break; - } -} - -HANDLE -win_get_netmap_handle(int fd) -{ - struct win_netmap_fd_list *curr; - - for (curr = win_netmap_fd_list_head; curr; curr = curr->next) { - if (fd == curr->win_netmap_fd) - return curr->win_netmap_handle; - } - return NULL; -} - -/* - * we need to wrap ioctl and mmap, at least for the netmap file descriptors - */ - -/* - * use this function only from netmap_user.h internal functions - * same as ioctl, returns 0 on success and -1 on error - */ -static int -win_nm_ioctl_internal(HANDLE h, int32_t ctlCode, void *arg) -{ - DWORD bReturn = 0, szIn, szOut; - BOOL ioctlReturnStatus; - void *inParam = arg, *outParam = arg; - - switch (ctlCode) { - case NETMAP_POLL: - szIn = sizeof(POLL_REQUEST_DATA); - szOut = sizeof(POLL_REQUEST_DATA); - break; - case NETMAP_MMAP: - szIn = 0; - szOut = sizeof(void *); - inParam = NULL; /* nothing on input */ - break; - case NIOCTXSYNC: - case NIOCRXSYNC: - szIn = 0; - szOut = 0; - break; - case NIOCREGIF: - szIn = sizeof(struct nmreq); - szOut = sizeof(struct nmreq); - break; - case NIOCCONFIG: - D("unsupported NIOCCONFIG!"); - return -1; - - default: /* a regular ioctl */ - D("invalid ioctl %x on netmap fd", ctlCode); - return -1; - } - - ioctlReturnStatus = DeviceIoControl(h, - ctlCode, inParam, szIn, - outParam, szOut, - &bReturn, NULL); - /* XXX note windows returns 0 on error or async call, 1 on success */ - /* we could call GetLastError() to figure out what happened */ - return ioctlReturnStatus ? 0 : -1; -} - -/* - * this function is what must be called from user-space programs - * same as ioctl, returns 0 on success and -1 on error - */ -static int -win_nm_ioctl(int fd, int32_t ctlCode, void *arg) -{ - HANDLE h = win_get_netmap_handle(fd); - - if (h == NULL) - return ioctl(fd, ctlCode, arg); - else - return win_nm_ioctl_internal(h, ctlCode, arg); -} - -#define ioctl win_nm_ioctl /* from now on, within this file ... */ - -/* - * We cannot use the native mmap on windows - * The only parameter used is "fd", the other ones are just declared to - * make this signature comparable to the FreeBSD/Linux one - */ -static void * -win32_mmap_emulated(void *addr, size_t length, int prot, int flags, int fd, - int32_t offset) -{ - HANDLE h = win_get_netmap_handle(fd); - - if (h == NULL) - return mmap(addr, length, prot, flags, fd, offset); - - MEMORY_ENTRY ret; - - return win_nm_ioctl_internal(h, NETMAP_MMAP, &ret) ? - NULL : ret.pUsermodeVirtualAddress; -} - -#define mmap win32_mmap_emulated - -#include /* XXX needed to use the structure pollfd */ - -static int -win_nm_poll(struct pollfd *fds, int nfds, int timeout) -{ - HANDLE h; - - h = win_get_netmap_handle(fds->fd); - if (nfds != 1 || fds == NULL || h == NULL) - return poll(fds, nfds, timeout); - - POLL_REQUEST_DATA prd; - - prd.timeout = timeout; - prd.events = fds->events; - - win_nm_ioctl_internal(h, NETMAP_POLL, &prd); - if ((prd.revents == POLLERR) || (prd.revents == STATUS_TIMEOUT)) - return -1; - - return 1; -} - -#define poll win_nm_poll - -static int -win_nm_open(char *pathname, int flags) -{ - if (strcmp(pathname, NETMAP_DEVICE_NAME) == 0) { - int fd = open(NETMAP_DEVICE_NAME, O_RDWR); - - if (fd < 0) - return -1; - - win_insert_fd_record(fd); - return fd; - } else { - return open(pathname, flags); - } -} - -#define open win_nm_open - -static int -win_nm_close(int fd) -{ - if (fd != -1) { - close(fd); - if (win_get_netmap_handle(fd) != NULL) - win_remove_fd_record(fd); - } - return 0; -} - -#define close win_nm_close - -#endif /* _WIN32 */ - -static int -nm_is_identifier(const char *s, const char *e) -{ - for (; s != e; s++) { - if (!isalnum(*s) && *s != '_') - return 0; - } - - return 1; -} - -/* - * Try to open, return descriptor if successful, NULL otherwise. - * An invalid netmap name will return errno = 0; - * You can pass a pointer to a pre-filled nm_desc to add special - * parameters. Flags is used as follows - * NM_OPEN_NO_MMAP use the memory from arg, only XXX avoid mmap - * if the nr_arg2 (memory block) matches. - * NM_OPEN_ARG1 use req.nr_arg1 from arg - * NM_OPEN_ARG2 use req.nr_arg2 from arg - * NM_OPEN_RING_CFG user ring config from arg - */ -static struct nm_desc * -nm_open(const char *ifname, const struct nmreq *req, - uint64_t new_flags, const struct nm_desc *arg) -{ - struct nm_desc *d = NULL; - const struct nm_desc *parent = arg; - u_int namelen; - uint32_t nr_ringid = 0, nr_flags, nr_reg; - const char *port = NULL; - const char *vpname = NULL; -#define MAXERRMSG 80 - char errmsg[MAXERRMSG] = ""; - enum { P_START, P_RNGSFXOK, P_GETNUM, P_FLAGS, P_FLAGSOK } p_state; - int is_vale; - long num; - - if (strncmp(ifname, "netmap:", 7) && - strncmp(ifname, NM_BDG_NAME, strlen(NM_BDG_NAME))) { - errno = 0; /* name not recognised, not an error */ - return NULL; - } - - is_vale = (ifname[0] == 'v'); - if (is_vale) { - port = index(ifname, ':'); - if (port == NULL) { - snprintf(errmsg, MAXERRMSG, - "missing ':' in vale name"); - goto fail; - } - - if (!nm_is_identifier(ifname + 4, port)) { - snprintf(errmsg, MAXERRMSG, "invalid bridge name"); - goto fail; - } - - vpname = ++port; - } else { - ifname += 7; - port = ifname; - } - - /* scan for a separator */ - for (; *port && !index("-*^{}/", *port); port++) - ; - - if (is_vale && !nm_is_identifier(vpname, port)) { - snprintf(errmsg, MAXERRMSG, "invalid bridge port name"); - goto fail; - } - - namelen = port - ifname; - if (namelen >= sizeof(d->req.nr_name)) { - snprintf(errmsg, MAXERRMSG, "name too long"); - goto fail; - } - p_state = P_START; - nr_flags = NR_REG_ALL_NIC; /* default for no suffix */ - while (*port) { - switch (p_state) { - case P_START: - switch (*port) { - case '^': /* only SW ring */ - nr_flags = NR_REG_SW; - p_state = P_RNGSFXOK; - break; - case '*': /* NIC and SW */ - nr_flags = NR_REG_NIC_SW; - p_state = P_RNGSFXOK; - break; - case '-': /* one NIC ring pair */ - nr_flags = NR_REG_ONE_NIC; - p_state = P_GETNUM; - break; - case '{': /* pipe (master endpoint) */ - nr_flags = NR_REG_PIPE_MASTER; - p_state = P_GETNUM; - break; - case '}': /* pipe (slave endoint) */ - nr_flags = NR_REG_PIPE_SLAVE; - p_state = P_GETNUM; - break; - case '/': /* start of flags */ - p_state = P_FLAGS; - break; - default: - snprintf(errmsg, MAXERRMSG, - "unknown modifier: '%c'", *port); - goto fail; - } - port++; - break; - case P_RNGSFXOK: - switch (*port) { - case '/': - p_state = P_FLAGS; - break; - default: - snprintf(errmsg, MAXERRMSG, - "unexpected character: '%c'", *port); - goto fail; - } - port++; - break; - case P_GETNUM: - num = strtol(port, (char **)&port, 10); - if (num < 0 || num >= NETMAP_RING_MASK) { - snprintf(errmsg, MAXERRMSG, "'%ld' out of range" - "[0, %d)", num, NETMAP_RING_MASK); - goto fail; - } - nr_ringid = num & NETMAP_RING_MASK; - p_state = P_RNGSFXOK; - break; - case P_FLAGS: - case P_FLAGSOK: - switch (*port) { - case 'x': - nr_flags |= NR_EXCLUSIVE; - break; - case 'z': - nr_flags |= NR_ZCOPY_MON; - break; - case 't': - nr_flags |= NR_MONITOR_TX; - break; - case 'r': - nr_flags |= NR_MONITOR_RX; - break; - case 'R': - nr_flags |= NR_RX_RINGS_ONLY; - break; - case 'T': - nr_flags |= NR_TX_RINGS_ONLY; - break; - default: - snprintf(errmsg, MAXERRMSG, "unrecognized " - "flag: '%c'", *port); - goto fail; - } - port++; - p_state = P_FLAGSOK; - break; - } - } - if (p_state != P_START && p_state != P_RNGSFXOK && - p_state != P_FLAGSOK) { - snprintf(errmsg, MAXERRMSG, "unexpected end of port name"); - goto fail; - } - if ((nr_flags & NR_ZCOPY_MON) && - !(nr_flags & (NR_MONITOR_TX|NR_MONITOR_RX))) { - snprintf(errmsg, MAXERRMSG, - "'z' used but neither 'r', nor 't' found"); - goto fail; - } - ND("flags: %s %s %s %s", - (nr_flags & NR_EXCLUSIVE) ? "EXCLUSIVE" : "", - (nr_flags & NR_ZCOPY_MON) ? "ZCOPY_MON" : "", - (nr_flags & NR_MONITOR_TX) ? "MONITOR_TX" : "", - (nr_flags & NR_MONITOR_RX) ? "MONITOR_RX" : ""); - d = (struct nm_desc *)calloc(1, sizeof(*d)); - if (d == NULL) { - snprintf(errmsg, MAXERRMSG, "nm_desc alloc failure"); - errno = ENOMEM; - return NULL; - } - d->self = d; /* set this early so nm_close() works */ - d->fd = open(NETMAP_DEVICE_NAME, O_RDWR); - if (d->fd < 0) { - snprintf(errmsg, MAXERRMSG, "cannot open /dev/netmap: %s", - strerror(errno)); - goto fail; - } - - if (req) - d->req = *req; - d->req.nr_version = NETMAP_API; - d->req.nr_ringid &= ~NETMAP_RING_MASK; - - /* these fields are overridden by ifname and flags processing */ - d->req.nr_ringid |= nr_ringid; - d->req.nr_flags |= nr_flags; - memcpy(d->req.nr_name, ifname, namelen); - d->req.nr_name[namelen] = '\0'; - /* optionally import info from parent */ - if (IS_NETMAP_DESC(parent) && new_flags) { - if (new_flags & NM_OPEN_ARG1) - D("overriding ARG1 %d", parent->req.nr_arg1); - d->req.nr_arg1 = new_flags & NM_OPEN_ARG1 ? - parent->req.nr_arg1 : 4; - if (new_flags & NM_OPEN_ARG2) - D("overriding ARG2 %d", parent->req.nr_arg2); - d->req.nr_arg2 = new_flags & NM_OPEN_ARG2 ? - parent->req.nr_arg2 : 0; - if (new_flags & NM_OPEN_ARG3) - D("overriding ARG3 %d", parent->req.nr_arg3); - d->req.nr_arg3 = new_flags & NM_OPEN_ARG3 ? - parent->req.nr_arg3 : 0; - if (new_flags & NM_OPEN_RING_CFG) { - D("overriding RING_CFG"); - d->req.nr_tx_slots = parent->req.nr_tx_slots; - d->req.nr_rx_slots = parent->req.nr_rx_slots; - d->req.nr_tx_rings = parent->req.nr_tx_rings; - d->req.nr_rx_rings = parent->req.nr_rx_rings; - } - if (new_flags & NM_OPEN_IFNAME) { - D("overriding ifname %s ringid 0x%x flags 0x%x", - parent->req.nr_name, parent->req.nr_ringid, - parent->req.nr_flags); - memcpy(d->req.nr_name, parent->req.nr_name, - sizeof(d->req.nr_name)); - d->req.nr_ringid = parent->req.nr_ringid; - d->req.nr_flags = parent->req.nr_flags; - } - } - /* add the *XPOLL flags */ - d->req.nr_ringid |= new_flags & (NETMAP_NO_TX_POLL | NETMAP_DO_RX_POLL); - - if (ioctl(d->fd, NIOCREGIF, &d->req)) { - snprintf(errmsg, MAXERRMSG, "NIOCREGIF failed: %s", - strerror(errno)); - goto fail; - } - - /* if parent is defined, do nm_mmap() even if NM_OPEN_NO_MMAP is set */ - if ((!(new_flags & NM_OPEN_NO_MMAP) || parent) && nm_mmap(d, parent)) { - snprintf(errmsg, MAXERRMSG, "mmap failed: %s", strerror(errno)); - goto fail; - } - - nr_reg = d->req.nr_flags & NR_REG_MASK; - - if (nr_reg == NR_REG_SW) { /* host stack */ - d->first_tx_ring = d->last_tx_ring = d->req.nr_tx_rings; - d->first_rx_ring = d->last_rx_ring = d->req.nr_rx_rings; - } else if (nr_reg == NR_REG_ALL_NIC) { /* only nic */ - d->first_tx_ring = 0; - d->first_rx_ring = 0; - d->last_tx_ring = d->req.nr_tx_rings - 1; - d->last_rx_ring = d->req.nr_rx_rings - 1; - } else if (nr_reg == NR_REG_NIC_SW) { - d->first_tx_ring = 0; - d->first_rx_ring = 0; - d->last_tx_ring = d->req.nr_tx_rings; - d->last_rx_ring = d->req.nr_rx_rings; - } else if (nr_reg == NR_REG_ONE_NIC) { - /* XXX check validity */ - d->first_tx_ring = d->last_tx_ring = - d->first_rx_ring = d->last_rx_ring = - d->req.nr_ringid & NETMAP_RING_MASK; - } else { /* pipes */ - d->first_tx_ring = d->last_tx_ring = 0; - d->first_rx_ring = d->last_rx_ring = 0; - } - -#ifdef DEBUG_NETMAP_USER - { /* debugging code */ - int i; - - D("%s tx %d .. %d %d rx %d .. %d %d", ifname, - d->first_tx_ring, d->last_tx_ring, d->req.nr_tx_rings, - d->first_rx_ring, d->last_rx_ring, d->req.nr_rx_rings); - for (i = 0; i <= d->req.nr_tx_rings; i++) { - struct netmap_ring *r = NETMAP_TXRING(d->nifp, i); - - D("TX%d %p h %d c %d t %d", i, r, r->head, r->cur, r->tail); - } - for (i = 0; i <= d->req.nr_rx_rings; i++) { - struct netmap_ring *r = NETMAP_RXRING(d->nifp, i); - - D("RX%d %p h %d c %d t %d", i, r, r->head, r->cur, r->tail); - } - } -#endif /* debugging */ - - d->cur_tx_ring = d->first_tx_ring; - d->cur_rx_ring = d->first_rx_ring; - return d; - -fail: - nm_close(d); - if (errmsg[0]) - D("%s %s", errmsg, ifname); - if (errno == 0) - errno = EINVAL; - return NULL; -} - -static int -nm_close(struct nm_desc *d) -{ - /* - * ugly trick to avoid unused warnings - */ - static void *__xxzt[] __attribute__ ((unused)) = { - (void *)nm_open, (void *)nm_inject, - (void *)nm_dispatch, (void *)nm_nextpkt }; - - if (d == NULL || d->self != d) - return -1; - if (d->done_mmap && d->mem) - munmap(d->mem, d->memsize); - if (d->fd != -1) - close(d->fd); - - bzero(d, sizeof(*d)); - free(d); - return 0; -} - -static int -nm_mmap(struct nm_desc *d, const struct nm_desc *parent) -{ - /* XXX TODO: check if mmap is already done */ - if (IS_NETMAP_DESC(parent) && parent->mem && - parent->req.nr_arg2 == d->req.nr_arg2) { - /* do not mmap, inherit from parent */ - D("do not mmap, inherit from parent"); - d->memsize = parent->memsize; - d->mem = parent->mem; - } else { - /* XXX TODO: check if memsize is too large (or there - * is overflow) - */ - d->memsize = d->req.nr_memsize; - d->mem = mmap(0, d->memsize, PROT_WRITE | PROT_READ, MAP_SHARED, - d->fd, 0); - if (d->mem == MAP_FAILED) - goto fail; - d->done_mmap = 1; - } - { - struct netmap_if *nifp = NETMAP_IF(d->mem, d->req.nr_offset); - struct netmap_ring *r = NETMAP_RXRING(nifp, 0); - - *(struct netmap_if **)(uintptr_t)&(d->nifp) = nifp; - *(struct netmap_ring **)(uintptr_t)&d->some_ring = r; - *(void **)(uintptr_t)&d->buf_start = NETMAP_BUF(r, 0); - *(void **)(uintptr_t)&d->buf_end = - (char *)d->mem + d->memsize; - } - - return 0; - -fail: - return -1; -} - -/* - * Same prototype as pcap_inject(), only need to cast. - */ -static int -nm_inject(struct nm_desc *d, const void *buf, size_t size) -{ - u_int c, n = d->last_tx_ring - d->first_tx_ring + 1; - - for (c = 0; c < n ; c++) { - /* compute current ring to use */ - struct netmap_ring *ring; - uint32_t i, idx; - uint32_t ri = d->cur_tx_ring + c; - - if (ri > d->last_tx_ring) - ri = d->first_tx_ring; - ring = NETMAP_TXRING(d->nifp, ri); - if (nm_ring_empty(ring)) - continue; - i = ring->cur; - idx = ring->slot[i].buf_idx; - ring->slot[i].len = size; - nm_pkt_copy(buf, NETMAP_BUF(ring, idx), size); - d->cur_tx_ring = ri; - ring->head = ring->cur = nm_ring_next(ring, i); - return size; - } - return 0; /* fail */ -} - - -/* - * Same prototype as pcap_dispatch(), only need to cast. - */ -static int -nm_dispatch(struct nm_desc *d, int cnt, nm_cb_t cb, u_char *arg) -{ - int n = d->last_rx_ring - d->first_rx_ring + 1; - int c, got = 0, ri = d->cur_rx_ring; - - d->hdr.buf = NULL; - d->hdr.flags = NM_MORE_PKTS; - d->hdr.d = d; - - if (cnt == 0) - cnt = -1; - /* cnt == -1 means infinite, but rings have a finite amount - * of buffers and the int is large enough that we never wrap, - * so we can omit checking for -1 - */ - for (c = 0; c < n && cnt != got; c++) { - /* compute current ring to use */ - struct netmap_ring *ring; - - ri = d->cur_rx_ring + c; - if (ri > d->last_rx_ring) - ri = d->first_rx_ring; - ring = NETMAP_RXRING(d->nifp, ri); - for ( ; !nm_ring_empty(ring) && cnt != got; got++) { - u_int idx, i; - - if (d->hdr.buf) { /* from previous round */ - cb(arg, &d->hdr, d->hdr.buf); - } - i = ring->cur; - idx = ring->slot[i].buf_idx; - d->hdr.slot = &ring->slot[i]; - d->hdr.buf = (u_char *)NETMAP_BUF(ring, idx); - /* __builtin_prefetch(buf); */ - d->hdr.len = d->hdr.caplen = ring->slot[i].len; - d->hdr.ts = ring->ts; - ring->head = ring->cur = nm_ring_next(ring, i); - } - } - if (d->hdr.buf) { /* from previous round */ - d->hdr.flags = 0; - cb(arg, &d->hdr, d->hdr.buf); - } - d->cur_rx_ring = ri; - return got; -} - -static u_char * -nm_nextpkt(struct nm_desc *d, struct nm_pkthdr *hdr) -{ - int ri = d->cur_rx_ring; - - do { - /* compute current ring to use */ - struct netmap_ring *ring = NETMAP_RXRING(d->nifp, ri); - - if (!nm_ring_empty(ring)) { - u_int i = ring->cur; - u_int idx = ring->slot[i].buf_idx; - u_char *buf = (u_char *)NETMAP_BUF(ring, idx); - - /* __builtin_prefetch(buf); */ - hdr->ts = ring->ts; - hdr->len = hdr->caplen = ring->slot[i].len; - ring->cur = nm_ring_next(ring, i); - /* we could postpone advancing head if we want - * to hold the buffer. This can be supported in - * the future. - */ - ring->head = ring->cur; - d->cur_rx_ring = ri; - return buf; - } - ri++; - if (ri > d->last_rx_ring) - ri = d->first_rx_ring; - } while (ri != d->cur_rx_ring); - return NULL; /* nothing found */ -} - -#endif /* !HAVE_NETMAP_WITH_LIBS */ - -#endif /* NETMAP_WITH_LIBS */ - -#endif /* _NETMAP_USER_H_ */ diff --git a/devicemodel/include/pcireg.h b/devicemodel/include/pcireg.h index 8db1a518a..a9c90f573 100644 --- a/devicemodel/include/pcireg.h +++ b/devicemodel/include/pcireg.h @@ -87,7 +87,7 @@ #define PCIR_COMMAND 0x04 #define PCIM_CMD_PORTEN 0x0001 #define PCIM_CMD_MEMEN 0x0002 -#define PCIM_CMD_BUSMASTEREN 0x0004 +#define PCIM_CMD_BUSHOSTEN 0x0004 #define PCIM_CMD_SPECIALEN 0x0008 #define PCIM_CMD_MWRICEN 0x0010 #define PCIM_CMD_PERRESPEN 0x0040 @@ -322,7 +322,7 @@ #define PCIP_STORAGE_IDE_PROGINDPRIM 0x02 #define PCIP_STORAGE_IDE_MODESEC 0x04 #define PCIP_STORAGE_IDE_PROGINDSEC 0x08 -#define PCIP_STORAGE_IDE_MASTERDEV 0x80 +#define PCIP_STORAGE_IDE_HOSTDEV 0x80 #define PCIS_STORAGE_FLOPPY 0x02 #define PCIS_STORAGE_IPI 0x03 #define PCIS_STORAGE_RAID 0x04 @@ -493,7 +493,7 @@ #define PCIB_BCR_SERR_ENABLE 0x0002 #define PCIB_BCR_ISA_ENABLE 0x0004 #define PCIB_BCR_VGA_ENABLE 0x0008 -#define PCIB_BCR_MASTER_ABORT_MODE 0x0020 +#define PCIB_BCR_HOST_ABORT_MODE 0x0020 #define PCIB_BCR_SECBUS_RESET 0x0040 #define PCIB_BCR_SECBUS_BACKTOBACK 0x0080 #define PCIB_BCR_PRI_DISCARD_TIMEOUT 0x0100 @@ -505,7 +505,7 @@ #define CBB_BCR_SERR_ENABLE 0x0002 #define CBB_BCR_ISA_ENABLE 0x0004 #define CBB_BCR_VGA_ENABLE 0x0008 -#define CBB_BCR_MASTER_ABORT_MODE 0x0020 +#define CBB_BCR_HOST_ABORT_MODE 0x0020 #define CBB_BCR_CARDBUS_RESET 0x0040 #define CBB_BCR_IREQ_INT_ENABLE 0x0080 #define CBB_BCR_PREFETCH_0_ENABLE 0x0100 @@ -717,7 +717,7 @@ /* HT (HyperTransport) Capability definitions */ #define PCIR_HT_COMMAND 0x2 #define PCIM_HTCMD_CAP_MASK 0xf800 /* Capability type. */ -#define PCIM_HTCAP_SLAVE 0x0000 /* 000xx */ +#define PCIM_HTCAP_CLIENT 0x0000 /* 000xx */ #define PCIM_HTCAP_HOST 0x2000 /* 001xx */ #define PCIM_HTCAP_SWITCH 0x4000 /* 01000 */ #define PCIM_HTCAP_INTERRUPT 0x8000 /* 10000 */