net/null: support bulk allocation
[dpdk.git] / drivers / net / null / rte_eth_null.c
index 726a5c5..73fe8b0 100644 (file)
@@ -32,7 +32,7 @@
  */
 
 #include <rte_mbuf.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 #include <rte_ethdev_vdev.h>
 #include <rte_malloc.h>
 #include <rte_memcpy.h>
@@ -73,6 +73,7 @@ struct pmd_internals {
        struct null_queue rx_null_queues[RTE_MAX_QUEUES_PER_PORT];
        struct null_queue tx_null_queues[RTE_MAX_QUEUES_PER_PORT];
 
+       struct ether_addr eth_addr;
        /** Bit mask of RSS offloads, the bit offset also means flow type */
        uint64_t flow_type_rss_offloads;
 
@@ -84,9 +85,6 @@ struct pmd_internals {
 
        uint8_t rss_key[40];                /**< 40-byte hash key. */
 };
-
-
-static struct ether_addr eth_addr = { .addr_bytes = {0} };
 static struct rte_eth_link pmd_link = {
        .link_speed = ETH_SPEED_NUM_10G,
        .link_duplex = ETH_LINK_FULL_DUPLEX,
@@ -105,10 +103,10 @@ eth_null_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
                return 0;
 
        packet_size = h->internals->packet_size;
+       if (rte_pktmbuf_alloc_bulk(h->mb_pool, bufs, nb_bufs) != 0)
+               return 0;
+
        for (i = 0; i < nb_bufs; i++) {
-               bufs[i] = rte_pktmbuf_alloc(h->mb_pool);
-               if (!bufs[i])
-                       break;
                bufs[i]->data_len = (uint16_t)packet_size;
                bufs[i]->pkt_len = packet_size;
                bufs[i]->port = h->internals->port_id;
@@ -130,10 +128,10 @@ eth_null_copy_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
                return 0;
 
        packet_size = h->internals->packet_size;
+       if (rte_pktmbuf_alloc_bulk(h->mb_pool, bufs, nb_bufs) != 0)
+               return 0;
+
        for (i = 0; i < nb_bufs; i++) {
-               bufs[i] = rte_pktmbuf_alloc(h->mb_pool);
-               if (!bufs[i])
-                       break;
                rte_memcpy(rte_pktmbuf_mtod(bufs[i], void *), h->dummy_packet,
                                        packet_size);
                bufs[i]->data_len = (uint16_t)packet_size;
@@ -278,6 +276,11 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
        return 0;
 }
 
+static int
+eth_mtu_set(struct rte_eth_dev *dev __rte_unused, uint16_t mtu __rte_unused)
+{
+       return 0;
+}
 
 static void
 eth_dev_info(struct rte_eth_dev *dev,
@@ -456,6 +459,12 @@ eth_rss_hash_conf_get(struct rte_eth_dev *dev,
        return 0;
 }
 
+static void
+eth_mac_address_set(__rte_unused struct rte_eth_dev *dev,
+                   __rte_unused struct ether_addr *addr)
+{
+}
+
 static const struct eth_dev_ops ops = {
        .dev_start = eth_dev_start,
        .dev_stop = eth_dev_stop,
@@ -465,7 +474,9 @@ static const struct eth_dev_ops ops = {
        .tx_queue_setup = eth_tx_queue_setup,
        .rx_queue_release = eth_queue_release,
        .tx_queue_release = eth_queue_release,
+       .mtu_set = eth_mtu_set,
        .link_update = eth_link_update,
+       .mac_addr_set = eth_mac_address_set,
        .stats_get = eth_stats_get,
        .stats_reset = eth_stats_reset,
        .reta_update = eth_rss_reta_update,
@@ -513,7 +524,6 @@ eth_dev_null_create(struct rte_vdev_device *dev,
                rte_free(data);
                return -ENOMEM;
        }
-
        /* now put it all together
         * - store queue data in internals,
         * - store numa_node info in ethdev data
@@ -527,6 +537,7 @@ eth_dev_null_create(struct rte_vdev_device *dev,
        internals->packet_size = packet_size;
        internals->packet_copy = packet_copy;
        internals->port_id = eth_dev->data->port_id;
+       eth_random_addr(internals->eth_addr.addr_bytes);
 
        internals->flow_type_rss_offloads =  ETH_RSS_PROTO_MASK;
        internals->reta_size = RTE_DIM(internals->reta_conf) * RTE_RETA_GROUP_SIZE;
@@ -537,7 +548,7 @@ eth_dev_null_create(struct rte_vdev_device *dev,
        data->nb_rx_queues = (uint16_t)nb_rx_queues;
        data->nb_tx_queues = (uint16_t)nb_tx_queues;
        data->dev_link = pmd_link;
-       data->mac_addrs = &eth_addr;
+       data->mac_addrs = &internals->eth_addr;
 
        eth_dev->data = data;
        eth_dev->dev_ops = &ops;