remove extra parentheses in return statement
[dpdk.git] / examples / netmap_compat / lib / compat_netmap.c
index ebb98ff..bf1b418 100644 (file)
@@ -1,13 +1,13 @@
 /*-
  *   BSD LICENSE
- * 
+ *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   All rights reserved.
- * 
+ *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
  *   are met:
- * 
+ *
  *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
  *     * Redistributions in binary form must reproduce the above copyright
@@ -17,7 +17,7 @@
  *     * Neither the name of Intel Corporation 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 COPYRIGHT HOLDERS AND CONTRIBUTORS
  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -73,6 +73,14 @@ struct fd_port {
        uint32_t port;
 };
 
+#ifndef POLLRDNORM
+#define POLLRDNORM     0x0040
+#endif
+
+#ifndef POLLWRNORM
+#define POLLWRNORM     0x0100
+#endif
+
 #define        FD_PORT_FREE    UINT32_MAX
 #define        FD_PORT_RSRV    (FD_PORT_FREE - 1)
 
@@ -92,7 +100,7 @@ struct netmap_state {
 static struct netmap_port ports[RTE_MAX_ETHPORTS];
 static struct netmap_state netmap;
 
-static struct fd_port fd_port[COMPAT_NETMAP_MAX_NOFILE]; 
+static struct fd_port fd_port[COMPAT_NETMAP_MAX_NOFILE];
 static const int next_fd_start = RLIMIT_NOFILE + 1;
 static rte_spinlock_t netmap_lock;
 
@@ -130,10 +138,10 @@ ifname_to_portid(const char *ifname, uint8_t *port)
        portid = strtoul(ifname, &endptr, 10);
        if (endptr == ifname || *endptr != '\0' ||
                        portid >= RTE_DIM(ports) || errno != 0)
-               return (-EINVAL);
+               return -EINVAL;
 
        *port = (uint8_t)portid;
-       return (0);
+       return 0;
 }
 
 /**
@@ -188,10 +196,10 @@ fd_reserve(void)
                ;
 
        if (i == RTE_DIM(fd_port))
-               return (-ENOMEM);
+               return -ENOMEM;
 
        fd_port[i].port = FD_PORT_RSRV;
-       return (IDX_TO_FD(i));
+       return IDX_TO_FD(i);
 }
 
 static int32_t
@@ -202,7 +210,7 @@ fd_release(int32_t fd)
        idx = FD_TO_IDX(fd);
 
        if (!FD_VALID(fd) || (port = fd_port[idx].port) == FD_PORT_FREE)
-               return (-EINVAL);
+               return -EINVAL;
 
        /* if we still have a valid port attached, release the port */
        if (port < RTE_DIM(ports) && ports[port].fd == idx) {
@@ -210,7 +218,7 @@ fd_release(int32_t fd)
        }
 
        fd_port[idx].port = FD_PORT_FREE;
-       return (0);
+       return 0;
 }
 
 static int
@@ -220,26 +228,26 @@ check_nmreq(struct nmreq *req, uint8_t *port)
        uint8_t portid;
 
        if (req == NULL)
-               return (-EINVAL);
+               return -EINVAL;
 
        if (req->nr_version != NETMAP_API) {
                req->nr_version = NETMAP_API;
-               return (-EINVAL);
+               return -EINVAL;
        }
 
        if ((rc = ifname_to_portid(req->nr_name, &portid)) != 0) {
                RTE_LOG(ERR, USER1, "Invalid interface name:\"%s\" "
                        "in NIOCGINFO call\n", req->nr_name);
-               return (rc);
+               return rc;
        }
 
        if (ports[portid].pool == NULL) {
                RTE_LOG(ERR, USER1, "Misconfigured portid %hhu\n", portid);
-               return (-EINVAL);
+               return -EINVAL;
        }
 
        *port = portid;
