ixgbe: fix build without builk alloc
[dpdk.git] / lib / librte_pmd_af_packet / rte_eth_af_packet.c
index 3b5bd58..2ac50ba 100644 (file)
@@ -285,8 +285,6 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
        unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
        const struct pmd_internals *internal = dev->data->dev_private;
 
-       memset(igb_stats, 0, sizeof(*igb_stats));
-
        imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ?
                internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS);
        for (i = 0; i < imax; i++) {
@@ -444,9 +442,10 @@ rte_pmd_init_internals(const char *name,
        struct tpacket_req *req;
        struct pkt_rx_queue *rx_queue;
        struct pkt_tx_queue *tx_queue;
-       int rc, tpver, discard, bypass;
+       int rc, tpver, discard;
+       int qsockfd = -1;
        unsigned int i, q, rdsize;
-       int qsockfd, fanout_arg;
+       int fanout_arg __rte_unused, bypass __rte_unused;
 
        for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
                pair = &kvlist->pairs[k_idx];
@@ -481,6 +480,11 @@ rte_pmd_init_internals(const char *name,
        if (*internals == NULL)
                goto error;
 
+       for (q = 0; q < nb_queues; q++) {
+               (*internals)->rx_queue[q].map = MAP_FAILED;
+               (*internals)->tx_queue[q].map = MAP_FAILED;
+       }
+
        req = &((*internals)->req);
 
        req->tp_block_size = blocksize;
@@ -519,9 +523,13 @@ rte_pmd_init_internals(const char *name,
        sockaddr.sll_protocol = htons(ETH_P_ALL);
        sockaddr.sll_ifindex = (*internals)->if_index;
 
+#if defined(PACKET_FANOUT)
        fanout_arg = (getpid() ^ (*internals)->if_index) & 0xffff;
-       fanout_arg |= (PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_DEFRAG |
-                      PACKET_FANOUT_FLAG_ROLLOVER) << 16;
+       fanout_arg |= (PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_DEFRAG) << 16;
+#if defined(PACKET_FANOUT_FLAG_ROLLOVER)
+       fanout_arg |= PACKET_FANOUT_FLAG_ROLLOVER << 16;
+#endif
+#endif
 
        for (q = 0; q < nb_queues; q++) {
                /* Open an AF_PACKET socket for this queue... */
@@ -553,6 +561,7 @@ rte_pmd_init_internals(const char *name,
                        goto error;
                }
 
+#if defined(PACKET_QDISC_BYPASS)
                bypass = 1;
                rc = setsockopt(qsockfd, SOL_PACKET, PACKET_QDISC_BYPASS,
                                &bypass, sizeof(bypass));
@@ -563,6 +572,7 @@ rte_pmd_init_internals(const char *name,
                                pair->value);
                        goto error;
                }
+#endif
 
                rc = setsockopt(qsockfd, SOL_PACKET, PACKET_RX_RING, req, sizeof(*req));
                if (rc == -1) {
@@ -597,6 +607,8 @@ rte_pmd_init_internals(const char *name,
                rdsize = req->tp_frame_nr * sizeof(*(rx_queue->rd));
 
                rx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node);
+               if (rx_queue->rd == NULL)
+                       goto error;
                for (i = 0; i < req->tp_frame_nr; ++i) {
                        rx_queue->rd[i].iov_base = rx_queue->map + (i * framesize);
                        rx_queue->rd[i].iov_len = req->tp_frame_size;
@@ -609,6 +621,8 @@ rte_pmd_init_internals(const char *name,
                tx_queue->map = rx_queue->map + req->tp_block_size * req->tp_block_nr;
 
                tx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node);
+               if (tx_queue->rd == NULL)
+                       goto error;
                for (i = 0; i < req->tp_frame_nr; ++i) {
                        tx_queue->rd[i].iov_base = tx_queue->map + (i * framesize);
                        tx_queue->rd[i].iov_len = req->tp_frame_size;
@@ -623,6 +637,7 @@ rte_pmd_init_internals(const char *name,
                        goto error;
                }
 
+#if defined(PACKET_FANOUT)
                rc = setsockopt(qsockfd, SOL_PACKET, PACKET_FANOUT,
                                &fanout_arg, sizeof(fanout_arg));
                if (rc == -1) {
@@ -631,10 +646,11 @@ rte_pmd_init_internals(const char *name,
                                "for %s\n", name, pair->value);
                        goto error;
                }
+#endif
        }
 
        /* reserve an ethdev entry */
-       *eth_dev = rte_eth_dev_allocate(name);
+       *eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
        if (*eth_dev == NULL)
                goto error;
 
@@ -668,14 +684,22 @@ error:
                rte_free(data);
        if (pci_dev)
                rte_free(pci_dev);
-       for (q = 0; q < nb_queues; q++) {
-               if ((*internals)->rx_queue[q].rd)
-                       rte_free((*internals)->rx_queue[q].rd);
-               if ((*internals)->tx_queue[q].rd)
-                       rte_free((*internals)->tx_queue[q].rd);
-       }
-       if (*internals)
+       if (*internals) {
+               for (q = 0; q < nb_queues; q++) {
+                       munmap((*internals)->rx_queue[q].map,
+                              2 * req->tp_block_size * req->tp_block_nr);
+                       if ((*internals)->rx_queue[q].rd)
+                               rte_free((*internals)->rx_queue[q].rd);
+                       if ((*internals)->tx_queue[q].rd)
+                               rte_free((*internals)->tx_queue[q].rd);
+                       if (((*internals)->rx_queue[q].sockfd != 0) &&
+                               ((*internals)->rx_queue[q].sockfd != qsockfd))
+                               close((*internals)->rx_queue[q].sockfd);
+               }
                rte_free(*internals);
+       }
+       if (qsockfd != -1)
+               close(qsockfd);
        return -1;
 }
 
@@ -784,7 +808,7 @@ int
 rte_pmd_af_packet_devinit(const char *name, const char *params)
 {
        unsigned numa_node;
-       int ret;
+       int ret = 0;
        struct rte_kvargs *kvlist;
        int sockfd = -1;
 
@@ -793,8 +817,10 @@ rte_pmd_af_packet_devinit(const char *name, const char *params)
        numa_node = rte_socket_id();
 
        kvlist = rte_kvargs_parse(params, valid_arguments);
-       if (kvlist == NULL)
-               return -1;
+       if (kvlist == NULL) {
+               ret = -1;
+               goto exit;
+       }
 
        /*
         * If iface argument is passed we open the NICs and use them for
@@ -805,16 +831,15 @@ rte_pmd_af_packet_devinit(const char *name, const char *params)
                ret = rte_kvargs_process(kvlist, ETH_AF_PACKET_IFACE_ARG,
                                         &open_packet_iface, &sockfd);
                if (ret < 0)
-                       return -1;
+                       goto exit;
        }
 
        ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist);
        close(sockfd); /* no longer needed */
 
-       if (ret < 0)
-               return -1;
-
-       return 0;
+exit:
+       rte_kvargs_free(kvlist);
+       return ret;
 }
 
 static struct rte_driver pmd_af_packet_drv = {