Пример #1
0
int kni_del_dev(struct netif_port *dev)
{
    if (!kni_dev_exist(dev))
        return EDPVS_INVAL;

    rte_kni_release(dev->kni.kni);
    dev->kni.kni = NULL;
    return EDPVS_OK;
}
Пример #2
0
int odp_kni_destory()
{
	for (int port = 0; port < RTE_MAX_ETHPORTS; port++) {
		/* Skip ports that are not enabled */
		if(kni_port_params_array[port] == NULL)
			continue;

		rte_kni_release(kni_port_params_array[port]->kni);
		rte_free(kni_port_params_array[port]);
	}
}
Пример #3
0
static int
kni_free_kni(uint8_t port_id)
{
	uint8_t i;
	struct kni_port_params **p = kni_port_params_array;

	if (port_id >= RTE_MAX_ETHPORTS || !p[port_id])
		return -1;

	rte_kni_release(p[i]->kni);
	p[i]->kni = NULL;

	return 0;
}
Пример #4
0
/* 
 * @dev     - real device kni attach to.
 * @kniname - optional, kni device name or auto generate.
 */
int kni_add_dev(struct netif_port *dev, const char *kniname)
{
    struct rte_kni_conf conf;
    struct rte_kni *kni;
    int err;

    if (!dev)
        return EDPVS_INVAL;

    if (dev->type == PORT_TYPE_BOND_SLAVE)
        return EDPVS_NOTSUPP;

    if (kni_dev_exist(dev)) {
        RTE_LOG(ERR, Kni, "%s: dev %s has already attached with kni\n",
                __func__, dev->name);
        return EDPVS_EXIST;
    }

    kni_fill_conf(dev, kniname, &conf);

    kni = rte_kni_alloc(kni_mbuf_pool[dev->socket], &conf, NULL);
    if (!kni)
        return EDPVS_DPDKAPIFAIL;

    err = kni_rtnl_init(dev);
    if (err != EDPVS_OK) {
        rte_kni_release(kni);
        return err;
    }

    /*
     * kni device should use same mac as real device,
     * because it may config same IP of real device.
     * diff mac means kni cannot accept packets sent
     * to real-device.
     */
    err = linux_set_if_mac(conf.name, (unsigned char *)&dev->addr);
    if (err != EDPVS_OK) {
        char mac[18];
        ether_format_addr(mac, sizeof(mac), &dev->addr);
        RTE_LOG(WARNING, Kni, "%s: fail to set mac %s for %s: %s\n",
                __func__, mac, conf.name, strerror(errno));
    }

    snprintf(dev->kni.name, sizeof(dev->kni.name), "%s", conf.name);
    dev->kni.addr = dev->addr;
    dev->kni.kni = kni;
    return EDPVS_OK;
}
Пример #5
0
int
kni_free_kni(uint8_t port_id)
{
	uint8_t i;
	struct kni_port_params** p = kni_port_params_array;

	if (port_id >= RTE_MAX_ETHPORTS || !p[port_id])
		return -1;

	for (i = 0; i < p[port_id]->nb_kni; i++) {
		rte_kni_release(p[port_id]->kni[i]);
		p[port_id]->kni[i] = NULL;
	}

	return 0;
}
/*
 * vr_dpdk_knidev_release - release KNI interface and remove it from the
 * global list.
 * Returns 0 on success, < 0 otherwise.
 */