-       return (0);
+       return 0;
 }
 
 /**
@@ -260,7 +268,7 @@ ioctl_niocginfo(__rte_unused int fd, void * param)
 
        req = (struct nmreq *)param;
        if ((rc = check_nmreq(req, &portid)) != 0)
-               return (rc);
+               return rc;
 
        req->nr_tx_rings = (uint16_t)(ports[portid].nr_tx_rings - 1);
        req->nr_rx_rings = (uint16_t)(ports[portid].nr_rx_rings - 1);
@@ -271,7 +279,7 @@ ioctl_niocginfo(__rte_unused int fd, void * param)
        req->nr_memsize = netmap.mem_sz;
        req->nr_offset = 0;
 
-       return (0);
+       return 0;
 }
 
 static void
@@ -288,7 +296,7 @@ netmap_ring_setup(struct netmap_ring *ring, uint8_t port, uint32_t ringid,
        ring->flags = 0;
        ring->ts.tv_sec = 0;
        ring->ts.tv_usec = 0;
-           
+
        for (j = 0; j < ring->num_slots; j++) {
                ring->slot[j].buf_idx = BUF_IDX(port, ringid, j);
                ring->slot[j].len = 0;
@@ -307,12 +315,12 @@ netmap_regif(struct nmreq *req, uint32_t idx, uint8_t port)
        if (ports[port].fd < RTE_DIM(fd_port)) {
                RTE_LOG(ERR, USER1, "port %hhu already in use by fd: %u\n",
                        port, IDX_TO_FD(ports[port].fd));
-               return (-EBUSY);
+               return -EBUSY;
        }
        if (fd_port[idx].port != FD_PORT_RSRV) {
                RTE_LOG(ERR, USER1, "fd: %u is misconfigured\n",
                        IDX_TO_FD(idx));
-               return (-EBUSY);
+               return -EBUSY;
        }
 
        nmif = ports[port].nmif;
@@ -322,9 +330,9 @@ netmap_regif(struct nmreq *req, uint32_t idx, uint8_t port)
 
        /* only ALL rings supported right now. */
        if (req->nr_ringid != 0)
-               return (-EINVAL);
+               return -EINVAL;
 
-       rte_snprintf(nmif->ni_name, sizeof(nmif->ni_name), "%s", req->nr_name);
+       snprintf(nmif->ni_name, sizeof(nmif->ni_name), "%s", req->nr_name);
        nmif->ni_version  = req->nr_version;
 
        /* Netmap uses ni_(r|t)x_rings + 1 */
@@ -372,7 +380,7 @@ netmap_regif(struct nmreq *req, uint32_t idx, uint8_t port)
                RTE_LOG(ERR, USER1,
                        "Couldn't start ethernet device %s (error %d)\n",
                        req->nr_name, rc);
-           return (rc);
+           return rc;
        }
 
        /* setup fdi <--> port relationtip. */
@@ -382,7 +390,7 @@ netmap_regif(struct nmreq *req, uint32_t idx, uint8_t port)
        req->nr_memsize = netmap.mem_sz;
        req->nr_offset = (uintptr_t)nmif - (uintptr_t)netmap.mem;
 
