ethdev: forbid MTU set before device configure
[dpdk.git] / lib / ethdev / rte_ethdev.c
index f981e02..0d7dd68 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 */
@@ -167,6 +167,15 @@ static const struct {
 
 #undef RTE_TX_OFFLOAD_BIT2STR
 
+static const struct {
+       uint64_t offload;
+       const char *name;
+} rte_eth_dev_capa_names[] = {
+       {RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP, "RUNTIME_RX_QUEUE_SETUP"},
+       {RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP, "RUNTIME_TX_QUEUE_SETUP"},
+       {RTE_ETH_DEV_CAPA_RXQ_SHARE, "RXQ_SHARE"},
+};
+
 /**
  * The user application callback description.
  *
@@ -538,7 +547,7 @@ unlock:
 
 /*
  * Attach to a port already registered by the primary process, which
- * makes sure that the same device would have the same port id both
+ * makes sure that the same device would have the same port ID both
  * in the primary and secondary process.
  */
 struct rte_eth_dev *
@@ -668,7 +677,7 @@ eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id,
        struct rte_eth_dev_owner *port_owner;
 
        if (port_id >= RTE_MAX_ETHPORTS || !eth_dev_is_allocated(ethdev)) {
-               RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
+               RTE_ETHDEV_LOG(ERR, "Port ID %"PRIu16" is not allocated\n",
                        port_id);
                return -ENODEV;
        }
@@ -760,7 +769,7 @@ rte_eth_dev_owner_delete(const uint64_t owner_id)
                        owner_id);
        } else {
                RTE_ETHDEV_LOG(ERR,
-                              "Invalid owner id=%016"PRIx64"\n",
+                              "Invalid owner ID=%016"PRIx64"\n",
                               owner_id);
                ret = -EINVAL;
        }
@@ -779,7 +788,7 @@ rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
        ethdev = &rte_eth_devices[port_id];
 
        if (!eth_dev_is_allocated(ethdev)) {
-               RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
+               RTE_ETHDEV_LOG(ERR, "Port ID %"PRIu16" is not allocated\n",
                        port_id);
                return -ENODEV;
        }
@@ -1236,6 +1245,22 @@ rte_eth_dev_tx_offload_name(uint64_t offload)
        return name;
 }
 
+const char *
+rte_eth_dev_capability_name(uint64_t capability)
+{
+       const char *name = "UNKNOWN";
+       unsigned int i;
+
+       for (i = 0; i < RTE_DIM(rte_eth_dev_capa_names); ++i) {
+               if (capability == rte_eth_dev_capa_names[i].offload) {
+                       name = rte_eth_dev_capa_names[i].name;
+                       break;
+               }
+       }
+
+       return name;
+}
+
 static inline int
 eth_dev_check_lro_pkt_size(uint16_t port_id, uint32_t config_size,
                   uint32_t max_rx_pkt_len, uint32_t dev_info_size)
@@ -1265,14 +1290,14 @@ eth_dev_check_lro_pkt_size(uint16_t port_id, uint32_t config_size,
 
 /*
  * Validate offloads that are requested through rte_eth_dev_configure against
- * the offloads successfully set by the ethernet device.
+ * the offloads successfully set by the Ethernet device.
  *
  * @param port_id
  *   The port identifier of the Ethernet device.
  * @param req_offloads
  *   The offloads that have been requested through `rte_eth_dev_configure`.
  * @param set_offloads
- *   The offloads successfully set by the ethernet device.
+ *   The offloads successfully set by the Ethernet device.
  * @param offload_type
  *   The offload type i.e. Rx/Tx string.
  * @param offload_name
@@ -1293,7 +1318,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",
@@ -1440,7 +1465,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;
@@ -1448,15 +1473,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) {
@@ -1571,7 +1596,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) {
@@ -1687,7 +1712,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;
@@ -1975,7 +2000,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;
@@ -2041,7 +2066,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;
        }
 
@@ -2175,6 +2200,14 @@ rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
                return -EINVAL;
        }
 
+       if (local_conf.share_group > 0 &&
+           (dev_info.dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE) == 0) {
+               RTE_ETHDEV_LOG(ERR,
+                       "Ethdev port_id=%d rx_queue_id=%d, enabled share_group=%hu while device doesn't support Rx queue share\n",
+                       port_id, rx_queue_id, local_conf.share_group);
+               return -EINVAL;
+       }
+
        /*
         * If LRO is enabled, check that the maximum aggregated packet
         * size is supported by the configured device.
@@ -2226,7 +2259,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;
        }
 
@@ -2298,7 +2331,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;
        }
 
@@ -2392,7 +2425,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;
        }
 
@@ -3695,6 +3728,13 @@ rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
                        return ret;
        }
 
+       if (dev->data->dev_configured == 0) {
+               RTE_ETHDEV_LOG(ERR,
+                       "Port %u must be configured before MTU set\n",
+                       port_id);
+               return -EINVAL;
+       }
+
        ret = (*dev->dev_ops->mtu_set)(dev, mtu);
        if (ret == 0)
                dev->data->mtu = mtu;
@@ -3713,7 +3753,7 @@ rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
 
        if (!(dev->data->dev_conf.rxmode.offloads &
              DEV_RX_OFFLOAD_VLAN_FILTER)) {
-               RTE_ETHDEV_LOG(ERR, "Port %u: vlan-filtering disabled\n",
+               RTE_ETHDEV_LOG(ERR, "Port %u: VLAN-filtering disabled\n",
                        port_id);
                return -ENOSYS;
        }
@@ -3736,9 +3776,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);
@@ -4010,7 +4050,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",
@@ -4333,7 +4373,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
                return -EINVAL;
        }
        if (pool >= ETH_64_POOLS) {
-               RTE_ETHDEV_LOG(ERR, "Pool id must be 0-%d\n", ETH_64_POOLS - 1);
+               RTE_ETHDEV_LOG(ERR, "Pool ID must be 0-%d\n", ETH_64_POOLS - 1);
                return -EINVAL;
        }
 
@@ -4349,7 +4389,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;
        }
 
@@ -4361,7 +4401,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);
@@ -4558,7 +4598,7 @@ int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
 
        if (queue_idx > dev_info.max_tx_queues) {
                RTE_ETHDEV_LOG(ERR,
-                       "Set queue rate limit:port %u: invalid queue id=%u\n",
+                       "Set queue rate limit:port %u: invalid queue ID=%u\n",
                        port_id, queue_idx);
                return -EINVAL;
        }
@@ -4777,13 +4817,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;
        }
 
@@ -4792,7 +4832,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);
                }
        }
@@ -4813,18 +4853,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;
        }
 
@@ -4999,18 +5039,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;
        }
 
@@ -5018,7 +5058,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;
        }
@@ -5296,7 +5336,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;
        }
 
@@ -5341,7 +5381,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;
        }
 
@@ -5386,7 +5426,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;
        }
 
@@ -5413,7 +5453,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;
        }
 
@@ -6415,7 +6455,7 @@ rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features)
 
        if (dev->data->dev_configured != 0) {
                RTE_ETHDEV_LOG(ERR,
-                       "The port (id=%"PRIu16") is already configured\n",
+                       "The port (ID=%"PRIu16") is already configured\n",
                        port_id);
                return -EBUSY;
        }