ethdev: fix Rx/Tx spelling
[dpdk.git] / lib / ethdev / rte_ethdev.c
index 982c1bb..f344da8 100644 (file)
@@ -50,10 +50,10 @@ struct rte_eth_fp_ops rte_eth_fp_ops[RTE_MAX_ETHPORTS];
 /* spinlock for eth device callbacks */
 static rte_spinlock_t eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
 
-/* spinlock for add/remove rx callbacks */
+/* spinlock for add/remove Rx callbacks */
 static rte_spinlock_t eth_dev_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
 
-/* spinlock for add/remove tx callbacks */
+/* spinlock for add/remove Tx callbacks */
 static rte_spinlock_t eth_dev_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
 
 /* spinlock for shared data allocation */
@@ -1293,7 +1293,7 @@ eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads,
 
        while (offloads_diff != 0) {
                /* Check if any offload is requested but not enabled. */
-               offload = 1ULL << __builtin_ctzll(offloads_diff);
+               offload = RTE_BIT64(__builtin_ctzll(offloads_diff));
                if (offload & req_offloads) {
                        RTE_ETHDEV_LOG(ERR,
                                "Port %u failed to enable %s offload %s\n",
@@ -1327,6 +1327,47 @@ eth_dev_get_overhead_len(uint32_t max_rx_pktlen, uint16_t max_mtu)
        return overhead_len;
 }
 
+/* rte_eth_dev_info_get() should be called prior to this function */
+static int
+eth_dev_validate_mtu(uint16_t port_id, struct rte_eth_dev_info *dev_info,
+               uint16_t mtu)
+{
+       uint32_t overhead_len;
+       uint32_t frame_size;
+
+       if (mtu < dev_info->min_mtu) {
+               RTE_ETHDEV_LOG(ERR,
+                       "MTU (%u) < device min MTU (%u) for port_id %u\n",
+                       mtu, dev_info->min_mtu, port_id);
+               return -EINVAL;
+       }
+       if (mtu > dev_info->max_mtu) {
+               RTE_ETHDEV_LOG(ERR,
+                       "MTU (%u) > device max MTU (%u) for port_id %u\n",
+                       mtu, dev_info->max_mtu, port_id);
+               return -EINVAL;
+       }
+
+       overhead_len = eth_dev_get_overhead_len(dev_info->max_rx_pktlen,
+                       dev_info->max_mtu);
+       frame_size = mtu + overhead_len;
+       if (frame_size < RTE_ETHER_MIN_LEN) {
+               RTE_ETHDEV_LOG(ERR,
+                       "Frame size (%u) < min frame size (%u) for port_id %u\n",
+                       frame_size, RTE_ETHER_MIN_LEN, port_id);
+               return -EINVAL;
+       }
+
+       if (frame_size > dev_info->max_rx_pktlen) {
+               RTE_ETHDEV_LOG(ERR,
+                       "Frame size (%u) > device max frame size (%u) for port_id %u\n",
+                       frame_size, dev_info->max_rx_pktlen, port_id);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 int
 rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
                      const struct rte_eth_conf *dev_conf)
@@ -1334,8 +1375,6 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
        struct rte_eth_dev *dev;
        struct rte_eth_dev_info dev_info;
        struct rte_eth_conf orig_conf;
-       uint32_t max_rx_pktlen;
-       uint32_t overhead_len;
        int diag;
        int ret;
        uint16_t old_mtu;
@@ -1384,10 +1423,6 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
        if (ret != 0)
                goto rollback;
 
-       /* Get the real Ethernet overhead length */
-       overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
-                       dev_info.max_mtu);
-
        /* If number of queues specified by application for both Rx and Tx is
         * zero, use driver preferred values. This cannot be done individually
         * as it is valid for either Tx or Rx (but not both) to be zero.
@@ -1405,7 +1440,7 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 
        if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
                RTE_ETHDEV_LOG(ERR,
-                       "Number of RX queues requested (%u) is greater than max supported(%d)\n",
+                       "Number of Rx queues requested (%u) is greater than max supported(%d)\n",
                        nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
                ret = -EINVAL;
                goto rollback;
@@ -1413,15 +1448,15 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 
        if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
                RTE_ETHDEV_LOG(ERR,
-                       "Number of TX queues requested (%u) is greater than max supported(%d)\n",
+                       "Number of Tx queues requested (%u) is greater than max supported(%d)\n",
                        nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
                ret = -EINVAL;
                goto rollback;
        }
 
        /*
-        * Check that the numbers of RX and TX queues are not greater
-        * than the maximum number of RX and TX queues supported by the
+        * Check that the numbers of Rx and Tx queues are not greater
+        * than the maximum number of Rx and Tx queues supported by the
         * configured device.
         */
        if (nb_rx_q > dev_info.max_rx_queues) {
@@ -1454,26 +1489,13 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
                goto rollback;
        }
 
-       /*
-        * Check that the maximum RX packet length is supported by the
-        * configured device.
-        */
        if (dev_conf->rxmode.mtu == 0)
                dev->data->dev_conf.rxmode.mtu = RTE_ETHER_MTU;
-       max_rx_pktlen = dev->data->dev_conf.rxmode.mtu + overhead_len;
-       if (max_rx_pktlen > dev_info.max_rx_pktlen) {
-               RTE_ETHDEV_LOG(ERR,
-                       "Ethdev port_id=%u max_rx_pktlen %u > max valid value %u\n",
-                       port_id, max_rx_pktlen, dev_info.max_rx_pktlen);
-               ret = -EINVAL;
-               goto rollback;
-       } else if (max_rx_pktlen < RTE_ETHER_MIN_LEN) {
-               RTE_ETHDEV_LOG(ERR,
-                       "Ethdev port_id=%u max_rx_pktlen %u < min valid value %u\n",
-                       port_id, max_rx_pktlen, RTE_ETHER_MIN_LEN);
-               ret = -EINVAL;
+
+       ret = eth_dev_validate_mtu(port_id, &dev_info,
+                       dev->data->dev_conf.rxmode.mtu);
+       if (ret != 0)
                goto rollback;
-       }
 
        dev->data->mtu = dev->data->dev_conf.rxmode.mtu;
 
@@ -1482,6 +1504,12 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
         * size is supported by the configured device.
         */
        if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_TCP_LRO) {
+               uint32_t max_rx_pktlen;
+               uint32_t overhead_len;
+
+               overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
+                               dev_info.max_mtu);
+               max_rx_pktlen = dev->data->dev_conf.rxmode.mtu + overhead_len;
                if (dev_conf->rxmode.max_lro_pkt_size == 0)
                        dev->data->dev_conf.rxmode.max_lro_pkt_size = max_rx_pktlen;
                ret = eth_dev_check_lro_pkt_size(port_id,
@@ -1543,7 +1571,7 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
        }
 
        /*
-        * Setup new number of RX/TX queues and reconfigure device.
+        * Setup new number of Rx/Tx queues and reconfigure device.
         */
        diag = eth_dev_rx_queue_config(dev, nb_rx_q);
        if (diag != 0) {
@@ -1659,7 +1687,7 @@ eth_dev_mac_restore(struct rte_eth_dev *dev,
                        pool_mask = dev->data->mac_pool_sel[i];
 
                        do {
-                               if (pool_mask & 1ULL)
+                               if (pool_mask & UINT64_C(1))
                                        (*dev->dev_ops->mac_addr_add)(dev,
                                                addr, i, pool);
                                pool_mask >>= 1;
@@ -1865,6 +1893,12 @@ rte_eth_dev_close(uint16_t port_id)
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
+       if (dev->data->dev_started) {
+               RTE_ETHDEV_LOG(ERR, "Cannot close started device (port %u)\n",
+                              port_id);
+               return -EINVAL;
+       }
+
        RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
        *lasterr = (*dev->dev_ops->dev_close)(dev);
        if (*lasterr != 0)
@@ -1941,7 +1975,7 @@ rte_eth_rx_queue_check_split(const struct rte_eth_rxseg_split *rx_seg,
         * for each segment specified in extended configuration.
         */
        mp_first = rx_seg[0].mp;
-       offset_mask = (1u << seg_capa->offset_align_log2) - 1;
+       offset_mask = RTE_BIT32(seg_capa->offset_align_log2) - 1;
        for (seg_idx = 0; seg_idx < n_seg; seg_idx++) {
                struct rte_mempool *mpl = rx_seg[seg_idx].mp;
                uint32_t length = rx_seg[seg_idx].length;
@@ -2007,7 +2041,7 @@ rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
        dev = &rte_eth_devices[port_id];
 
        if (rx_queue_id >= dev->data->nb_rx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", rx_queue_id);
                return -EINVAL;
        }
 
@@ -2192,7 +2226,7 @@ rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
        dev = &rte_eth_devices[port_id];
 
        if (rx_queue_id >= dev->data->nb_rx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", rx_queue_id);
                return -EINVAL;
        }
 
@@ -2264,7 +2298,7 @@ rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
        dev = &rte_eth_devices[port_id];
 
        if (tx_queue_id >= dev->data->nb_tx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Tx queue_id=%u\n", tx_queue_id);
                return -EINVAL;
        }
 
@@ -2358,7 +2392,7 @@ rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
        dev = &rte_eth_devices[port_id];
 
        if (tx_queue_id >= dev->data->nb_tx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Tx queue_id=%u\n", tx_queue_id);
                return -EINVAL;
        }
 
@@ -3400,7 +3434,8 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
        dev_info->rx_desc_lim = lim;
        dev_info->tx_desc_lim = lim;
        dev_info->device = dev->device;
-       dev_info->min_mtu = RTE_ETHER_MIN_MTU;
+       dev_info->min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN -
+               RTE_ETHER_CRC_LEN;
        dev_info->max_mtu = UINT16_MAX;
 
        RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
@@ -3651,21 +3686,13 @@ rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
         * which relies on dev->dev_ops->dev_infos_get.
         */
        if (*dev->dev_ops->dev_infos_get != NULL) {
-               uint16_t overhead_len;
-               uint32_t frame_size;
-
                ret = rte_eth_dev_info_get(port_id, &dev_info);
                if (ret != 0)
                        return ret;
 
-               if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu)
-                       return -EINVAL;
-
-               overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
-                               dev_info.max_mtu);
-               frame_size = mtu + overhead_len;
-               if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)
-                       return -EINVAL;
+               ret = eth_dev_validate_mtu(port_id, &dev_info, mtu);
+               if (ret != 0)
+                       return ret;
        }
 
        ret = (*dev->dev_ops->mtu_set)(dev, mtu);
@@ -3709,9 +3736,9 @@ rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
                vbit = vlan_id % 64;
 
                if (on)
-                       vfc->ids[vidx] |= UINT64_C(1) << vbit;
+                       vfc->ids[vidx] |= RTE_BIT64(vbit);
                else
-                       vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
+                       vfc->ids[vidx] &= ~RTE_BIT64(vbit);
        }
 
        return eth_err(port_id, ret);
@@ -3983,7 +4010,7 @@ eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
        for (i = 0; i < reta_size; i++) {
                idx = i / RTE_RETA_GROUP_SIZE;
                shift = i % RTE_RETA_GROUP_SIZE;
-               if ((reta_conf[idx].mask & (1ULL << shift)) &&
+               if ((reta_conf[idx].mask & RTE_BIT64(shift)) &&
                        (reta_conf[idx].reta[shift] >= max_rxq)) {
                        RTE_ETHDEV_LOG(ERR,
                                "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n",
@@ -4322,7 +4349,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
                pool_mask = dev->data->mac_pool_sel[index];
 
                /* Check if both MAC address and pool is already there, and do nothing */
-               if (pool_mask & (1ULL << pool))
+               if (pool_mask & RTE_BIT64(pool))
                        return 0;
        }
 
@@ -4334,7 +4361,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
                rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]);
 
                /* Update pool bitmap in NIC data structure */
-               dev->data->mac_pool_sel[index] |= (1ULL << pool);
+               dev->data->mac_pool_sel[index] |= RTE_BIT64(pool);
        }
 
        return eth_err(port_id, ret);
@@ -4750,13 +4777,13 @@ rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
        dev = &rte_eth_devices[port_id];
 
        if (!dev->intr_handle) {
-               RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
+               RTE_ETHDEV_LOG(ERR, "Rx Intr handle unset\n");
                return -ENOTSUP;
        }
 
        intr_handle = dev->intr_handle;
        if (!intr_handle->intr_vec) {
-               RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
+               RTE_ETHDEV_LOG(ERR, "Rx Intr vector unset\n");
                return -EPERM;
        }
 
@@ -4765,7 +4792,7 @@ rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
                rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
                if (rc && rc != -EEXIST) {
                        RTE_ETHDEV_LOG(ERR,
-                               "p %u q %u rx ctl error op %d epfd %d vec %u\n",
+                               "p %u q %u Rx ctl error op %d epfd %d vec %u\n",
                                port_id, qid, op, epfd, vec);
                }
        }
@@ -4786,18 +4813,18 @@ rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
        dev = &rte_eth_devices[port_id];
 
        if (queue_id >= dev->data->nb_rx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", queue_id);
                return -1;
        }
 
        if (!dev->intr_handle) {
-               RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
+               RTE_ETHDEV_LOG(ERR, "Rx Intr handle unset\n");
                return -1;
        }
 
        intr_handle = dev->intr_handle;
        if (!intr_handle->intr_vec) {
-               RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
+               RTE_ETHDEV_LOG(ERR, "Rx Intr vector unset\n");
                return -1;
        }
 
@@ -4972,18 +4999,18 @@ rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
        dev = &rte_eth_devices[port_id];
 
        if (queue_id >= dev->data->nb_rx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", queue_id);
                return -EINVAL;
        }
 
        if (!dev->intr_handle) {
-               RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n");
+               RTE_ETHDEV_LOG(ERR, "Rx Intr handle unset\n");
                return -ENOTSUP;
        }
 
        intr_handle = dev->intr_handle;
        if (!intr_handle->intr_vec) {
-               RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n");
+               RTE_ETHDEV_LOG(ERR, "Rx Intr vector unset\n");
                return -EPERM;
        }
 
@@ -4991,7 +5018,7 @@ rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
        rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
        if (rc && rc != -EEXIST) {
                RTE_ETHDEV_LOG(ERR,
-                       "p %u q %u rx ctl error op %d epfd %d vec %u\n",
+                       "p %u q %u Rx ctl error op %d epfd %d vec %u\n",
                        port_id, queue_id, op, epfd, vec);
                return rc;
        }
@@ -5269,7 +5296,7 @@ rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
        dev = &rte_eth_devices[port_id];
 
        if (queue_id >= dev->data->nb_rx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", queue_id);
                return -EINVAL;
        }
 
@@ -5314,7 +5341,7 @@ rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
        dev = &rte_eth_devices[port_id];
 
        if (queue_id >= dev->data->nb_tx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Tx queue_id=%u\n", queue_id);
                return -EINVAL;
        }
 
@@ -5359,7 +5386,7 @@ rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
        dev = &rte_eth_devices[port_id];
 
        if (queue_id >= dev->data->nb_rx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", queue_id);
                return -EINVAL;
        }
 
@@ -5386,7 +5413,7 @@ rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
        dev = &rte_eth_devices[port_id];
 
        if (queue_id >= dev->data->nb_tx_queues) {
-               RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id);
+               RTE_ETHDEV_LOG(ERR, "Invalid Tx queue_id=%u\n", queue_id);
                return -EINVAL;
        }