/* Callback for request of configuring network interface up/down */ static int kni_config_network_interface(uint8_t port_id, uint8_t if_up) { #if 0 int ret = 0; if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) { RTE_LOG(ERR, APP, "Invalid port id %d\n", port_id); return -EINVAL; } RTE_LOG(INFO, APP, "Configure network interface of %d %s\n", port_id, if_up ? "up" : "down"); if (if_up != 0) { /* Configure network interface up */ rte_eth_dev_stop(port_id); ret = rte_eth_dev_start(port_id); } else /* Configure network interface down */ rte_eth_dev_stop(port_id); if (ret < 0) RTE_LOG(ERR, APP, "Failed to start port %d\n", port_id); return ret; #endif return 0; }
/********************************************************************** *@description: * * *@parameters: * [in]: * [in]: * *@return values: * **********************************************************************/ static int odp_start_ports(unsigned short nb_ports, struct odp_user_config *user_conf) { int ret; uint8_t portid; /* start ports */ for (portid = 0; portid < nb_ports; portid++) { if ((user_conf->port_mask & (1 << portid)) == 0) { continue; } /* Start device */ ret = rte_eth_dev_start(portid); if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%d\n", ret, portid); /* * If enabled, put device in promiscuous mode. * This allows IO forwarding mode to forward packets * to itself through 2 cross-connected ports of the * target machine. */ if (user_conf->promiscuous_on) rte_eth_promiscuous_enable(portid); } odp_check_ports_link_status((uint8_t)nb_ports, user_conf->port_mask); return 0; }
/* Callback for request of configuring network interface up/down */ static int kni_config_network_interface(uint8_t port_id, uint8_t if_up) { int ret = 0; RTE_LOG(INFO, KNI, "---- kni_config_network_interface\n"); if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) { RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id); return -EINVAL; } RTE_LOG(INFO, KNI, "Configure network interface of %d %s\n", port_id, if_up ? "up" : "down"); if (if_up != 0) { /* Configure network interface up */ rte_eth_dev_stop(port_id); ret = rte_eth_dev_start(port_id); kni_port_rdy[port_id]++; } else /* Configure network interface down */ rte_eth_dev_stop(port_id); if (ret < 0) RTE_LOG(ERR, KNI, "Failed to start port %d\n", port_id); RTE_LOG(INFO, KNI, "finished kni_config_network_interface\n"); return ret; }
static void app_init_ports(void) { uint32_t i; /* Init driver */ RTE_LOG(INFO, USER1, "Initializing the PMD driver ...\n"); if (rte_eal_pci_probe() < 0) rte_panic("Cannot probe PCI\n"); /* Init NIC ports, then start the ports */ for (i = 0; i < app.n_ports; i++) { uint8_t port; int ret; port = (uint8_t) app.ports[i]; RTE_LOG(INFO, USER1, "Initializing NIC port %u ...\n", port); /* Init port */ ret = rte_eth_dev_configure( port, 1, 1, &port_conf); if (ret < 0) rte_panic("Cannot init NIC port %u (%d)\n", port, ret); rte_eth_promiscuous_enable(port); /* Init RX queues */ ret = rte_eth_rx_queue_setup( port, 0, app.port_rx_ring_size, rte_eth_dev_socket_id(port), &rx_conf, app.pool); if (ret < 0) rte_panic("Cannot init RX for port %u (%d)\n", (uint32_t) port, ret); /* Init TX queues */ ret = rte_eth_tx_queue_setup( port, 0, app.port_tx_ring_size, rte_eth_dev_socket_id(port), &tx_conf); if (ret < 0) rte_panic("Cannot init TX for port %u (%d)\n", (uint32_t) port, ret); /* Start port */ ret = rte_eth_dev_start(port); if (ret < 0) rte_panic("Cannot start port %u (%d)\n", port, ret); } app_ports_check_link(); }
static bool config_port(uint8_t port, bool simple_tx) { int rc = rte_eth_dev_configure(port, 1, 1, &port_conf); if (rc) { printf("Configure %d failed: %d\n", port, rc); return false; } tx_conf.txq_flags = simple_tx ? ETH_TXQ_FLAGS_NOMULTSEGS | ETH_TXQ_FLAGS_NOOFFLOADS : ETH_TXQ_FLAGS_NOMULTSEGS; rc = rte_eth_tx_queue_setup(port, 0, TX_DESCS, rte_socket_id(), &tx_conf); if (rc) { printf("could not configure tx queue on port %d: %d\n", port, rc); return false; } // dev_start segfaults without a rx queue rc = rte_eth_rx_queue_setup(port, 0, RX_DESCS, rte_socket_id(), &rx_conf, make_mempool()); if (rc) { printf("could not configure tx queue on port %d: %d\n", port, rc); return false; } rc = rte_eth_dev_start(port); if (rc) { printf("failed to start port %d: %d\n", port, rc); return false; } return true; }
/** * Initialise an individual port: * - configure number of rx and tx rings * - set up each rx ring, to pull from the main mbuf pool * - set up each tx ring * - start the port and report its status to stdout */ static int init_port(uint8_t port_num) { /* for port configuration all features are off by default */ const struct rte_eth_conf port_conf = { .rxmode = { .mq_mode = ETH_RSS } }; const uint16_t rx_rings = 1, tx_rings = num_clients; const uint16_t rx_ring_size = RTE_MP_RX_DESC_DEFAULT; const uint16_t tx_ring_size = RTE_MP_TX_DESC_DEFAULT; struct rte_eth_link link; uint16_t q; int retval; printf("Port %u init ... ", (unsigned)port_num); fflush(stdout); /* Standard DPDK port initialisation - config port, then set up * rx and tx rings */ if ((retval = rte_eth_dev_configure(port_num, rx_rings, tx_rings, &port_conf)) != 0) return retval; for (q = 0; q < rx_rings; q++) { retval = rte_eth_rx_queue_setup(port_num, q, rx_ring_size, SOCKET0, &rx_conf_default, pktmbuf_pool); if (retval < 0) return retval; } for ( q = 0; q < tx_rings; q ++ ) { retval = rte_eth_tx_queue_setup(port_num, q, tx_ring_size, SOCKET0, &tx_conf_default); if (retval < 0) return retval; } rte_eth_promiscuous_enable(port_num); retval = rte_eth_dev_start(port_num); if (retval < 0) return retval; printf( "done: "); /* get link status */ rte_eth_link_get(port_num, &link); if (link.link_status) { printf(" Link Up - speed %u Mbps - %s\n", (uint32_t) link.link_speed, (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex\n")); } else { printf(" Link Down\n"); } return 0; }
int tcpreplay_netport_init(struct arguments *args) { int ret; uint8_t rss_key [40]; struct rte_eth_link link; struct rte_eth_dev_info dev_info; struct rte_eth_rss_conf rss_conf; struct rte_eth_fdir fdir_conf; /* Retreiving and printing device infos */ rte_eth_dev_info_get(i, &dev_info); printf("Name:%s\n\tDriver name: %s\n\tMax rx queues: %d\n\tMax tx queues: %d\n", dev_info.pci_dev->driver->name,dev_info.driver_name, dev_info.max_rx_queues, dev_info.max_tx_queues); printf("\tPCI Adress: %04d:%02d:%02x:%01d\n", dev_info.pci_dev->addr.domain, dev_info.pci_dev->addr.bus, dev_info.pci_dev->addr.devid, dev_info.pci_dev->addr.function); /* Configure device with '1' rx queues and 1 tx queue */ ret = rte_eth_dev_configure(i, 1, 1, &port_conf); if (ret < 0) rte_panic("Error configuring the port\n"); /* For each RX queue in each NIC */ /* Configure rx queue j of current device on current NUMA socket. It takes elements from the mempool */ ret = rte_eth_rx_queue_setup(i, 0, RX_QUEUE_SZ, rte_socket_id(), &rx_conf, pktmbuf_pool); if (ret < 0) FATAL_ERROR("Error configuring receiving queue\n"); /* Configure mapping [queue] -> [element in stats array] */ ret = rte_eth_dev_set_rx_queue_stats_mapping (i, 0, 0); if (ret < 0) FATAL_ERROR("Error configuring receiving queue stats\n"); /* Configure tx queue of current device on current NUMA socket. Mandatory configuration even if you want only rx packet */ ret = rte_eth_tx_queue_setup(i, 0, TX_QUEUE_SZ, rte_socket_id(), &tx_conf); if (ret < 0) FATAL_ERROR("Error configuring transmitting queue. Errno: %d (%d bad arg, %d no mem)\n", -ret, EINVAL ,ENOMEM); /* Start device */ ret = rte_eth_dev_start(i); if (ret < 0) FATAL_ERROR("Cannot start port\n"); /* Enable receipt in promiscuous mode for an Ethernet device */ rte_eth_promiscuous_enable(i); /* Print link status */ rte_eth_link_get_nowait(i, &link); if (link.link_status) printf("\tPort %d Link Up - speed %u Mbps - %s\n", (uint8_t)i, (unsigned)link.link_speed,(link.link_duplex == ETH_LINK_FULL_DUPLEX) ?("full-duplex") : ("half-duplex\n")); else printf("\tPort %d Link Down\n",(uint8_t)i); /* Print RSS support, not reliable because a NIC could support rss configuration just in rte_eth_dev_configure whithout supporting rte_eth_dev_rss_hash_conf_get*/ rss_conf.rss_key = rss_key; ret = rte_eth_dev_rss_hash_conf_get (i,&rss_conf); if (ret == 0) printf("\tDevice supports RSS\n"); else printf("\tDevice DOES NOT support RSS\n"); /* Print Flow director support */ ret = rte_eth_dev_fdir_get_infos (i, &fdir_conf); if (ret == 0) printf("\tDevice supports Flow Director\n"); else printf("\tDevice DOES NOT support Flow Director\n"); if (args) return 1; return 1; }
static void bond_port_init(struct rte_mempool *mbuf_pool) { int retval; uint8_t i; retval = rte_eth_bond_create("bond0", BONDING_MODE_ALB, 0 /*SOCKET_ID_ANY*/); if (retval < 0) rte_exit(EXIT_FAILURE, "Faled to create bond port\n"); BOND_PORT = (uint8_t)retval; retval = rte_eth_dev_configure(BOND_PORT, 1, 1, &port_conf); if (retval != 0) rte_exit(EXIT_FAILURE, "port %u: configuration failed (res=%d)\n", BOND_PORT, retval); /* RX setup */ retval = rte_eth_rx_queue_setup(BOND_PORT, 0, RTE_RX_DESC_DEFAULT, rte_eth_dev_socket_id(BOND_PORT), NULL, mbuf_pool); if (retval < 0) rte_exit(retval, " port %u: RX queue 0 setup failed (res=%d)", BOND_PORT, retval); /* TX setup */ retval = rte_eth_tx_queue_setup(BOND_PORT, 0, RTE_TX_DESC_DEFAULT, rte_eth_dev_socket_id(BOND_PORT), NULL); if (retval < 0) rte_exit(retval, "port %u: TX queue 0 setup failed (res=%d)", BOND_PORT, retval); for (i = 0; i < slaves_count; i++) { if (rte_eth_bond_slave_add(BOND_PORT, slaves[i]) == -1) rte_exit(-1, "Oooops! adding slave (%u) to bond (%u) failed!\n", slaves[i], BOND_PORT); } retval = rte_eth_dev_start(BOND_PORT); if (retval < 0) rte_exit(retval, "Start port %d failed (res=%d)", BOND_PORT, retval); rte_eth_promiscuous_enable(BOND_PORT); struct ether_addr addr; rte_eth_macaddr_get(BOND_PORT, &addr); printf("Port %u MAC: ", (unsigned)BOND_PORT); PRINT_MAC(addr); printf("\n"); }
int rw_piot_dev_start(rw_piot_api_handle_t api_handle) { rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle); ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev)); if (NULL == rw_piot_dev) { RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n"); return -1; } return(rte_eth_dev_start(rw_piot_dev->rte_port_id)); }
static void app_init_ports(void) { uint32_t i; /* Init NIC ports, then start the ports */ for (i = 0; i < app.n_ports; i++) { uint32_t port; int ret; port = app.ports[i]; RTE_LOG(INFO, USER1, "Initializing NIC port %u ...\n", port); /* Init port */ ret = rte_eth_dev_configure( port, 1, 1, &app.port_conf); if (ret < 0) rte_panic("Cannot init NIC port %u (%d)\n", port, ret); rte_eth_promiscuous_enable(port); /* Init RX queues */ ret = rte_eth_rx_queue_setup( port, 0, app.rsz_hwq_rx, rte_eth_dev_socket_id(port), &app.rx_conf, app.pool); if (ret < 0) rte_panic("Cannot init RX for port %u (%d)\n", (uint32_t) port, ret); /* Init TX queues */ ret = rte_eth_tx_queue_setup( port, 0, app.rsz_hwq_tx, rte_eth_dev_socket_id(port), &app.tx_conf); if (ret < 0) rte_panic("Cannot init TX for port %u (%d)\n", port, ret); /* Start port */ ret = rte_eth_dev_start(port); if (ret < 0) rte_panic("Cannot start port %u (%d)\n", port, ret); } app_ports_check_link(); }
static inline int port_init(uint16_t port, struct rte_mempool *mbuf_pool) { struct rte_eth_conf port_conf = port_conf_default; const uint16_t rx_rings = 1, tx_rings = 1; int retval; uint16_t q; if (port >= rte_eth_dev_count()) return -1; /* Configure the Ethernet device. */ retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf); if (retval != 0) return retval; /* Allocate and set up 1 RX queue per Ethernet port. */ for (q = 0; q < rx_rings; q++) { retval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE, rte_eth_dev_socket_id(port), NULL, mbuf_pool); if (retval < 0) return retval; } /* Allocate and set up 1 TX queue per Ethernet port. */ for (q = 0; q < tx_rings; q++) { retval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE, rte_eth_dev_socket_id(port), NULL); if (retval < 0) return retval; } /* Start the Ethernet port. */ retval = rte_eth_dev_start(port); if (retval < 0) return retval; /* Display the port MAC address. */ struct ether_addr addr; rte_eth_macaddr_get(port, &addr); printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n", (unsigned int)port, addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2], addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5]); /* Enable RX in promiscuous mode for the Ethernet device. */ rte_eth_promiscuous_enable(port); return 0; }
int VIFHYPER_CREATE(const char *devstr, struct virtif_sc *vif_sc, uint8_t *enaddr, struct virtif_user **viup) { struct rte_eth_conf portconf; struct rte_eth_link link; struct ether_addr ea; struct virtif_user *viu; int rv = EINVAL; /* XXX: not very accurate ;) */ viu = malloc(sizeof(*viu)); memset(viu, 0, sizeof(*viu)); viu->viu_devstr = strdup(devstr); viu->viu_virtifsc = vif_sc; /* this is here only for simplicity */ if ((rv = globalinit(viu)) != 0) goto out; memset(&portconf, 0, sizeof(portconf)); if ((rv = rte_eth_dev_configure(IF_PORTID, NQUEUE, NQUEUE, &portconf)) < 0) OUT("configure device"); if ((rv = rte_eth_rx_queue_setup(IF_PORTID, 0, NDESCRX, 0, &rxconf, mbpool_rx)) <0) OUT("rx queue setup"); if ((rv = rte_eth_tx_queue_setup(IF_PORTID, 0, NDESCTX, 0, &txconf)) < 0) OUT("tx queue setup"); if ((rv = rte_eth_dev_start(IF_PORTID)) < 0) OUT("device start"); rte_eth_link_get(IF_PORTID, &link); if (!link.link_status) { ifwarn(viu, "link down"); } rte_eth_promiscuous_enable(IF_PORTID); rte_eth_macaddr_get(IF_PORTID, &ea); memcpy(enaddr, ea.addr_bytes, ETHER_ADDR_LEN); rv = pthread_create(&viu->viu_rcvpt, NULL, receiver, viu); out: /* XXX: well this isn't much of an unrolling ... */ if (rv != 0) free(viu); else *viup = viu; return rumpuser_component_errtrans(-rv); }
/** * Initialise an individual port: * - configure number of rx and tx rings * - set up each rx ring, to pull from the main mbuf pool * - set up each tx ring * - start the port and report its status to stdout */ int init_port(uint8_t port_num) { /* for port configuration all features are off by default */\ const struct rte_eth_conf port_conf = { .rxmode = { .hw_vlan_filter = 0, .hw_vlan_strip = 0, .hw_vlan_extend = 0, .mq_mode = ETH_MQ_RX_RSS } }; const uint16_t rx_rings = 1, tx_rings = 1; const uint16_t rx_ring_size = RTE_MP_RX_DESC_DEFAULT; const uint16_t tx_ring_size = RTE_MP_TX_DESC_DEFAULT; uint16_t q; int retval; printf("Port %u init ... ", (unsigned)port_num); fflush(stdout); /* Standard DPDK port initialisation - config port, then set up * rx and tx rings */ if ((retval = rte_eth_dev_configure(port_num, rx_rings, tx_rings, &port_conf)) != 0) return retval; for (q = 0; q < rx_rings; q++) { retval = rte_eth_rx_queue_setup(port_num, q, rx_ring_size, rte_eth_dev_socket_id(port_num), NULL, pktmbuf_pool); if (retval < 0) return retval; } for ( q = 0; q < tx_rings; q ++ ) { retval = rte_eth_tx_queue_setup(port_num, q, tx_ring_size, rte_eth_dev_socket_id(port_num), NULL); if (retval < 0) return retval; } rte_eth_promiscuous_enable(port_num); retval = rte_eth_dev_start(port_num); if (retval < 0) return retval; printf( "Port %d Init done\n", port_num); return 0; }
/* * Initialises a given port using global settings and with the rx buffers * coming from the mbuf_pool passed as parameter */ static inline int port_init(uint8_t port, struct rte_mempool *mbuf_pool) { struct rte_eth_conf port_conf; const uint16_t rxRings = ETH_VMDQ_DCB_NUM_QUEUES, txRings = (uint16_t)rte_lcore_count(); const uint16_t rxRingSize = 128, txRingSize = 512; int retval; uint16_t q; retval = get_eth_conf(&port_conf, num_pools); if (retval < 0) return retval; if (port >= rte_eth_dev_count()) return -1; retval = rte_eth_dev_configure(port, rxRings, txRings, &port_conf); if (retval != 0) return retval; for (q = 0; q < rxRings; q ++) { retval = rte_eth_rx_queue_setup(port, q, rxRingSize, rte_eth_dev_socket_id(port), NULL, mbuf_pool); if (retval < 0) return retval; } for (q = 0; q < txRings; q ++) { retval = rte_eth_tx_queue_setup(port, q, txRingSize, rte_eth_dev_socket_id(port), NULL); if (retval < 0) return retval; } retval = rte_eth_dev_start(port); if (retval < 0) return retval; struct ether_addr addr; rte_eth_macaddr_get(port, &addr); printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8 " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", (unsigned)port, addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2], addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5]); return 0; }
static void slave_port_init(uint16_t portid, struct rte_mempool *mbuf_pool) { int retval; uint16_t nb_rxd = RTE_RX_DESC_DEFAULT; uint16_t nb_txd = RTE_TX_DESC_DEFAULT; if (portid >= rte_eth_dev_count()) rte_exit(EXIT_FAILURE, "Invalid port\n"); retval = rte_eth_dev_configure(portid, 1, 1, &port_conf); if (retval != 0) rte_exit(EXIT_FAILURE, "port %u: configuration failed (res=%d)\n", portid, retval); retval = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, &nb_txd); if (retval != 0) rte_exit(EXIT_FAILURE, "port %u: rte_eth_dev_adjust_nb_rx_tx_desc " "failed (res=%d)\n", portid, retval); /* RX setup */ retval = rte_eth_rx_queue_setup(portid, 0, nb_rxd, rte_eth_dev_socket_id(portid), NULL, mbuf_pool); if (retval < 0) rte_exit(retval, " port %u: RX queue 0 setup failed (res=%d)", portid, retval); /* TX setup */ retval = rte_eth_tx_queue_setup(portid, 0, nb_txd, rte_eth_dev_socket_id(portid), NULL); if (retval < 0) rte_exit(retval, "port %u: TX queue 0 setup failed (res=%d)", portid, retval); retval = rte_eth_dev_start(portid); if (retval < 0) rte_exit(retval, "Start port %d failed (res=%d)", portid, retval); struct ether_addr addr; rte_eth_macaddr_get(portid, &addr); printf("Port %u MAC: ", portid); PRINT_MAC(addr); printf("\n"); }
int32_t interfaceSetup(void) { uint8_t portIndex = 0, portCount = rte_eth_dev_count(); int32_t ret = 0, socket_id = -1; struct rte_eth_link link; for (portIndex = 0; portIndex < portCount; portIndex++) { /* fetch the socket Id to which the port the mapped */ for (ret = 0; ret < GTP_MAX_NUMANODE; ret++) { if (numaNodeInfo[ret].intfTotal) { if (numaNodeInfo[ret].intfAvail & (1 << portIndex)) { socket_id = ret; break; } } } memset(&link, 0x00, sizeof(struct rte_eth_link)); ret = rte_eth_dev_configure(portIndex, 1, 1, &portConf); if (unlikely(ret < 0)) { rte_panic("ERROR: Dev Configure\n"); return -1; } ret = rte_eth_rx_queue_setup(portIndex, 0, RTE_TEST_RX_DESC_DEFAULT, 0, NULL, numaNodeInfo[socket_id].rx[0]); if (unlikely(ret < 0)) { rte_panic("ERROR: Rx Queue Setup\n"); return -2; } ret = rte_eth_tx_queue_setup(portIndex, 0, RTE_TEST_TX_DESC_DEFAULT, 0, NULL); if (unlikely(ret < 0)) { rte_panic("ERROR: Tx Queue Setup\n"); return -3; } rte_eth_promiscuous_enable(portIndex); rte_eth_dev_start(portIndex); } return 0; }
/** * @brief Start DPDK device * * @param devId uint8_t, ID of DPDK device * * @return 0 if success and DPDK related error code otherwice */ int DPDKAdapter::startDev(uint8_t devId) { if(devId > RTE_MAX_ETHPORTS) { qCritical("Device ID is out of range"); return -1; } int ret = rte_eth_dev_start(devId); if(ret < 0) qCritical("Can not start device: err=%d, dev=%u", ret, (unsigned) devId); return ret; }
static inline int configure_eth_port(uint8_t port_id) { struct ether_addr addr; const uint16_t rxRings = 1, txRings = 1; const uint8_t nb_ports = rte_eth_dev_count(); int ret; uint16_t q; if (port_id > nb_ports) return -1; ret = rte_eth_dev_configure(port_id, rxRings, txRings, &port_conf_default); if (ret != 0) return ret; for (q = 0; q < rxRings; q++) { ret = rte_eth_rx_queue_setup(port_id, q, RX_DESC_PER_QUEUE, rte_eth_dev_socket_id(port_id), NULL, mbuf_pool); if (ret < 0) return ret; } for (q = 0; q < txRings; q++) { ret = rte_eth_tx_queue_setup(port_id, q, TX_DESC_PER_QUEUE, rte_eth_dev_socket_id(port_id), NULL); if (ret < 0) return ret; } ret = rte_eth_dev_start(port_id); if (ret < 0) return ret; rte_eth_macaddr_get(port_id, &addr); printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8 " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", (unsigned)port_id, addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2], addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5]); rte_eth_promiscuous_enable(port_id); return 0; }
/* * Initialises a given port using global settings and with the rx buffers * coming from the mbuf_pool passed as parameter */ static inline int port_init(uint8_t port, struct rte_mempool *mbuf_pool) { struct rte_eth_conf port_conf = port_conf_default; const uint16_t rx_rings = 1, tx_rings = 1; int retval; uint16_t q; if (port >= rte_eth_dev_count()) return -1; retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf); if (retval != 0) return retval; for (q = 0; q < rx_rings; q++) { retval = rte_eth_rx_queue_setup(port, q, RX_RING_SIZE, rte_eth_dev_socket_id(port), NULL, mbuf_pool); if (retval < 0) return retval; } for (q = 0; q < tx_rings; q++) { retval = rte_eth_tx_queue_setup(port, q, TX_RING_SIZE, rte_eth_dev_socket_id(port), NULL); if (retval < 0) return retval; } retval = rte_eth_dev_start(port); if (retval < 0) return retval; struct ether_addr addr; rte_eth_macaddr_get(port, &addr); printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8 " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", (unsigned)port, addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2], addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5]); rte_eth_promiscuous_enable(port); return 0; }
/* Callback for request of changing MTU */ static int kni_change_mtu(uint8_t port_id, unsigned new_mtu) { int ret; uint16_t nb_rx_queue; struct rte_eth_conf conf; if (port_id >= rte_eth_dev_count()) { RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id); return -EINVAL; } RTE_LOG(INFO, KNI, "-----------------Change MTU of port %d to %u\n", port_id, new_mtu); /* Stop specific port */ rte_eth_dev_stop(port_id); memcpy(&conf, &port_conf, sizeof(conf)); /* Set new MTU */ if (new_mtu > ETHER_MAX_LEN) conf.rxmode.jumbo_frame = 1; else conf.rxmode.jumbo_frame = 0; /* mtu + length of header + length of FCS = max pkt length */ conf.rxmode.max_rx_pkt_len = new_mtu + KNI_ENET_HEADER_SIZE + KNI_ENET_FCS_SIZE; nb_rx_queue = get_port_n_rx_queues(port_id); // XXX nb_rx_queue +1 for the kni ret = rte_eth_dev_configure(port_id, nb_rx_queue, nb_rx_queue + 1, &conf); if (ret < 0) { RTE_LOG(ERR, KNI, "Fail to reconfigure port %d\n", port_id); return ret; } /* Restart specific port */ ret = rte_eth_dev_start(port_id); if (ret < 0) { RTE_LOG(ERR, KNI, "Fail to restart port %d\n", port_id); return ret; } return 0; }
static int setup_and_bond_ports(struct rte_mempool *mp) { int portid, queueid; int ret; int pl_idx; int nb_queue; nb_queue = rte_lcore_count(); nb_port = rte_eth_dev_count(); memset(lcore_args, 0, sizeof(struct lcore_arg_t) * RTE_MAX_LCORE); for(portid = 0; portid < nb_port; portid++) { ret = rte_eth_dev_configure(portid, nb_queue, nb_queue, &port_conf); if(unlikely(ret < 0)) { rte_exit(EINVAL, "port %d configure failed!\n", portid); } for(queueid = 0; queueid < nb_queue; queueid++) { ret = rte_eth_rx_queue_setup(portid, queueid, NB_RXD, rte_socket_id(), NULL, mp); if(unlikely(ret < 0)) { rte_exit(EINVAL, "port %d rx queue %d setup failed!\n", portid, queueid); } ret = rte_eth_tx_queue_setup(portid, queueid, NB_TXD, rte_socket_id(), NULL); if(unlikely(ret < 0)) { rte_exit(EINVAL, "port %d tx queue %d setup failed!\n", portid, queueid); } pl_idx = lcore_args[queueid].pl_len; lcore_args[queueid].pl[pl_idx].portid = portid; lcore_args[queueid].pl[pl_idx].queueid = queueid; lcore_args[queueid].mp = mp; lcore_args[queueid].pl_len = pl_idx + 1; } ret = rte_eth_dev_start(portid); if(unlikely(ret < 0)) { rte_exit(EINVAL, "port %d start failed!\n", portid); } rte_eth_promiscuous_enable(portid); } return 0; }
void configure_eth_port(uint8_t port_id) { int ret; rte_eth_dev_stop(port_id); ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf); if (ret < 0) rte_exit(EXIT_FAILURE, "Cannot configure port %u (error %d)\n", (unsigned) port_id, ret); /* Initialize the port's RX queue */ ret = rte_eth_rx_queue_setup(port_id, 0, RX_DESC_PER_QUEUE, rte_eth_dev_socket_id(port_id), NULL, mbuf_pool); if (ret < 0) rte_exit(EXIT_FAILURE, "Failed to setup RX queue on " "port %u (error %d)\n", (unsigned) port_id, ret); /* Initialize the port's TX queue */ ret = rte_eth_tx_queue_setup(port_id, 0, TX_DESC_PER_QUEUE, rte_eth_dev_socket_id(port_id), NULL); if (ret < 0) rte_exit(EXIT_FAILURE, "Failed to setup TX queue on " "port %u (error %d)\n", (unsigned) port_id, ret); /* Initialize the port's flow control */ ret = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf); if (ret < 0) rte_exit(EXIT_FAILURE, "Failed to setup hardware flow control on " "port %u (error %d)\n", (unsigned) port_id, ret); /* Start the port */ ret = rte_eth_dev_start(port_id); if (ret < 0) rte_exit(EXIT_FAILURE, "Failed to start port %u (error %d)\n", (unsigned) port_id, ret); /* Put it in promiscuous mode */ rte_eth_promiscuous_enable(port_id); }
void init_port(int port_id) { struct rte_eth_dev_info dev_info; int ret; struct rte_eth_link link; rte_eth_dev_info_get(port_id, &dev_info); printf("Name:%s\n\tDriver name: %s\n\tMax rx queues: %d\n\tMax tx queues: %d\n", dev_info.pci_dev->driver->name,dev_info.driver_name, dev_info.max_rx_queues, dev_info.max_tx_queues); printf("\tPCI Adress: %04d:%02d:%02x:%01d\n", dev_info.pci_dev->addr.domain, dev_info.pci_dev->addr.bus, dev_info.pci_dev->addr.devid, dev_info.pci_dev->addr.function); ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf); if (ret < 0) rte_panic("Error configuring the port\n"); ret = rte_eth_rx_queue_setup(port_id, 0, RX_QUEUE_SZ, rte_socket_id(), &rx_conf, pktmbuf_pool); if (ret < 0) FATAL_ERROR("Error configuring receiving queue= %d\n", ret); // TODO: Need to check whether it is supported in the VMXNET /*ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, 0, 0); if (ret < 0) FATAL_ERROR("Error configuring receiving queue stats= %d [ENOTSUP= %d]\n", ret, ENOTSUP); */ ret = rte_eth_tx_queue_setup(port_id, 0, TX_QUEUE_SZ, rte_socket_id(), &tx_conf); if (ret < 0) FATAL_ERROR("Error configuring transmitting queue. Errno: %d (%d bad arg, %d no mem)\n", -ret, EINVAL ,ENOMEM); /* Start device */ ret = rte_eth_dev_start(port_id); if (ret < 0) FATAL_ERROR("Cannot start port\n"); /* Enable receipt in promiscuous mode for an Ethernet device */ //rte_eth_promiscuous_enable(port_id); /* Print link status */ rte_eth_link_get_nowait(port_id, &link); if (link.link_status) printf("\tPort %d Link Up - speed %u Mbps - %s\n", (uint8_t)port_id, (unsigned)link.link_speed,(link.link_duplex == ETH_LINK_FULL_DUPLEX) ?("full-duplex") : ("half-duplex\n")); else printf("\tPort %d Link Down\n",(uint8_t)port_id); }
pcap_t* pcap_open_live(const char *source, int snaplen, int promisc, int to_ms, char *errbuf) { pcap_t *p = NULL; int deviceId = 0; debug("Opening device %s\n", source); if (initFinished == 0) { snprintf (errbuf, PCAP_ERRBUF_SIZE, "Global DPDK init is not performed yet"); return NULL; } deviceId = findDevice(source, errbuf); if (deviceId < 0) { snprintf (errbuf, PCAP_ERRBUF_SIZE, "Did not find the device %s", source); return NULL; } if (promisc) rte_eth_promiscuous_enable(deviceId); else rte_eth_promiscuous_disable(deviceId); if (rte_eth_dev_start(deviceId) < 0) { snprintf (errbuf, PCAP_ERRBUF_SIZE, "Could not start the device %d", deviceId); return NULL; } p = malloc (sizeof(pcap_t)); memset(p, 0, sizeof(pcap_t)); p->deviceId = deviceId; return p; }
/* Callback for request of configuring network interface up/down */ int rw_piot_kni_config_network_interface(uint8_t port_id, uint8_t if_up) { int ret = 0, i; rw_piot_device_t *rw_piot_dev = NULL; for (i=0; i<RWPIOT_MAX_DEVICES; i++) { if ((rw_piot_global_config.device[i].used) && (rw_piot_global_config.device[i].rte_port_id == port_id)) { rw_piot_dev = &rw_piot_global_config.device[i]; } } if (NULL == rw_piot_dev) { printf("Could not find port, rw_piot_kni_change_mtu\n"); return -1; } printf("Configure network interface of %d %s\n", port_id, if_up ? "up" : "down"); #if 0 if (if_up != 0) { /* Configure network interface up */ rte_eth_dev_stop(port_id); ret = rte_eth_dev_start(port_id); } else /* Configure network interface down */ rte_eth_dev_stop(port_id); if (ret < 0) printf("Failed to start port %d\n", port_id); if (rw_piot_dev->kni_config_network_if) { rw_piot_dev->kni_config_network_if(rw_piot_dev->piot_api_handle, if_up); } #endif return ret; }
int rumpcomp_virtif_create(int devnum, struct virtif_user **viup) { struct rte_eth_conf portconf; struct rte_eth_link link; int rv = EINVAL; /* XXX: not very accurate ;) */ /* this is here only for simplicity */ if (globalinit() != 0) goto out; memset(&portconf, 0, sizeof(portconf)); if (rte_eth_dev_configure(IF_PORTID, NQUEUE, NQUEUE, &portconf) < 0) OUT("configure device\n"); if (rte_eth_rx_queue_setup(IF_PORTID, 0, NDESC, 0, &rxconf, mbpool) <0) OUT("rx queue setup\n"); if (rte_eth_tx_queue_setup(IF_PORTID, 0, NDESC, 0, &txconf) < 0) OUT("tx queue setup\n"); if (rte_eth_dev_start(IF_PORTID) < 0) OUT("device start\n"); rte_eth_link_get(IF_PORTID, &link); if (!link.link_status) { printf("warning: virt link down\n"); } rte_eth_promiscuous_enable(IF_PORTID); rv = 0; out: *viup = NULL; /* not used by the driver in its current state */ return rv; }
void pktgen_config_ports(void) { uint32_t lid, pid, i, s, q, sid; rxtx_t rt; pkt_seq_t * pkt; port_info_t * info; char buff[RTE_MEMZONE_NAMESIZE]; int32_t ret, cache_size; char output_buff[256] = { 0 }; // Find out the total number of ports in the system. // We have already blacklisted the ones we needed to in main routine. pktgen.nb_ports = rte_eth_dev_count(); if (pktgen.nb_ports > RTE_MAX_ETHPORTS) pktgen.nb_ports = RTE_MAX_ETHPORTS; if ( pktgen.nb_ports == 0 ) pktgen_log_panic("*** Did not find any ports to use ***"); pktgen.starting_port = 0; // Setup the number of ports to display at a time if ( pktgen.nb_ports > pktgen.nb_ports_per_page ) pktgen.ending_port = pktgen.starting_port + pktgen.nb_ports_per_page; else pktgen.ending_port = pktgen.starting_port + pktgen.nb_ports; wr_port_matrix_dump(pktgen.l2p); pktgen_log_info("Configuring %d ports, MBUF Size %d, MBUF Cache Size %d", pktgen.nb_ports, MBUF_SIZE, MBUF_CACHE_SIZE); // For each lcore setup each port that is handled by that lcore. for(lid = 0; lid < RTE_MAX_LCORE; lid++) { if ( wr_get_map(pktgen.l2p, RTE_MAX_ETHPORTS, lid) == 0 ) continue; // For each port attached or handled by the lcore for(pid = 0; pid < pktgen.nb_ports; pid++) { // If non-zero then this port is handled by this lcore. if ( wr_get_map(pktgen.l2p, pid, lid) == 0 ) continue; wr_set_port_private(pktgen.l2p, pid, &pktgen.info[pid]); pktgen.info[pid].pid = pid; } } wr_dump_l2p(pktgen.l2p); pktgen.total_mem_used = 0; for(pid = 0; pid < pktgen.nb_ports; pid++) { // Skip if we do not have any lcores attached to a port. if ( (rt.rxtx = wr_get_map(pktgen.l2p, pid, RTE_MAX_LCORE)) == 0 ) continue; pktgen.port_cnt++; snprintf(output_buff, sizeof(output_buff), "Initialize Port %d -- TxQ %d, RxQ %d", pid, rt.tx, rt.rx); info = wr_get_port_private(pktgen.l2p, pid); // Create the pkt header structures for transmitting sequence of packets. snprintf(buff, sizeof(buff), "seq_hdr_%d", pid); info->seq_pkt = (pkt_seq_t *)rte_zmalloc(buff, (sizeof(pkt_seq_t) * NUM_TOTAL_PKTS), RTE_CACHE_LINE_SIZE); if ( info->seq_pkt == NULL ) pktgen_log_panic("Unable to allocate %d pkt_seq_t headers", NUM_TOTAL_PKTS); info->seqIdx = 0; info->seqCnt = 0; info->nb_mbufs = MAX_MBUFS_PER_PORT; cache_size = (info->nb_mbufs > RTE_MEMPOOL_CACHE_MAX_SIZE)? RTE_MEMPOOL_CACHE_MAX_SIZE : info->nb_mbufs; pktgen_port_conf_setup(pid, &rt, &default_port_conf); if ( (ret = rte_eth_dev_configure(pid, rt.rx, rt.tx, &info->port_conf)) < 0) pktgen_log_panic("Cannot configure device: port=%d, Num queues %d,%d (%d)%s", pid, rt.rx, rt.tx, errno, rte_strerror(-ret)); pkt = &info->seq_pkt[SINGLE_PKT]; // Grab the source MAC addresses */ rte_eth_macaddr_get(pid, &pkt->eth_src_addr); pktgen_log_info("%s, Src MAC %02x:%02x:%02x:%02x:%02x:%02x", output_buff, pkt->eth_src_addr.addr_bytes[0], pkt->eth_src_addr.addr_bytes[1], pkt->eth_src_addr.addr_bytes[2], pkt->eth_src_addr.addr_bytes[3], pkt->eth_src_addr.addr_bytes[4], pkt->eth_src_addr.addr_bytes[5]); // Copy the first Src MAC address in SINGLE_PKT to the rest of the sequence packets. for (i = 0; i < NUM_SEQ_PKTS; i++) ethAddrCopy( &info->seq_pkt[i].eth_src_addr, &pkt->eth_src_addr ); pktgen.mem_used = 0; for(q = 0; q < rt.rx; q++) { // grab the socket id value based on the lcore being used. sid = rte_lcore_to_socket_id(wr_get_port_lid(pktgen.l2p, pid, q)); // Create and initialize the default Receive buffers. info->q[q].rx_mp = pktgen_mbuf_pool_create("Default RX", pid, q, info->nb_mbufs, sid, cache_size); if ( info->q[q].rx_mp == NULL ) pktgen_log_panic("Cannot init port %d for Default RX mbufs", pid); ret = rte_eth_rx_queue_setup(pid, q, pktgen.nb_rxd, sid, &info->rx_conf, pktgen.info[pid].q[q].rx_mp); if (ret < 0) pktgen_log_panic("rte_eth_rx_queue_setup: err=%d, port=%d, %s", ret, pid, rte_strerror(-ret)); } pktgen_log_info(""); for(q = 0; q < rt.tx; q++) { // grab the socket id value based on the lcore being used. sid = rte_lcore_to_socket_id(wr_get_port_lid(pktgen.l2p, pid, q)); // Create and initialize the default Transmit buffers. info->q[q].tx_mp = pktgen_mbuf_pool_create("Default TX", pid, q, MAX_MBUFS_PER_PORT, sid, cache_size); if ( info->q[q].tx_mp == NULL ) pktgen_log_panic("Cannot init port %d for Default TX mbufs", pid); // Create and initialize the range Transmit buffers. info->q[q].range_mp = pktgen_mbuf_pool_create("Range TX", pid, q, MAX_MBUFS_PER_PORT, sid, 0); if ( info->q[q].range_mp == NULL ) pktgen_log_panic("Cannot init port %d for Range TX mbufs", pid); // Create and initialize the sequence Transmit buffers. info->q[q].seq_mp = pktgen_mbuf_pool_create("Sequence TX", pid, q, MAX_MBUFS_PER_PORT, sid, cache_size); if ( info->q[q].seq_mp == NULL ) pktgen_log_panic("Cannot init port %d for Sequence TX mbufs", pid); // Used for sending special packets like ARP requests info->q[q].special_mp = pktgen_mbuf_pool_create("Special TX", pid, q, MAX_SPECIAL_MBUFS, sid, cache_size); if (info->q[q].special_mp == NULL) pktgen_log_panic("Cannot init port %d for Special TX mbufs", pid); // Setup the PCAP file for each port if ( pktgen.info[pid].pcap != NULL ) { if ( pktgen_pcap_parse(pktgen.info[pid].pcap, info, q) == -1 ) pktgen_log_panic("Cannot load PCAP file for port %d", pid); } // Find out the link speed to program the WTHRESH value correctly. pktgen_get_link_status(info, pid, 0); //info->tx_conf.tx_thresh.wthresh = (info->link.link_speed == 1000)? TX_WTHRESH_1GB : TX_WTHRESH; ret = rte_eth_tx_queue_setup(pid, q, pktgen.nb_txd, sid, &info->tx_conf); if (ret < 0) pktgen_log_panic("rte_eth_tx_queue_setup: err=%d, port=%d, %s", ret, pid, rte_strerror(-ret)); #if 0 ret = rte_eth_dev_flow_ctrl_set(pid, &fc_conf); if (ret < 0) pktgen_log_panic("rte_eth_dev_flow_ctrl_set: err=%d, port=%d, %s", ret, pid, rte_strerror(-ret)); #endif pktgen_log_info(""); } pktgen_log_info("%*sPort memory used = %6lu KB", 71, " ", (pktgen.mem_used + 1023)/1024); } pktgen_log_info("%*sTotal memory used = %6lu KB", 70, " ", (pktgen.total_mem_used + 1023)/1024); // Start up the ports and display the port Link status for(pid = 0; pid < pktgen.nb_ports; pid++) { if ( wr_get_map(pktgen.l2p, pid, RTE_MAX_LCORE) == 0 ) continue; info = wr_get_port_private(pktgen.l2p, pid); /* Start device */ if ( (ret = rte_eth_dev_start(pid)) < 0 ) pktgen_log_panic("rte_eth_dev_start: port=%d, %s", pid, rte_strerror(-ret)); pktgen_get_link_status(info, pid, 1); if (info->link.link_status) { snprintf(output_buff, sizeof(output_buff), "Port %2d: Link Up - speed %u Mbps - %s", pid, (uint32_t) info->link.link_speed, (info->link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex")); } else snprintf(output_buff, sizeof(output_buff), "Port %2d: Link Down", pid); // If enabled, put device in promiscuous mode. if (pktgen.flags & PROMISCUOUS_ON_FLAG) { strncatf(output_buff, " <Enable promiscuous mode>"); rte_eth_promiscuous_enable(pid); } pktgen_log_info("%s", output_buff); pktgen.info[pid].seq_pkt[SINGLE_PKT].pktSize = MIN_PKT_SIZE; // Setup the port and packet defaults. (must be after link speed is found) for (s = 0; s < NUM_TOTAL_PKTS; s++) pktgen_port_defaults(pid, s); pktgen_range_setup(info); pktgen_rnd_bits_init(&pktgen.info[pid].rnd_bitfields); } pktgen_log_info(""); for (sid = 0; sid < wr_coremap_cnt(pktgen.core_info, pktgen.core_cnt, 0); sid++) pktgen_packet_capture_init(&pktgen.capture[sid], sid); }
int32_t interfaceSetup(void) { uint8_t portIndex = 0, portCount = rte_eth_dev_count(); int32_t ret = 0, socket_id = -1; struct rte_eth_link link; for (portIndex = 0; portIndex < portCount; portIndex++) { /* fetch the socket Id to which the port the mapped */ for (ret = 0; ret < MAX_NUMANODE; ret++) { if (numaNodeInfo[ret].intfTotal) { if (numaNodeInfo[ret].intfAvail & (1 << portIndex)) { socket_id = ret; break; } } } memset(&link, 0x00, sizeof(struct rte_eth_link)); ret = rte_eth_dev_configure(portIndex, 1, 1, &portConf); if (unlikely(ret < 0)) { rte_panic("ERROR: Dev Configure\n"); return -1; } ret = rte_eth_rx_queue_setup(portIndex, 0, RTE_TEST_RX_DESC_DEFAULT, 0, NULL, numaNodeInfo[socket_id].rx[0]); if (unlikely(ret < 0)) { rte_panic("ERROR: Rx Queue Setup\n"); return -2; } ret = rte_eth_tx_queue_setup(portIndex, 0, RTE_TEST_TX_DESC_DEFAULT, 0, NULL); if (unlikely(ret < 0)) { rte_panic("ERROR: Tx Queue Setup\n"); return -3; } rte_eth_link_get(portIndex, &link); if (unlikely(link.link_duplex != ETH_LINK_FULL_DUPLEX)) { printf(" port:%u; duplex:%s, status:%s", (unsigned) portIndex, (link.link_duplex == ETH_LINK_FULL_DUPLEX)?"Full":"half", (link.link_status == 1)?"up":"down"); /*return -1; Note: there is chance if interface is not connected or speed does not match */ } rte_eth_promiscuous_enable(portIndex); rte_eth_dev_start(portIndex); } return 0; }
static void app_init_nics(void) { unsigned socket; uint32_t lcore; uint16_t port; uint8_t queue; int ret; uint32_t n_rx_queues, n_tx_queues; /* Init NIC ports and queues, then start the ports */ for (port = 0; port < APP_MAX_NIC_PORTS; port ++) { struct rte_mempool *pool; uint16_t nic_rx_ring_size; uint16_t nic_tx_ring_size; struct rte_eth_rxconf rxq_conf; struct rte_eth_txconf txq_conf; struct rte_eth_dev_info dev_info; struct rte_eth_conf local_port_conf = port_conf; n_rx_queues = app_get_nic_rx_queues_per_port(port); n_tx_queues = app.nic_tx_port_mask[port]; if ((n_rx_queues == 0) && (n_tx_queues == 0)) { continue; } /* Init port */ printf("Initializing NIC port %u ...\n", port); rte_eth_dev_info_get(port, &dev_info); if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) local_port_conf.txmode.offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE; local_port_conf.rx_adv_conf.rss_conf.rss_hf &= dev_info.flow_type_rss_offloads; if (local_port_conf.rx_adv_conf.rss_conf.rss_hf != port_conf.rx_adv_conf.rss_conf.rss_hf) { printf("Port %u modified RSS hash function based on hardware support," "requested:%#"PRIx64" configured:%#"PRIx64"\n", port, port_conf.rx_adv_conf.rss_conf.rss_hf, local_port_conf.rx_adv_conf.rss_conf.rss_hf); } ret = rte_eth_dev_configure( port, (uint8_t) n_rx_queues, (uint8_t) n_tx_queues, &local_port_conf); if (ret < 0) { rte_panic("Cannot init NIC port %u (%d)\n", port, ret); } rte_eth_promiscuous_enable(port); nic_rx_ring_size = app.nic_rx_ring_size; nic_tx_ring_size = app.nic_tx_ring_size; ret = rte_eth_dev_adjust_nb_rx_tx_desc( port, &nic_rx_ring_size, &nic_tx_ring_size); if (ret < 0) { rte_panic("Cannot adjust number of descriptors for port %u (%d)\n", port, ret); } app.nic_rx_ring_size = nic_rx_ring_size; app.nic_tx_ring_size = nic_tx_ring_size; rxq_conf = dev_info.default_rxconf; rxq_conf.offloads = local_port_conf.rxmode.offloads; /* Init RX queues */ for (queue = 0; queue < APP_MAX_RX_QUEUES_PER_NIC_PORT; queue ++) { if (app.nic_rx_queue_mask[port][queue] == 0) { continue; } app_get_lcore_for_nic_rx(port, queue, &lcore); socket = rte_lcore_to_socket_id(lcore); pool = app.lcore_params[lcore].pool; printf("Initializing NIC port %u RX queue %u ...\n", port, queue); ret = rte_eth_rx_queue_setup( port, queue, (uint16_t) app.nic_rx_ring_size, socket, &rxq_conf, pool); if (ret < 0) { rte_panic("Cannot init RX queue %u for port %u (%d)\n", queue, port, ret); } } txq_conf = dev_info.default_txconf; txq_conf.offloads = local_port_conf.txmode.offloads; /* Init TX queues */ if (app.nic_tx_port_mask[port] == 1) { app_get_lcore_for_nic_tx(port, &lcore); socket = rte_lcore_to_socket_id(lcore); printf("Initializing NIC port %u TX queue 0 ...\n", port); ret = rte_eth_tx_queue_setup( port, 0, (uint16_t) app.nic_tx_ring_size, socket, &txq_conf); if (ret < 0) { rte_panic("Cannot init TX queue 0 for port %d (%d)\n", port, ret); } } /* Start port */ ret = rte_eth_dev_start(port); if (ret < 0) { rte_panic("Cannot start port %d (%d)\n", port, ret); } } check_all_ports_link_status(APP_MAX_NIC_PORTS, (~0x0)); }
static int netmap_regif(struct nmreq *req, uint32_t idx, uint8_t port) { struct netmap_if *nmif; struct netmap_ring *ring; uint32_t i, slots, start_ring; int32_t rc; if (ports[port].fd < RTE_DIM(fd_port)) { RTE_LOG(ERR, USER1, "port %hhu already in use by fd: %u\n", port, IDX_TO_FD(ports[port].fd)); return (-EBUSY); } if (fd_port[idx].port != FD_PORT_RSRV) { RTE_LOG(ERR, USER1, "fd: %u is misconfigured\n", IDX_TO_FD(idx)); return (-EBUSY); } nmif = ports[port].nmif; /* setup netmap_if fields. */ memset(nmif, 0, netmap.netif_memsz); /* only ALL rings supported right now. */ if (req->nr_ringid != 0) return (-EINVAL); snprintf(nmif->ni_name, sizeof(nmif->ni_name), "%s", req->nr_name); nmif->ni_version = req->nr_version; /* Netmap uses ni_(r|t)x_rings + 1 */ nmif->ni_rx_rings = ports[port].nr_rx_rings - 1; nmif->ni_tx_rings = ports[port].nr_tx_rings - 1; /* * Setup TX rings and slots. * Refer to the comments in netmap.h for details */ slots = 0; for (i = 0; i < nmif->ni_tx_rings + 1; i++) { nmif->ring_ofs[i] = NETMAP_IF_RING_OFS(i, PORT_NUM_RINGS, slots); ring = NETMAP_TXRING(nmif, i); netmap_ring_setup(ring, port, i, ports[port].nr_tx_slots); ring->avail = ring->num_slots; slots += ports[port].nr_tx_slots; } /* * Setup RX rings and slots. * Refer to the comments in netmap.h for details */ start_ring = i; for (; i < nmif->ni_rx_rings + 1 + start_ring; i++) { nmif->ring_ofs[i] = NETMAP_IF_RING_OFS(i, PORT_NUM_RINGS, slots); ring = NETMAP_RXRING(nmif, (i - start_ring)); netmap_ring_setup(ring, port, i, ports[port].nr_rx_slots); ring->avail = 0; slots += ports[port].nr_rx_slots; } if ((rc = rte_eth_dev_start(port)) < 0) { RTE_LOG(ERR, USER1, "Couldn't start ethernet device %s (error %d)\n", req->nr_name, rc); return (rc); } /* setup fdi <--> port relationtip. */ ports[port].fd = idx; fd_port[idx].port = port; req->nr_memsize = netmap.mem_sz; req->nr_offset = (uintptr_t)nmif - (uintptr_t)netmap.mem; return (0); }