drivers: copy fake PCI device info to ethdev data
[dpdk.git] / drivers / net / af_packet / rte_eth_af_packet.c
index bdd9628..c7d5522 100644 (file)
@@ -5,7 +5,7 @@
  *
  *   Originally based upon librte_pmd_pcap code:
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
  *   Copyright(c) 2014 6WIND S.A.
  *   All rights reserved.
  *
@@ -220,7 +220,8 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
        }
 
        /* kick-off transmits */
-       sendto(pkt_q->sockfd, NULL, 0, MSG_DONTWAIT, NULL, 0);
+       if (sendto(pkt_q->sockfd, NULL, 0, MSG_DONTWAIT, NULL, 0) == -1)
+               return 0; /* error sending -- no packets transmitted */
 
        pkt_q->framenum = framenum;
        pkt_q->tx_pkts += num_tx;
@@ -454,7 +455,7 @@ rte_pmd_init_internals(const char *name,
                RTE_LOG(ERR, PMD,
                        "%s: no interface specified for AF_PACKET ethdev\n",
                        name);
-               goto error;
+               goto error_early;
        }
 
        RTE_LOG(INFO, PMD,
@@ -467,16 +468,16 @@ rte_pmd_init_internals(const char *name,
         */
        data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
        if (data == NULL)
-               goto error;
+               goto error_early;
 
        pci_dev = rte_zmalloc_socket(name, sizeof(*pci_dev), 0, numa_node);
        if (pci_dev == NULL)
-               goto error;
+               goto error_early;
 
        *internals = rte_zmalloc_socket(name, sizeof(**internals),
                                        0, numa_node);
        if (*internals == NULL)
-               goto error;
+               goto error_early;
 
        for (q = 0; q < nb_queues; q++) {
                (*internals)->rx_queue[q].map = MAP_FAILED;
@@ -498,13 +499,13 @@ rte_pmd_init_internals(const char *name,
                RTE_LOG(ERR, PMD,
                        "%s: I/F name too long (%s)\n",
                        name, pair->value);
-               goto error;
+               goto error_early;
        }
        if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
                RTE_LOG(ERR, PMD,
                        "%s: ioctl failed (SIOCGIFINDEX)\n",
                        name);
-               goto error;
+               goto error_early;
        }
        (*internals)->if_index = ifr.ifr_ifindex;
 
@@ -512,7 +513,7 @@ rte_pmd_init_internals(const char *name,
                RTE_LOG(ERR, PMD,
                        "%s: ioctl failed (SIOCGIFHWADDR)\n",
                        name);
-               goto error;
+               goto error_early;
        }
        memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
 
@@ -655,8 +656,8 @@ rte_pmd_init_internals(const char *name,
        /*
         * now put it all together
         * - store queue data in internals,
-        * - store numa_node info in pci_driver
-        * - point eth_dev_data to internals and pci_driver
+        * - store numa_node in eth_dev
+        * - point eth_dev_data to internals
         * - and point eth_dev structure to new eth_dev_data structure
         */
 
@@ -674,28 +675,31 @@ rte_pmd_init_internals(const char *name,
        (*eth_dev)->data = data;
        (*eth_dev)->dev_ops = &ops;
        (*eth_dev)->pci_dev = pci_dev;
+       (*eth_dev)->driver = NULL;
+       (*eth_dev)->data->dev_flags = 0;
+       (*eth_dev)->data->drv_name = drivername;
+       (*eth_dev)->data->kdrv = RTE_KDRV_NONE;
+       (*eth_dev)->data->numa_node = numa_node;
 
        return 0;
 
 error:
-       rte_free(data);
-       rte_free(pci_dev);
-
-       if (*internals) {
-               for (q = 0; q < nb_queues; q++) {
-                       munmap((*internals)->rx_queue[q].map,
-                              2 * req->tp_block_size * req->tp_block_nr);
-
-                       rte_free((*internals)->rx_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);
+       for (q = 0; q < nb_queues; q++) {
+               munmap((*internals)->rx_queue[q].map,
+                      2 * req->tp_block_size * req->tp_block_nr);
+
+               rte_free((*internals)->rx_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);
+error_early:
+       rte_free(pci_dev);
+       rte_free(data);
        return -1;
 }