-       return (0);
+       return 0;
 }
 
 /**
@@ -398,7 +406,7 @@ ioctl_niocregif(int32_t fd, void * param)
 
        req = (struct nmreq *)param;
        if ((rc = check_nmreq(req, &portid)) != 0)
-               return (rc);
+               return rc;
 
        idx = FD_TO_IDX(fd);
 
@@ -406,7 +414,7 @@ ioctl_niocregif(int32_t fd, void * param)
        rc = netmap_regif(req, idx, portid);
        rte_spinlock_unlock(&netmap_lock);
 
-       return (rc);
+       return rc;
 }
 
 static void
@@ -444,7 +452,7 @@ ioctl_niocunregif(int fd)
        }
 
        rte_spinlock_unlock(&netmap_lock);
-       return (rc);
+       return rc;
 }
 
 /**
@@ -487,7 +495,7 @@ rx_sync_ring(struct netmap_ring *ring, uint8_t port, uint16_t ring_number,
                ring->avail += n_rx;
                n_free_slots -= n_rx;
        }
-       
+
        return 0;
 }
 
@@ -509,7 +517,7 @@ rx_sync_if(uint32_t port)
                rc += r->avail;
        }
 
-       return (rc);
+       return rc;
 }
 
 /**
@@ -523,9 +531,9 @@ ioctl_niocrxsync(int fd)
        idx = FD_TO_IDX(fd);
        if ((port = fd_port[idx].port) < RTE_DIM(ports) &&
                        ports[port].fd == idx) {
-               return (rx_sync_if(fd_port[idx].port));
+               return rx_sync_if(fd_port[idx].port);
        } else  {
-               return (-EINVAL);
+               return -EINVAL;
        }
 }
 
@@ -550,7 +558,7 @@ tx_sync_ring(struct netmap_ring *ring, uint8_t port, uint16_t ring_number,
                burst_size = (uint16_t)RTE_MIN(n_used_slots, RTE_DIM(tx_mbufs));
 
                for (i = 0; i < burst_size; i++) {
-                       tx_mbufs[i] = rte_pktmbuf_alloc(pool);
+                       tx_mbufs[i] = rte_pktmbuf_alloc(pool);
                        if (tx_mbufs[i] == NULL)
                                goto err;
 
@@ -604,7 +612,7 @@ tx_sync_if(uint32_t port)
                rc += r->avail;
        }
 
-       return (rc);
+       return rc;
 }
 
 /**
@@ -618,9 +626,9 @@ ioctl_nioctxsync(int fd)
        idx = FD_TO_IDX(fd);
        if ((port = fd_port[idx].port) < RTE_DIM(ports) &&
                        ports[port].fd == idx) {
-               return (tx_sync_if(fd_port[idx].port));
+               return tx_sync_if(fd_port[idx].port);
        } else  {
-               return (-EINVAL);
+               return -EINVAL;
        }
 }
 
@@ -638,20 +646,20 @@ rte_netmap_init(const struct rte_netmap_conf *conf)
        port_num = RTE_MAX_ETHPORTS;
        port_rings = 2 * conf->max_rings;
        port_slots = port_rings * conf->max_slots;
-       port_bufs = port_slots;
+       port_bufs = port_slots;
 
        nmif_sz = NETMAP_IF_RING_OFS(port_rings, port_rings, port_slots);
        sz = nmif_sz * port_num;
 
-       buf_ofs = RTE_ALIGN_CEIL(sz, CACHE_LINE_SIZE);
+       buf_ofs = RTE_ALIGN_CEIL(sz, RTE_CACHE_LINE_SIZE);
        sz = buf_ofs + port_bufs * conf->max_bufsz * port_num;
 
        if (sz > UINT32_MAX ||
                        (netmap.mem = rte_zmalloc_socket(__func__, sz,
-                       CACHE_LINE_SIZE, conf->socket_id)) == NULL) {
+                       RTE_CACHE_LINE_SIZE, conf->socket_id)) == NULL) {
                RTE_LOG(ERR, USER1, "%s: failed to allocate %zu bytes\n",
                        __func__, sz);
-               return (-ENOMEM);
+               return -ENOMEM;
        }
 
        netmap.mem_sz = sz;
@@ -673,7 +681,7 @@ rte_netmap_init(const struct rte_netmap_conf *conf)
                fd_port[i].port = FD_PORT_FREE;
        }
 
-       return (0);
+       return 0;
 }
 
 
@@ -690,7 +698,7 @@ rte_netmap_init_port(uint8_t portid, const struct rte_netmap_port_conf *conf)
                        conf->nr_rx_rings > netmap.conf.max_rings) {
                RTE_LOG(ERR, USER1, "%s(%hhu): invalid parameters\n",
                        __func__, portid);
-               return (-EINVAL);
+               return -EINVAL;
        }
 
                rx_slots = (uint16_t)rte_align32pow2(conf->nr_rx_slots);
@@ -700,45 +708,43 @@ rte_netmap_init_port(uint8_t portid, const struct rte_netmap_port_conf *conf)
                        rx_slots > netmap.conf.max_slots) {
                RTE_LOG(ERR, USER1, "%s(%hhu): invalid parameters\n",
                        __func__, portid);
-               return (-EINVAL);
+               return -EINVAL;
        }
 
        ret = rte_eth_dev_configure(portid, conf->nr_rx_rings,
                conf->nr_tx_rings, conf->eth_conf);
-                                   
+
        if (ret < 0) {
            RTE_LOG(ERR, USER1, "Couldn't configure port %hhu\n", portid);
-           return (ret);
+           return ret;
        }
 
        for (i = 0; i < conf->nr_tx_rings; i++) {
                ret = rte_eth_tx_queue_setup(portid, i, tx_slots,
-                       conf->socket_id, conf->tx_conf);
+                       conf->socket_id, NULL);
 
                if (ret < 0) {
                        RTE_LOG(ERR, USER1,
-                               "Couldn't configure TX queue %hhu of "
-                               "port %hu\n",
+                               "Couldn't configure TX queue %"PRIu16" of "
+                               "port %"PRIu8"\n",
                                i, portid);
-                       return (ret);
+                       return ret;
                }
 
                ret = rte_eth_rx_queue_setup(portid, i, rx_slots,
-                       conf->socket_id, conf->rx_conf, conf->pool);
-                                        
+                       conf->socket_id, NULL, conf->pool);
+
                if (ret < 0) {
                        RTE_LOG(ERR, USER1,
-                               "Couldn't configure RX queue %hu of "
-                               "port %hhu\n",
+                               "Couldn't configure RX queue %"PRIu16" of "
+                               "port %"PRIu8"\n",
                                i, portid);
-                       return (ret);
+                       return ret;
                }
        }
 
        /* copy config to the private storage. */
        ports[portid].eth_conf = conf->eth_conf[0];
