fix typos using codespell utility
[dpdk.git] / examples / vhost_xen / main.c
index d83138d..ed26e28 100644 (file)
@@ -149,7 +149,7 @@ static const struct rte_eth_conf vmdq_conf_default = {
                 */
                .hw_vlan_strip  = 1, /**< VLAN strip enabled. */
                .jumbo_frame    = 0, /**< Jumbo Frame Support disabled */
-               .hw_strip_crc   = 0, /**< CRC stripped by hardware */
+               .hw_strip_crc   = 1, /**< CRC stripped by hardware */
        },
 
        .txmode = {
@@ -506,37 +506,11 @@ static unsigned check_ports_num(unsigned nb_ports)
        return valid_num_ports;
 }
 
-/*
- * Macro to print out packet contents. Wrapped in debug define so that the
- * data path is not effected when debug is disabled.
- */
-#ifdef DEBUG
-#define PRINT_PACKET(device, addr, size, header) do {                                                                                                                          \
-       char *pkt_addr = (char*)(addr);                                                                                                                                                                 \
-       unsigned int index;                                                                                                                                                                                             \
-       char packet[MAX_PRINT_BUFF];                                                                                                                                                                    \
-                                                                                                                                                                                                                                       \
-       if ((header))                                                                                                                                                                                                   \
-               snprintf(packet, MAX_PRINT_BUFF, "(%"PRIu64") Header size %d: ", (device->device_fh), (size));                          \
-       else                                                                                                                                                                                                                    \
-               snprintf(packet, MAX_PRINT_BUFF, "(%"PRIu64") Packet size %d: ", (device->device_fh), (size));                          \
-       for (index = 0; index < (size); index++) {                                                                                                                                              \
-               snprintf(packet + strnlen(packet, MAX_PRINT_BUFF), MAX_PRINT_BUFF - strnlen(packet, MAX_PRINT_BUFF),    \
-                       "%02hhx ", pkt_addr[index]);                                                                                                                                                    \
-       }                                                                                                                                                                                                                               \
-       snprintf(packet + strnlen(packet, MAX_PRINT_BUFF), MAX_PRINT_BUFF - strnlen(packet, MAX_PRINT_BUFF), "\n");     \
-                                                                                                                                                                                                                                       \
-       LOG_DEBUG(VHOST_DATA, "%s", packet);                                                                                                                                                                    \
-} while(0)
-#else
-#define PRINT_PACKET(device, addr, size, header) do{} while(0)
-#endif
-
 /*
  * Function to convert guest physical addresses to vhost virtual addresses. This
  * is used to convert virtio buffer addresses.
  */
-static inline uint64_t __attribute__((always_inline))
+static __rte_always_inline uint64_t
 gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
 {
        struct virtio_memory_regions *region;
@@ -551,7 +525,7 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
                        break;
                }
        }
-       LOG_DEBUG(VHOST_DATA, "(%"PRIu64") GPA %p| VVA %p\n",
+       RTE_LOG_DP(DEBUG, VHOST_DATA, "(%" PRIu64 ") GPA %p| VVA %p\n",
                dev->device_fh, (void*)(uintptr_t)guest_pa, (void*)(uintptr_t)vhost_va);
 
        return vhost_va;
@@ -560,10 +534,10 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)
 /*
  * This function adds buffers to the virtio devices RX virtqueue. Buffers can
  * be received from the physical port or from another virtio device. A packet
- * count is returned to indicate the number of packets that were succesfully
+ * count is returned to indicate the number of packets that were successfully
  * added to the RX queue.
  */
-static inline uint32_t __attribute__((always_inline))
+static __rte_always_inline uint32_t
 virtio_dev_rx(struct virtio_net *dev, struct rte_mbuf **pkts, uint32_t count)
 {
        struct vhost_virtqueue *vq;
@@ -581,7 +555,7 @@ virtio_dev_rx(struct virtio_net *dev, struct rte_mbuf **pkts, uint32_t count)
        uint8_t success = 0;
        void *userdata;
 
-       LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_rx()\n", dev->device_fh);
+       RTE_LOG_DP(DEBUG, VHOST_DATA, "(%" PRIu64 ") virtio_dev_rx()\n", dev->device_fh);
        vq = dev->virtqueue_rx;
        count = (count > MAX_PKT_BURST) ? MAX_PKT_BURST : count;
        /* As many data cores may want access to available buffers, they need to be reserved. */
@@ -606,7 +580,8 @@ virtio_dev_rx(struct virtio_net *dev, struct rte_mbuf **pkts, uint32_t count)
                                                                        res_end_idx);
        } while (unlikely(success == 0));
        res_cur_idx = res_base_idx;