int
vr_dpdk_knidev_release(struct vr_interface *vif)
{
    int i;
    struct rte_kni *kni = vif->vif_os;

    vif->vif_os = NULL;

    /* delete the interface from the table of KNIs */
    for (i = 0; i < VR_DPDK_MAX_KNI_INTERFACES; i++) {
        if (vr_dpdk.knis[i] == kni) {
            vr_dpdk.knis[i] = NULL;
            break;
        }
    }
    rte_wmb();

    return rte_kni_release(kni);
}
Пример #7
0
int 
rw_piot_kni_destroy(struct rte_kni *kni)
{
  rte_kni_release(kni);
  return(0); 
}
Пример #8
0
/* Init KNI RX queue */
struct vr_dpdk_queue *
vr_dpdk_kni_rx_queue_init(unsigned lcore_id, struct vr_interface *vif,
    unsigned host_lcore_id)
{
    struct vr_dpdk_lcore *lcore = vr_dpdk.lcores[lcore_id];
    const unsigned socket_id = rte_lcore_to_socket_id(lcore_id);
    uint8_t port_id = 0;
    unsigned vif_idx = vif->vif_idx;
    struct vr_dpdk_queue *rx_queue = &lcore->lcore_rx_queues[vif_idx];
    struct vr_dpdk_queue_params *rx_queue_params
                    = &lcore->lcore_rx_queue_params[vif_idx];

    if (vif->vif_type == VIF_TYPE_HOST) {
        port_id = (((struct vr_dpdk_ethdev *)(vif->vif_bridge->vif_os))->
                ethdev_port_id);
    }

    /* init queue */
    rx_queue->rxq_ops = dpdk_knidev_reader_ops;
    rx_queue->q_queue_h = NULL;
    rx_queue->q_vif = vrouter_get_interface(vif->vif_rid, vif_idx);

    /* create the queue */
    struct dpdk_knidev_reader_params reader_params = {
        .kni = vif->vif_os,
    };
    rx_queue->q_queue_h = rx_queue->rxq_ops.f_create(&reader_params, socket_id);
    if (rx_queue->q_queue_h == NULL) {
        RTE_LOG(ERR, VROUTER, "    error creating KNI device %s RX queue"
            " at eth device %" PRIu8 "\n", vif->vif_name, port_id);
        return NULL;
    }

    /* store queue params */
    rx_queue_params->qp_release_op = &dpdk_kni_rx_queue_release;

    return rx_queue;
}

/* Release KNI TX queue */
static void
dpdk_kni_tx_queue_release(unsigned lcore_id, struct vr_interface *vif)
{
    struct vr_dpdk_lcore *lcore = vr_dpdk.lcores[lcore_id];
    struct vr_dpdk_queue *tx_queue = &lcore->lcore_tx_queues[vif->vif_idx];
    struct vr_dpdk_queue_params *tx_queue_params
                        = &lcore->lcore_tx_queue_params[vif->vif_idx];

    tx_queue->txq_ops.f_tx = NULL;
    rte_wmb();

    /* flush and free the queue */
    if (tx_queue->txq_ops.f_free(tx_queue->q_queue_h)) {
        RTE_LOG(ERR, VROUTER, "    error freeing lcore %u KNI device TX queue\n",
                    lcore_id);
    }

    /* reset the queue */
    vrouter_put_interface(tx_queue->q_vif);
    memset(tx_queue, 0, sizeof(*tx_queue));
    memset(tx_queue_params, 0, sizeof(*tx_queue_params));
}

/* Init KNI TX queue */
struct vr_dpdk_queue *
vr_dpdk_kni_tx_queue_init(unsigned lcore_id, struct vr_interface *vif,
    unsigned host_lcore_id)
{
    struct vr_dpdk_lcore *lcore = vr_dpdk.lcores[lcore_id];
    const unsigned socket_id = rte_lcore_to_socket_id(lcore_id);
    uint8_t port_id = 0;
    unsigned vif_idx = vif->vif_idx;
    struct vr_dpdk_queue *tx_queue = &lcore->lcore_tx_queues[vif_idx];
    struct vr_dpdk_queue_params *tx_queue_params
                    = &lcore->lcore_tx_queue_params[vif_idx];
    struct vr_dpdk_ethdev *ethdev;

    if (vif->vif_type == VIF_TYPE_HOST) {
        ethdev = vif->vif_bridge->vif_os;
        if (ethdev == NULL) {
            RTE_LOG(ERR, VROUTER, "    error creating KNI device %s TX queue:"
                " bridge vif %u ethdev is not initialized\n",
                vif->vif_name, vif->vif_bridge->vif_idx);
            return NULL;
        }
        port_id = ethdev->ethdev_port_id;
    }

    /* init queue */
    tx_queue->txq_ops = dpdk_knidev_writer_ops;
    tx_queue->q_queue_h = NULL;
    tx_queue->q_vif = vrouter_get_interface(vif->vif_rid, vif_idx);

    /* create the queue */
    struct dpdk_knidev_writer_params writer_params = {
        .kni = vif->vif_os,
        .tx_burst_sz = VR_DPDK_TX_BURST_SZ,
    };
    tx_queue->q_queue_h = tx_queue->txq_ops.f_create(&writer_params, socket_id);
    if (tx_queue->q_queue_h == NULL) {
        RTE_LOG(ERR, VROUTER, "    error creating KNI device %s TX queue"
            " at eth device %" PRIu8 "\n", vif->vif_name, port_id);
        return NULL;
    }

    /* store queue params */
    tx_queue_params->qp_release_op = &dpdk_kni_tx_queue_release;

    return tx_queue;
}