-       ports[portid].rx_conf = conf->rx_conf[0];
-       ports[portid].tx_conf = conf->tx_conf[0];
        ports[portid].pool = conf->pool;
        ports[portid].socket_id = conf->socket_id;
        ports[portid].nr_tx_rings = conf->nr_tx_rings;
@@ -748,7 +754,7 @@ rte_netmap_init_port(uint8_t portid, const struct rte_netmap_port_conf *conf)
        ports[portid].tx_burst = conf->tx_burst;
        ports[portid].rx_burst = conf->rx_burst;
 
-       return (0);
+       return 0;
 }
 
 int
@@ -764,17 +770,17 @@ rte_netmap_close(__rte_unused int fd)
                errno =-rc;
                rc = -1;
        }
-       return (rc);
+       return rc;
 }
 
-int rte_netmap_ioctl(int fd, int op, void *param)
+int rte_netmap_ioctl(int fd, uint32_t op, void *param)
 {
        int ret;
 
        if (!FD_VALID(fd)) {
            errno = EBADF;
-           return (-1);
-       } 
+           return -1;
+       }
 
        switch (op) {
 
@@ -809,7 +815,7 @@ int rte_netmap_ioctl(int fd, int op, void *param)
                ret = 0;
        }
 
-       return (ret);
+       return ret;
 }
 
 void *
@@ -823,13 +829,13 @@ rte_netmap_mmap(void *addr, size_t length,
                        ((flags & MAP_FIXED) != 0 && addr != NULL)) {
 
                errno = EINVAL;
-               return (MAP_FAILED);
+               return MAP_FAILED;
        }
 
-       return ((void *)((uintptr_t)netmap.mem + offset));
+       return (void *)((uintptr_t)netmap.mem + (uintptr_t)offset);
 }
 
-/** 
+/**
  * Return a "fake" file descriptor with a value above RLIMIT_NOFILE so that
  * any attempt to use that file descriptor with the usual API will fail.
  */
@@ -846,7 +852,7 @@ rte_netmap_open(__rte_unused const char *pathname, __rte_unused int flags)
                errno = -fd;
                fd = -1;
        }
-       return (fd);
+       return fd;
 }
 
 /**
@@ -869,10 +875,10 @@ rte_netmap_poll(struct pollfd *fds, nfds_t nfds, int timeout)
                                fds[i].revents = 0;
                                continue;
                        }
-               
+
                        idx = FD_TO_IDX(fds[i].fd);
                        if ((port = fd_port[idx].port) >= RTE_DIM(ports) ||
-                                       ports[port].fd != idx) {
+               ports[port].fd != idx) {
 
                                fds[i].revents |= POLLERR;
                                ret++;