-       LOG_DEBUG(VHOST_DATA, "(%"PRIu64") Current Index %d| End Index %d\n", dev->device_fh, res_cur_idx, res_end_idx);
+       RTE_LOG_DP(DEBUG, VHOST_DATA, "(%" PRIu64 ") Current Index %d| End Index %d\n",
+               dev->device_fh, res_cur_idx, res_end_idx);
 
        /* Prefetch available ring to retrieve indexes. */
        rte_prefetch0(&vq->avail->ring[res_cur_idx & (vq->size - 1)]);
@@ -687,7 +662,7 @@ virtio_dev_rx(struct virtio_net *dev, struct rte_mbuf **pkts, uint32_t count)
 /*
  * Compares a packet destination MAC address to a device MAC address.
  */
-static inline int __attribute__((always_inline))
+static __rte_always_inline int
 ether_addr_cmp(struct ether_addr *ea, struct ether_addr *eb)
 {
        return ((*(uint64_t *)ea ^ *(uint64_t *)eb) & MAC_ADDR_CMP) == 0;
@@ -782,7 +757,7 @@ unlink_vmdq(struct virtio_net *dev)
  * Check if the packet destination MAC address is for a local device. If so then put
  * the packet on that devices RX queue. If not then return.
  */
-static inline unsigned __attribute__((always_inline))
+static __rte_always_inline unsigned
 virtio_tx_local(struct virtio_net *dev, struct rte_mbuf *m)
 {
        struct virtio_net_data_ll *dev_ll;
@@ -800,17 +775,22 @@ virtio_tx_local(struct virtio_net *dev, struct rte_mbuf *m)
 
                        /* Drop the packet if the TX packet is destined for the TX device. */
                        if (dev_ll->dev->device_fh == dev->device_fh) {
-                               LOG_DEBUG(VHOST_DATA, "(%"PRIu64") TX: Source and destination MAC addresses are the same. Dropping packet.\n",
-                                                       dev_ll->dev->device_fh);
+                               RTE_LOG_DP(DEBUG, VHOST_DATA, "(%" PRIu64 ") TX: "
+                                       "Source and destination MAC addresses are the same. "
+                                       "Dropping packet.\n",
+                                       dev_ll->dev->device_fh);
                                return 0;
                        }
 
 
-                       LOG_DEBUG(VHOST_DATA, "(%"PRIu64") TX: MAC address is local\n", dev_ll->dev->device_fh);
+                       RTE_LOG_DP(DEBUG, VHOST_DATA, "(%" PRIu64 ") TX: "
+                               "MAC address is local\n", dev_ll->dev->device_fh);
 
                        if (dev_ll->dev->remove) {
                                /*drop the packet if the device is marked for removal*/
-                               LOG_DEBUG(VHOST_DATA, "(%"PRIu64") Device is marked for removal\n", dev_ll->dev->device_fh);
+                               RTE_LOG_DP(DEBUG, VHOST_DATA, "(%" PRIu64 ") "
+                                       "Device is marked for removal\n",
+                                       dev_ll->dev->device_fh);
                        } else {
                                /*send the packet to the local virtio device*/
                                ret = virtio_dev_rx(dev_ll->dev, &m, 1);
@@ -834,7 +814,7 @@ virtio_tx_local(struct virtio_net *dev, struct rte_mbuf *m)
  * This function routes the TX packet to the correct interface. This may be a local device
  * or the physical port.
  */
-static inline void __attribute__((always_inline))
+static __rte_always_inline void
 virtio_tx_route(struct virtio_net* dev, struct rte_mbuf *m, struct rte_mempool *mbuf_pool, uint16_t vlan_tag)
 {
        struct mbuf_table *tx_q;
@@ -849,7 +829,8 @@ virtio_tx_route(struct virtio_net* dev, struct rte_mbuf *m, struct rte_mempool *
                return;
        }
 
-       LOG_DEBUG(VHOST_DATA, "(%"PRIu64") TX: MAC address is external\n", dev->device_fh);
+       RTE_LOG_DP(DEBUG, VHOST_DATA, "(%" PRIu64 ") TX: "
+               "MAC address is external\n", dev->device_fh);
 
        /*Add packet to the port tx queue*/
        tx_q = &lcore_tx_queue[lcore_id];
@@ -902,7 +883,7 @@ virtio_tx_route(struct virtio_net* dev, struct rte_mbuf *m, struct rte_mempool *
        return;
 }
 
-static inline void __attribute__((always_inline))
+static __rte_always_inline void
 virtio_dev_tx(struct virtio_net* dev, struct rte_mempool *mbuf_pool)
 {
        struct rte_mbuf m;
@@ -922,7 +903,8 @@ virtio_dev_tx(struct virtio_net* dev, struct rte_mempool *mbuf_pool)
        if (vq->last_used_idx == avail_idx)
                return;
 
-       LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_tx()\n", dev->device_fh);
+       RTE_LOG_DP(DEBUG, VHOST_DATA, "(%" PRIu64 ") virtio_dev_tx()\n",
+               dev->device_fh);
 
        /* Prefetch available ring to retrieve head indexes. */
        rte_prefetch0(&vq->avail->ring[vq->last_used_idx & (vq->size - 1)]);
@@ -931,7 +913,8 @@ virtio_dev_tx(struct virtio_net* dev, struct rte_mempool *mbuf_pool)
        free_entries = avail_idx - vq->last_used_idx;
        free_entries = unlikely(free_entries < MAX_PKT_BURST) ? free_entries : MAX_PKT_BURST;
 
-       LOG_DEBUG(VHOST_DATA, "(%"PRIu64") Buffers available %d\n", dev->device_fh, free_entries);
+       RTE_LOG_DP(DEBUG, VHOST_DATA, "(%" PRIu64 ") Buffers available %d\n",
+               dev->device_fh, free_entries);
        /* Retrieve all of the head indexes first to avoid caching issues. */
        for (i = 0; i < free_entries; i++)
                head[i] = vq->avail->ring[(vq->last_used_idx + i) & (vq->size - 1)];
@@ -1020,7 +1003,9 @@ switch_worker(__attribute__((unused)) void *arg)
                if (unlikely(diff_tsc > drain_tsc)) {
 
                        if (tx_q->len) {
-                               LOG_DEBUG(VHOST_DATA, "TX queue drained after timeout with burst size %u \n", tx_q->len);
+                               RTE_LOG_DP(DEBUG, VHOST_DATA,
+                                       "TX queue drained after timeout with burst size %u\n",
+                                       tx_q->len);
 
                                /*Tx any packets in the queue*/
                                ret = rte_eth_tx_burst(ports[0], (uint16_t)tx_q->txq_id,
@@ -1422,8 +1407,7 @@ print_stats(void)
 int init_virtio_net(struct virtio_net_device_ops const * const ops);
 
 /*
- * Main function, does initialisation and calls the per-lcore functions. The CUSE
- * device is also registered here to handle the IOCTLs.
+ * Main function, does initialisation and calls the per-lcore functions.
  */
 int
 main(int argc, char *argv[])
@@ -1460,8 +1444,6 @@ main(int argc, char *argv[])
 
        /* Get the number of physical ports. */
        nb_ports = rte_eth_dev_count();
-       if (nb_ports > RTE_MAX_ETHPORTS)
-               nb_ports = RTE_MAX_ETHPORTS;
 
        /*
         * Update the global var NUM_PORTS and global array PORTS
@@ -1482,9 +1464,6 @@ main(int argc, char *argv[])
        if (mbuf_pool == NULL)
                rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
 
-       /* Set log level. */
-       rte_set_log_level(LOG_LEVEL);
-
        /* initialize all ports */
        for (portid = 0; portid < nb_ports; portid++) {
                /* skip ports that are not enabled */
@@ -1514,7 +1493,7 @@ main(int argc, char *argv[])
                snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "print-xen-stats");
                ret = rte_thread_setname(tid, thread_name);
                if (ret != 0)
-                       RTE_LOG(ERR, VHOST_CONFIG,
+                       RTE_LOG(DEBUG, VHOST_CONFIG,
                                "Cannot set print-stats name\n");
        }