ethdev: save VLAN filter setting
[dpdk.git] / lib / librte_ether / rte_ethdev.c
index 798af41..76179fd 100644 (file)
@@ -179,9 +179,11 @@ rte_eth_dev_allocated(const char *name)
        unsigned i;
 
        for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-               if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
-                   strcmp(rte_eth_devices[i].data->name, name) == 0)
-                       return &rte_eth_devices[i];
+               if (rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED &&
+                               rte_eth_devices[i].device) {
+                       if (!strcmp(rte_eth_devices[i].device->name, name))
+                               return &rte_eth_devices[i];
+               }
        }
        return NULL;
 }
@@ -311,7 +313,7 @@ rte_eth_dev_count(void)
 int
 rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
 {
-       char *tmp;
+       const char *tmp;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
@@ -322,7 +324,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
 
        /* shouldn't check 'rte_eth_devices[i].data',
         * because it might be overwritten by VDEV PMD */
-       tmp = rte_eth_dev_data[port_id].name;
+       tmp = rte_eth_devices[port_id].device->name;
        strcpy(name, tmp);
        return 0;
 }
@@ -330,6 +332,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
 int
 rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
 {
+       int ret;
        int i;
 
        if (name == NULL) {
@@ -341,11 +344,13 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
                return -ENODEV;
 
        RTE_ETH_FOREACH_DEV(i) {
-               if (!strncmp(name,
-                       rte_eth_dev_data[i].name, strlen(name))) {
+               if (!rte_eth_devices[i].device)
+                       continue;
 
+               ret = strncmp(name, rte_eth_devices[i].device->name,
+                               strlen(name));
+               if (ret == 0) {
                        *port_id = i;
-
                        return 0;
                }
        }
@@ -438,8 +443,8 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
        if (rte_eth_dev_is_detachable(port_id))
                goto err;
 
-       snprintf(name, sizeof(rte_eth_devices[port_id].data->name),
-                "%s", rte_eth_devices[port_id].data->name);
+       snprintf(name, sizeof(rte_eth_devices[port_id].device->name),
+                "%s", rte_eth_devices[port_id].device->name);
 
        ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
        if (ret < 0)
@@ -1976,6 +1981,7 @@ int
 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
 {
        struct rte_eth_dev *dev;
+       int ret;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
@@ -1991,7 +1997,23 @@ rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
        }
        RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
 
-       return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
+       ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
+       if (ret == 0) {
+               struct rte_vlan_filter_conf *vfc;
+               int vidx;
+               int vbit;
+
+               vfc = &dev->data->vlan_filter_conf;
+               vidx = vlan_id / 64;
+               vbit = vlan_id % 64;
+
+               if (on)
+                       vfc->ids[vidx] |= UINT64_C(1) << vbit;
+               else
+                       vfc->ids[vidx] &= ~(UINT64_C(1) << vbit);
+       }
+
+       return ret;
 }
 
 int
@@ -3355,3 +3377,40 @@ rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
                                -ENOTSUP);
        return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
 }
+
+static void
+rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
+                          const struct rte_eth_desc_lim *desc_lim)
+{
+       if (desc_lim->nb_align != 0)
+               *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
+
+       if (desc_lim->nb_max != 0)
+               *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
+
+       *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
+}
+
+int
+rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
+                                uint16_t *nb_rx_desc,
+                                uint16_t *nb_tx_desc)
+{
+       struct rte_eth_dev *dev;
+       struct rte_eth_dev_info dev_info;
+
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+
+       dev = &rte_eth_devices[port_id];
+       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
+
+       rte_eth_dev_info_get(port_id, &dev_info);
+
+       if (nb_rx_desc != NULL)
+               rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
+
+       if (nb_tx_desc != NULL)
+               rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
+
+       return 0;
+}