diff options
author | Maxim Uvarov <maxim.uvarov@linaro.org> | 2014-09-26 19:19:44 +0400 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2014-10-01 14:48:41 +0400 |
commit | 96518b7daa0de16180712e01c2cc364966ef229d (patch) | |
tree | 421f98e04d3e16d377c394ad8c56a3788bba7f6f /platform | |
parent | daad3c3e4a853d0f4a759cd7350979e2a04555dd (diff) |
git split: delete netmap
netmap will be developed and supported in different git repo:
https://git.linaro.org/lng/odp-netmap.git
netmap will be separate odp platform.
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform')
-rw-r--r-- | platform/linux-generic/Makefile.am | 6 | ||||
-rw-r--r-- | platform/linux-generic/odp_packet_io.c | 39 | ||||
-rw-r--r-- | platform/linux-generic/odp_packet_netmap.c | 453 |
3 files changed, 0 insertions, 498 deletions
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 25c82eac4..5b3c8798e 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -37,7 +37,6 @@ include_HEADERS = \ $(top_srcdir)/platform/linux-generic/include/api/odp_timer.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_version.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_pktio_types.h \ - $(top_srcdir)/platform/linux-generic/include/api/odp_pktio_netmap.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_pktio_socket.h subdirheadersdir = $(includedir)/helper @@ -73,8 +72,3 @@ __LIB__libodp_la_SOURCES = \ odp_ticketlock.c \ odp_time.c \ odp_timer.c - -if ODP_NETMAP_ENABLED -__LIB__libodp_la_SOURCES += \ - odp_packet_netmap.c -endif diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 06d89350c..c06653fef 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -13,9 +13,6 @@ #include <odp_spinlock.h> #include <odp_shared_memory.h> #include <odp_packet_socket.h> -#ifdef ODP_HAVE_NETMAP -#include <odp_packet_netmap.h> -#endif #include <odp_hints.h> #include <odp_config.h> #include <odp_queue_internal.h> @@ -23,9 +20,6 @@ #include <odp_debug.h> #include <odp_pktio_socket.h> -#ifdef ODP_HAVE_NETMAP -#include <odp_pktio_netmap.h> -#endif #include <string.h> @@ -192,11 +186,6 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool, case ODP_PKTIO_TYPE_SOCKET_MMAP: ODP_DBG("Allocating socket pktio\n"); break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - ODP_DBG("Allocating netmap pktio\n"); - break; -#endif default: ODP_ERR("Invalid pktio type: %02x\n", params->type); return ODP_PKTIO_INVALID; @@ -230,18 +219,6 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool, id = ODP_PKTIO_INVALID; } break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - - res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev, - pool, ¶ms->nm_params); - if (res == -1) { - close_pkt_netmap(&pktio_entry->s.pkt_nm); - free_pktio_entry(id); - id = ODP_PKTIO_INVALID; - } - break; -#endif default: free_pktio_entry(id); id = ODP_PKTIO_INVALID; @@ -272,11 +249,6 @@ int odp_pktio_close(odp_pktio_t id) case ODP_PKTIO_TYPE_SOCKET_MMAP: res = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap); break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - res = close_pkt_netmap(&entry->s.pkt_nm); - break; -#endif default: break; res |= free_pktio_entry(id); @@ -323,11 +295,6 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, pkt_table, len); break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - pkts = recv_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table, len); - break; -#endif default: pkts = -1; break; @@ -365,12 +332,6 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, pkt_table, len); break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, - pkt_table, len); - break; -#endif default: pkts = -1; } diff --git a/platform/linux-generic/odp_packet_netmap.c b/platform/linux-generic/odp_packet_netmap.c deleted file mode 100644 index 524492dc4..000000000 --- a/platform/linux-generic/odp_packet_netmap.c +++ /dev/null @@ -1,453 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * Copyright (c) 2013, Nokia Solutions and Networks - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* - * NETMAP I/O code inspired by the pkt-gen example application in netmap by: - * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved. - * Copyright (C) 2013-2014 Universita` di Pisa. All rights reserved. - */ - -#define _GNU_SOURCE -#include <stdio.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <poll.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <stdlib.h> - -#include <linux/ethtool.h> -#include <linux/sockios.h> - -#include <odp_packet_internal.h> -#include <odp_hints.h> -#include <odp_thread.h> - -#include <odph_eth.h> -#include <odph_ip.h> -#include <odph_packet.h> - -#define NETMAP_WITH_LIBS -#include <odp_packet_netmap.h> - -/** Eth buffer start offset from u32-aligned address to make sure the following - * header (e.g. IP) starts at a 32-bit aligned address. - */ -#define ETHBUF_OFFSET (ODP_ALIGN_ROUNDUP(ODPH_ETHHDR_LEN, sizeof(uint32_t)) \ - - ODPH_ETHHDR_LEN) - -/** Round up buffer address to get a properly aliged eth buffer, i.e. aligned - * so that the next header always starts at a 32bit aligned address. - */ -#define ETHBUF_ALIGN(buf_ptr) ((uint8_t *)ODP_ALIGN_ROUNDUP_PTR((buf_ptr), \ - sizeof(uint32_t)) + ETHBUF_OFFSET) - -#define ETH_PROMISC 1 /* TODO: maybe this should be exported to the user */ -#define WAITLINK_TMO 2 -#define POLL_TMO 50 - -static int nm_do_ioctl(pkt_netmap_t * const pkt_nm, unsigned long cmd, - int subcmd) -{ - struct ethtool_value eval; - struct ifreq ifr; - int error; - int fd; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - ODP_ERR("Error: cannot get device control socket\n"); - return -1; - } - - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, pkt_nm->ifname, sizeof(ifr.ifr_name)); - - switch (cmd) { - case SIOCSIFFLAGS: - ifr.ifr_flags = pkt_nm->if_flags & 0xffff; - break; - case SIOCETHTOOL: - eval.cmd = subcmd; - eval.data = 0; - ifr.ifr_data = (caddr_t)&eval; - break; - default: - break; - } - error = ioctl(fd, cmd, &ifr); - if (error) - goto done; - - switch (cmd) { - case SIOCGIFFLAGS: - pkt_nm->if_flags = (ifr.ifr_flags << 16) | - (0xffff & ifr.ifr_flags); - ODP_DBG("flags are 0x%x\n", pkt_nm->if_flags); - break; - default: - break; - } -done: - close(fd); - if (error) - ODP_ERR("ioctl err %d %lu: %s\n", error, cmd, strerror(errno)); - - return error; -} - -int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, - odp_buffer_pool_t pool, netmap_params_t *nm_params) -{ - char qname[ODP_QUEUE_NAME_LEN]; - char ifname[32]; - odp_packet_t pkt; - odp_buffer_t token; - uint8_t *pkt_buf; - uint16_t ringid; - uint8_t *l2_hdr; - int ret; - - if (pool == ODP_BUFFER_POOL_INVALID) - return -1; - pkt_nm->pool = pool; - - pkt = odph_packet_alloc(pool); - if (!odph_packet_is_valid(pkt)) - return -1; - - pkt_buf = odp_packet_buf_addr(pkt); - l2_hdr = ETHBUF_ALIGN(pkt_buf); - /* Store eth buffer offset for buffers from this pool */ - pkt_nm->frame_offset = (uintptr_t)l2_hdr - (uintptr_t)pkt_buf; - /* pkt buffer size */ - pkt_nm->buf_size = odph_packet_buf_size(pkt); - /* max frame len taking into account the l2-offset */ - pkt_nm->max_frame_len = pkt_nm->buf_size - pkt_nm->frame_offset; - /* save netmap_mode for later use */ - pkt_nm->netmap_mode = nm_params->netmap_mode; - - odph_packet_free(pkt); - - if (nm_params->netmap_mode == ODP_NETMAP_MODE_SW) - ringid = NETMAP_SW_RING; - else - ringid = nm_params->ringid; - - strncpy(pkt_nm->ifname, netdev, sizeof(pkt_nm->ifname)); - snprintf(ifname, sizeof(ifname), "netmap:%s", netdev); - pkt_nm->nm_desc = nm_open(ifname, NULL, ringid, 0); - - if (pkt_nm->nm_desc == NULL) { - ODP_ERR("Error opening nm interface: %s\n", strerror(errno)); - return -1; - } - - ODP_DBG("thread %d mode %s mmap addr %p\n", - odp_thread_id(), - nm_params->netmap_mode == ODP_NETMAP_MODE_SW ? "SW" : "HW", - pkt_nm->nm_desc->mem); - - if (nm_params->netmap_mode == ODP_NETMAP_MODE_SW) { - pkt_nm->begin = pkt_nm->nm_desc->req.nr_rx_rings; - pkt_nm->end = pkt_nm->begin + 1; - pkt_nm->rxring = NETMAP_RXRING(pkt_nm->nm_desc->nifp, - pkt_nm->nm_desc->req.nr_rx_rings); - pkt_nm->txring = NETMAP_TXRING(pkt_nm->nm_desc->nifp, - pkt_nm->nm_desc->req.nr_tx_rings); - } else if (nm_params->ringid & NETMAP_HW_RING) { - pkt_nm->begin = nm_params->ringid & NETMAP_RING_MASK; - pkt_nm->end = pkt_nm->begin + 1; - pkt_nm->rxring = NETMAP_RXRING(pkt_nm->nm_desc->nifp, - pkt_nm->begin); - pkt_nm->txring = NETMAP_TXRING(pkt_nm->nm_desc->nifp, - pkt_nm->begin); - } else { - pkt_nm->begin = 0; - pkt_nm->end = pkt_nm->nm_desc->req.nr_rx_rings; - pkt_nm->rxring = NETMAP_RXRING(pkt_nm->nm_desc->nifp, 0); - pkt_nm->txring = NETMAP_TXRING(pkt_nm->nm_desc->nifp, 0); - } - - /* Set TX checksumming if hardware rings */ - if (nm_params->netmap_mode == ODP_NETMAP_MODE_HW) { - ret = nm_do_ioctl(pkt_nm, SIOCGIFFLAGS, 0); - if (ret) - return ret; - if ((pkt_nm->if_flags & IFF_UP) == 0) { - ODP_DBG("%s is down, bringing up...\n", pkt_nm->ifname); - pkt_nm->if_flags |= IFF_UP; - } - if (ETH_PROMISC) { - pkt_nm->if_flags |= IFF_PROMISC; - nm_do_ioctl(pkt_nm, SIOCSIFFLAGS, 0); - } - ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_SGSO); - if (ret) - ODP_DBG("ETHTOOL_SGSO not supported\n"); - - ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_STSO); - if (ret) - ODP_DBG("ETHTOOL_STSO not supported\n"); - /* TODO: This seems to cause the app to not receive frames - * first time it is launched after netmap driver is inserted. - * Should be investigated further. - */ - /* - nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_SRXCSUM); - */ - ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_STXCSUM); - if (ret) - ODP_DBG("ETHTOOL_STXCSUM not supported\n"); - } - - /* Set up the TX access queue */ - snprintf(qname, sizeof(qname), "%s:%s-pktio_tx_access", netdev, - nm_params->netmap_mode == ODP_NETMAP_MODE_SW ? "SW" : "HW"); - pkt_nm->tx_access = odp_queue_create(qname, ODP_QUEUE_TYPE_POLL, NULL); - if (pkt_nm->tx_access == ODP_QUEUE_INVALID) { - ODP_ERR("Error: pktio queue creation failed\n"); - return -1; - } - token = odp_buffer_alloc(pool); - if (!odp_buffer_is_valid(token)) { - ODP_ERR("Error: token creation failed\n"); - return -1; - } - - odp_queue_enq(pkt_nm->tx_access, token); - - ODP_DBG("Wait for link to come up\n"); - sleep(WAITLINK_TMO); - ODP_DBG("Done\n"); - - return 0; -} - -int close_pkt_netmap(pkt_netmap_t * const pkt_nm) -{ - if (pkt_nm->nm_desc != NULL) { - nm_close(pkt_nm->nm_desc); - pkt_nm->nm_desc = NULL; - } - - return 0; -} - -int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], - unsigned len) -{ - struct netmap_ring *rxring = pkt_nm->rxring; - int fd; - unsigned nb_rx = 0; - uint32_t limit, rx; - uint32_t ringid = pkt_nm->begin; - odp_packet_t pkt = ODP_PACKET_INVALID; -#ifdef NETMAP_BLOCKING_IO - struct pollfd fds[1]; - int ret; -#endif - - fd = pkt_nm->nm_desc->fd; -#ifdef NETMAP_BLOCKING_IO - fds[0].fd = fd; - fds[0].events = POLLIN; -#endif - - while (nb_rx < len) { -#ifdef NETMAP_BLOCKING_IO - ret = poll(&fds[0], 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) - break; -#else - ioctl(fd, NIOCRXSYNC, NULL); -#endif - - /* Find first ring not empty */ - while (nm_ring_empty(rxring)) { - ringid++; - - /* Return to scheduler if no more data to meet the - requested amount (len) */ - if (ringid == pkt_nm->end) { - ODP_DBG("No more data on the wire\n"); - break; - } - - rxring = NETMAP_RXRING(pkt_nm->nm_desc->nifp, ringid); - } - - limit = len - nb_rx; - if (nm_ring_space(rxring) < limit) - limit = nm_ring_space(rxring); - - ODP_DBG("receiving %d frames out of %u\n", limit, len); - - for (rx = 0; rx < limit; rx++) { - struct netmap_slot *rslot; - char *p; - uint16_t frame_len; - uint8_t *pkt_buf; - uint8_t *l2_hdr; - uint32_t cur; - - if (odp_likely(pkt == ODP_PACKET_INVALID)) { - pkt = odph_packet_alloc(pkt_nm->pool); - if (odp_unlikely(pkt == ODP_PACKET_INVALID)) - break; - } - - cur = rxring->cur; - rslot = &rxring->slot[cur]; - p = NETMAP_BUF(rxring, rslot->buf_idx); - frame_len = rslot->len; - - rxring->head = nm_ring_next(rxring, cur); - rxring->cur = rxring->head; - - pkt_buf = odp_packet_buf_addr(pkt); - l2_hdr = pkt_buf + pkt_nm->frame_offset; - - if (frame_len > pkt_nm->max_frame_len) { - ODP_ERR("RX: frame too big %u %lu!\n", - frame_len, pkt_nm->max_frame_len); - /* drop the frame, reuse pkt next interation */ - continue; - } - if (odp_unlikely(frame_len < ODPH_ETH_LEN_MIN)) { - if (odp_unlikely(pkt_nm->netmap_mode != - ODP_NETMAP_MODE_SW)) { - ODP_ERR("RX: Frame truncated: %u\n", - (unsigned)frame_len); - continue; - } - memset(l2_hdr + frame_len, 0, - ODPH_ETH_LEN_MIN - frame_len); - frame_len = ODPH_ETH_LEN_MIN; - } - - /* For now copy the data in the mbuf, - worry about zero-copy later */ - memcpy(l2_hdr, p, frame_len); - - /* Initialize, parse and set packet header data */ - odp_packet_init(pkt); - odp_packet_parse(pkt, frame_len, pkt_nm->frame_offset); - - pkt_table[nb_rx] = pkt; - pkt = ODP_PACKET_INVALID; - nb_rx++; - } - - if (odp_unlikely(pkt == ODP_PACKET_INVALID)) - break; - } - - if (odp_unlikely(pkt != ODP_PACKET_INVALID)) - odp_buffer_free((odp_buffer_t) pkt); - - if (nb_rx) - ODP_DBG("<=== rcvd %03u frames from netmap adapter\n", nb_rx); - - return nb_rx; -} - -int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], - unsigned len) -{ - struct netmap_ring *txring = pkt_nm->txring; - int fd; - unsigned nb_tx = 0; - uint32_t limit, tx; - uint32_t ringid = pkt_nm->begin; - odp_packet_t pkt; - odp_buffer_t token; - -#ifdef NETMAP_BLOCKING_IO - struct pollfd fds[2]; - int ret; -#endif - - fd = pkt_nm->nm_desc->fd; -#ifdef NETMAP_BLOCKING_IO - fds[0].fd = fd; - fds[0].events = POLLOUT; -#endif - - token = odp_queue_deq(pkt_nm->tx_access); - - while (nb_tx < len) { -#ifdef NETMAP_BLOCKING_IO - ret = poll(&fds[0], 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) - break; -#else - ioctl(fd, NIOCTXSYNC, NULL); -#endif - - /* Find first ring not empty */ - while (nm_ring_empty(txring)) { - ringid++; - - /* Return to scheduler if no more space to meet the - requested amount (len) */ - if (ringid == pkt_nm->end) { - ODP_DBG("No more space in TX rings\n"); - break; - } - - txring = NETMAP_TXRING(pkt_nm->nm_desc->nifp, ringid); - } - - limit = len - nb_tx; - if (nm_ring_space(txring) < limit) - limit = nm_ring_space(txring); - - ODP_DBG("Sending %d packets out of %d to netmap %p %u\n", - limit, len, txring, txring->cur); - - for (tx = 0; tx < limit; tx++) { - struct netmap_slot *tslot; - size_t frame_len; - uint32_t cur; - uint8_t *frame; - void *txbuf; - - cur = txring->cur; - tslot = &txring->slot[cur]; - txbuf = NETMAP_BUF(txring, tslot->buf_idx); - - pkt = pkt_table[nb_tx]; - frame = odp_packet_start(pkt); - frame_len = odp_packet_get_len(pkt); - - memcpy(txbuf, frame, frame_len); - tslot->len = frame_len; - txring->head = nm_ring_next(txring, cur); - txring->cur = txring->head; - nb_tx++; - } - } - - odp_queue_enq(pkt_nm->tx_access, token); - -#ifndef NETMAP_BLOCKING_IO - ioctl(fd, NIOCTXSYNC, NULL); -#endif - - if (nb_tx) - ODP_DBG("===> sent %03u frames to netmap adapter\n", nb_tx); - - for (tx = 0; tx < len; tx++) - odph_packet_free(pkt_table[tx]); - - return nb_tx; -} |