ethdev: forbid MTU set before device configure
[dpdk.git] / lib / ethdev / rte_ethdev.c
index 4d702d5..0d7dd68 100644 (file)
@@ -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)
@@ -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.
@@ -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;
        }
@@ -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;
        }
 
@@ -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;
        }
@@ -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;
        }