/* Change KNI MTU size callback */
static int
dpdk_knidev_change_mtu(uint8_t port_id, unsigned new_mtu)
{
    struct vrouter *router = vrouter_get(0);
    struct vr_interface *vif;
    int i, ret;
    uint8_t slave_port_id;
    struct vr_dpdk_ethdev *ethdev = NULL;

    if (port_id >= rte_eth_dev_count()) {
        RTE_LOG(ERR, VROUTER,
                "Error changing eth device %"PRIu8" MTU: invalid eth device\n",
                port_id);
        return -EINVAL;
    }

    /*
     * TODO: DPDK bond PMD does not implement mtu_set op, so we need to
     * set the MTU manually for all the slaves.
     */
    /* Bond vif uses first slave port ID. */
    if (router->vr_eth_if)
        ethdev = (struct vr_dpdk_ethdev *)router->vr_eth_if->vif_os;

    if (ethdev && vr_dpdk_ethdev_bond_port_match(port_id, ethdev)) {
        RTE_LOG(INFO, VROUTER, "Changing bond eth device %" PRIu8 " MTU\n",
                ethdev->ethdev_port_id);

        rte_eth_devices[ethdev->ethdev_port_id].data->mtu = new_mtu;
        for (i = 0; i < ethdev->ethdev_nb_slaves; i++) {
            slave_port_id = ethdev->ethdev_slaves[i];
            RTE_LOG(INFO, VROUTER,
                    "    changing bond member eth device %" PRIu8 " MTU to %u\n",
                    slave_port_id, new_mtu);

            ret =  rte_eth_dev_set_mtu(slave_port_id, new_mtu);
            if (ret < 0) {
                RTE_LOG(ERR, VROUTER,
                        "    error changing bond member eth device %" PRIu8 " MTU: %s (%d)\n",
                        slave_port_id, rte_strerror(-ret), -ret);
                return ret;
            }
        }
    } else {
        RTE_LOG(INFO, VROUTER, "Changing eth device %" PRIu8 " MTU to %u\n",
                port_id, new_mtu);

        ret =  rte_eth_dev_set_mtu(port_id, new_mtu);
        if (ret < 0) {
            RTE_LOG(ERR, VROUTER,
                    "Error changing eth device %" PRIu8 " MTU: %s (%d)\n",
                    port_id, rte_strerror(-ret), -ret);
            return ret;
        }
    }

    /* On success, inform vrouter about new MTU */
    for (i = 0; i < router->vr_max_interfaces; i++) {
        vif = __vrouter_get_interface(router, i);
        if (vif && (vif->vif_type == VIF_TYPE_PHYSICAL)) {
           /* Ethernet header size */
           new_mtu += sizeof(struct vr_eth);
           if (vr_dpdk.vlan_tag != VLAN_ID_INVALID) {
               /* 802.1q header size */
               new_mtu += sizeof(uint32_t);
           }
           vif->vif_mtu = new_mtu;
           if (vif->vif_bridge)
               vif->vif_bridge->vif_mtu = new_mtu;
        }
    }

    return 0;
}

/* Configure KNI state callback */
static int
dpdk_knidev_config_network_if(uint8_t port_id, uint8_t if_up)
{
    struct vrouter *router = vrouter_get(0);
    struct vr_dpdk_ethdev *ethdev = NULL;
    int ret = 0;

    if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) {
        RTE_LOG(ERR, VROUTER, "%s: Invalid eth device %" PRIu8 "\n",
                __func__, port_id);
        return -EINVAL;
    }

    if (router->vr_eth_if)
        ethdev = (struct vr_dpdk_ethdev *)router->vr_eth_if->vif_os;

    if (ethdev && vr_dpdk_ethdev_bond_port_match(port_id, ethdev))
        port_id = ethdev->ethdev_port_id;

    RTE_LOG(INFO, VROUTER, "Configuring eth device %" PRIu8 " %s\n",
                    port_id, if_up ? "UP" : "DOWN");

    if (if_up)
        ret = rte_eth_dev_start(port_id);
    else
        rte_eth_dev_stop(port_id);

    if (ret < 0) {
        RTE_LOG(ERR, VROUTER, "Configuring eth device %" PRIu8 " UP "
                    "failed (%d)\n", port_id, ret);
    }

    return ret;
}

/*
 * vr_dpdk_knidev_init - initializes Kernel Network Interface device using
 * specified Ethernet device port.
 *
 * Returns 0 on success, < 0 otherwise.
 */
int
vr_dpdk_knidev_init(uint8_t port_id, struct vr_interface *vif)
{
    int i;
    struct rte_eth_dev_info dev_info;
    struct rte_kni_conf kni_conf;
    struct rte_kni_ops kni_ops;
    struct rte_kni *kni;
    struct rte_config *rte_conf = rte_eal_get_configuration();

    if (!vr_dpdk.kni_inited) {
        /*
         * If the host does not support KNIs (i.e. RedHat), we'll get
         * a panic here.
         */
        rte_kni_init(VR_DPDK_MAX_KNI_INTERFACES);
        vr_dpdk.kni_inited = true;
    }

    /* Check if port is valid. */
    if (!rte_eth_dev_is_valid_port(port_id)) {
        RTE_LOG(ERR, VROUTER, "    error initializing KNI device %s: invalid eth device %"
                PRIu8"\n", vif->vif_name, port_id);
        return -EINVAL;
    }

    /* get eth device info */
    memset(&dev_info, 0, sizeof(dev_info));
    rte_eth_dev_info_get(port_id, &dev_info);

    /* create KNI configuration */
    memset(&kni_conf, 0, sizeof(kni_conf));
    strncpy(kni_conf.name, (char *)vif->vif_name, sizeof(kni_conf.name) - 1);

    kni_conf.addr = dev_info.pci_dev->addr;
    kni_conf.id = dev_info.pci_dev->id;
    kni_conf.group_id = port_id;
    kni_conf.mbuf_size = vr_packet_sz;
    /*
     * Due to DPDK commit 41a6ebd, now to prevent packet reordering in KNI
     * we have to bind KNI kernel thread to a first online unused CPU.
     */
    for (i = 0; i < RTE_MAX_LCORE; i++) {
        if (lcore_config[i].detected
                && rte_conf->lcore_role[VR_DPDK_FWD_LCORE_ID + i] == ROLE_OFF) {
            kni_conf.force_bind = 1;
            kni_conf.core_id = i;
            RTE_LOG(INFO, VROUTER, "    bind KNI kernel thread to CPU %d\n", i);
            break;
        }
    }

    /* KNI options
     *
     * Changing state of the KNI interface can change state of the physical
     * interface. This is useful for the vhost, but not for the VLAN
     * forwarding interface.
     */
    if (vif->vif_type == VIF_TYPE_VLAN) {
        memset(&kni_ops, 0, sizeof(kni_ops));
    } else {
        kni_ops.port_id = port_id;
        kni_ops.change_mtu = dpdk_knidev_change_mtu;
        kni_ops.config_network_if = dpdk_knidev_config_network_if;
    }

    /* allocate KNI device */
    kni = rte_kni_alloc(vr_dpdk.rss_mempool, &kni_conf, &kni_ops);
    if (kni == NULL) {
        RTE_LOG(ERR, VROUTER, "    error allocation KNI device %s"
            " at eth device %" PRIu8 "\n", vif->vif_name, port_id);
        return -ENOMEM;
    }

    /* store pointer to KNI for further use */
    vif->vif_os = kni;

    /* add interface to the table of KNIs */
    for (i = 0; i < VR_DPDK_MAX_KNI_INTERFACES; i++) {
        if (vr_dpdk.knis[i] == NULL) {
            vr_dpdk.knis[i] = vif->vif_os;
            break;
        }
    }

    return 0;
}

/*
 * vr_dpdk_knidev_release - release KNI interface and remove it from the
 * global list.
 * Returns 0 on success, < 0 otherwise.
 */
int
vr_dpdk_knidev_release(struct vr_interface *vif)
{
    int i;
    struct rte_kni *kni = vif->vif_os;

    vif->vif_os = NULL;

    /* delete the interface from the table of KNIs */
    for (i = 0; i < VR_DPDK_MAX_KNI_INTERFACES; i++) {
        if (vr_dpdk.knis[i] == kni) {
            vr_dpdk.knis[i] = NULL;
            break;
        }
    }
    rte_wmb();

    return rte_kni_release(kni);
}