X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Flink_status_interrupt%2Fmain.c;h=9bbcadfcf8b95fec366a737cba7eed099e917fd4;hb=3ee6f706519c0a7456f3d8a79048150dfa6d2581;hp=19b5a99dd80e7a2ba9e6c883e337bbfd90502366;hpb=bacbf5ac505a3063943e83196f7332fc6436a09e;p=dpdk.git diff --git a/examples/link_status_interrupt/main.c b/examples/link_status_interrupt/main.c index 19b5a99dd8..9bbcadfcf8 100644 --- a/examples/link_status_interrupt/main.c +++ b/examples/link_status_interrupt/main.c @@ -47,13 +47,13 @@ /* * Configurable number of RX/TX ring descriptors */ -#define RTE_TEST_RX_DESC_DEFAULT 128 -#define RTE_TEST_TX_DESC_DEFAULT 512 +#define RTE_TEST_RX_DESC_DEFAULT 1024 +#define RTE_TEST_TX_DESC_DEFAULT 1024 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; /* ethernet addresses of ports */ -static struct ether_addr lsi_ports_eth_addr[RTE_MAX_ETHPORTS]; +static struct rte_ether_addr lsi_ports_eth_addr[RTE_MAX_ETHPORTS]; /* mask of enabled ports */ static uint32_t lsi_enabled_port_mask = 0; @@ -76,14 +76,9 @@ struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE]; struct rte_eth_dev_tx_buffer *tx_buffer[RTE_MAX_ETHPORTS]; -static const struct rte_eth_conf port_conf = { +static struct rte_eth_conf port_conf = { .rxmode = { .split_hdr_size = 0, - .header_split = 0, /**< Header Split disabled */ - .hw_ip_checksum = 0, /**< IP checksum offload disabled */ - .hw_vlan_filter = 0, /**< VLAN filtering disabled */ - .jumbo_frame = 0, /**< Jumbo Frame Support disabled */ - .hw_strip_crc = 1, /**< CRC stripped by hardware */ }, .txmode = { .mq_mode = ETH_MQ_TX_NONE, @@ -122,6 +117,7 @@ print_stats(void) const char clr[] = { 27, '[', '2', 'J', '\0' }; const char topLeft[] = { 27, '[', '1', ';', '1', 'H','\0' }; + int link_get_err; /* Clear screen and move to top left */ printf("%s%s", clr, topLeft); @@ -134,7 +130,7 @@ print_stats(void) continue; memset(&link, 0, sizeof(link)); - rte_eth_link_get_nowait(portid, &link); + link_get_err = rte_eth_link_get_nowait(portid, &link); printf("\nStatistics for port %u ------------------------------" "\nLink status: %25s" "\nLink speed: %26u" @@ -143,8 +139,11 @@ print_stats(void) "\nPackets received: %20"PRIu64 "\nPackets dropped: %21"PRIu64, portid, + link_get_err < 0 ? "Link get failed" : (link.link_status ? "Link up" : "Link down"), - (unsigned)link.link_speed, + link_get_err < 0 ? 0 : + (unsigned int)link.link_speed, + link_get_err < 0 ? "Link get failed" : (link.link_duplex == ETH_LINK_FULL_DUPLEX ? \ "full-duplex" : "half-duplex"), port_statistics[portid].tx, @@ -163,25 +162,27 @@ print_stats(void) total_packets_rx, total_packets_dropped); printf("\n====================================================\n"); + + fflush(stdout); } static void lsi_simple_forward(struct rte_mbuf *m, unsigned portid) { - struct ether_hdr *eth; + struct rte_ether_hdr *eth; void *tmp; unsigned dst_port = lsi_dst_ports[portid]; int sent; struct rte_eth_dev_tx_buffer *buffer; - eth = rte_pktmbuf_mtod(m, struct ether_hdr *); + eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); /* 02:00:00:00:00:xx */ tmp = ð->d_addr.addr_bytes[0]; *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dst_port << 40); /* src addr */ - ether_addr_copy(&lsi_ports_eth_addr[dst_port], ð->s_addr); + rte_ether_addr_copy(&lsi_ports_eth_addr[dst_port], ð->s_addr); buffer = tx_buffer[dst_port]; sent = rte_eth_tx_buffer(dst_port, 0, buffer, m); @@ -287,7 +288,7 @@ lsi_main_loop(void) } static int -lsi_launch_one_lcore(__attribute__((unused)) void *dummy) +lsi_launch_one_lcore(__rte_unused void *dummy) { lsi_main_loop(); return 0; @@ -443,13 +444,19 @@ lsi_event_callback(uint16_t port_id, enum rte_eth_event_type type, void *param, void *ret_param) { struct rte_eth_link link; + int ret; RTE_SET_USED(param); RTE_SET_USED(ret_param); printf("\n\nIn registered callback...\n"); printf("Event type: %s\n", type == RTE_ETH_EVENT_INTR_LSC ? "LSC interrupt" : "unknown event"); - rte_eth_link_get_nowait(port_id, &link); + ret = rte_eth_link_get_nowait(port_id, &link); + if (ret < 0) { + printf("Failed link get on port %d: %s\n", + port_id, rte_strerror(-ret)); + return ret; + } if (link.link_status) { printf("Port %d Link Up - speed %u Mbps - %s\n\n", port_id, (unsigned)link.link_speed, @@ -470,6 +477,7 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) uint8_t count, all_ports_up, print_flag = 0; uint16_t portid; struct rte_eth_link link; + int ret; printf("\nChecking link status"); fflush(stdout); @@ -479,7 +487,14 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) if ((port_mask & (1 << portid)) == 0) continue; memset(&link, 0, sizeof(link)); - rte_eth_link_get_nowait(portid, &link); + ret = rte_eth_link_get_nowait(portid, &link); + if (ret < 0) { + all_ports_up = 0; + if (print_flag == 1) + printf("Port %u link get failed: %s\n", + portid, rte_strerror(-ret)); + continue; + } /* print link status if flag set */ if (print_flag == 1) { if (link.link_status) @@ -487,7 +502,7 @@ check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) "Port%d Link Up. Speed %u Mbps - %s\n", portid, link.link_speed, (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? - ("full-duplex") : ("half-duplex\n")); + ("full-duplex") : ("half-duplex")); else printf("Port %d Link Down\n", portid); continue; @@ -545,7 +560,7 @@ main(int argc, char **argv) if (lsi_pktmbuf_pool == NULL) rte_panic("Cannot init mbuf pool\n"); - nb_ports = rte_eth_dev_count(); + nb_ports = rte_eth_dev_count_avail(); if (nb_ports == 0) rte_panic("No Ethernet port - bye\n"); @@ -601,6 +616,11 @@ main(int argc, char **argv) /* Initialise each port */ for (portid = 0; portid < nb_ports; portid++) { + struct rte_eth_rxconf rxq_conf; + struct rte_eth_txconf txq_conf; + struct rte_eth_conf local_port_conf = port_conf; + struct rte_eth_dev_info dev_info; + /* skip ports that are not enabled */ if ((lsi_enabled_port_mask & (1 << portid)) == 0) { printf("Skipping disabled port %u\n", (unsigned) portid); @@ -609,7 +629,17 @@ main(int argc, char **argv) /* init port */ printf("Initializing port %u... ", (unsigned) portid); fflush(stdout); - ret = rte_eth_dev_configure(portid, 1, 1, &port_conf); + + ret = rte_eth_dev_info_get(portid, &dev_info); + if (ret != 0) + rte_exit(EXIT_FAILURE, + "Error during getting device (port %u) info: %s\n", + portid, strerror(-ret)); + + if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) + local_port_conf.txmode.offloads |= + DEV_TX_OFFLOAD_MBUF_FAST_FREE; + ret = rte_eth_dev_configure(portid, 1, 1, &local_port_conf); if (ret < 0) rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n", ret, (unsigned) portid); @@ -629,14 +659,20 @@ main(int argc, char **argv) rte_eth_dev_callback_register(portid, RTE_ETH_EVENT_INTR_LSC, lsi_event_callback, NULL); - rte_eth_macaddr_get(portid, + ret = rte_eth_macaddr_get(portid, &lsi_ports_eth_addr[portid]); + if (ret < 0) + rte_exit(EXIT_FAILURE, + "rte_eth_macaddr_get: err=%d, port=%u\n", + ret, (unsigned int)portid); /* init one RX queue */ fflush(stdout); + rxq_conf = dev_info.default_rxconf; + rxq_conf.offloads = local_port_conf.rxmode.offloads; ret = rte_eth_rx_queue_setup(portid, 0, nb_rxd, rte_eth_dev_socket_id(portid), - NULL, + &rxq_conf, lsi_pktmbuf_pool); if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup: err=%d, port=%u\n", @@ -644,9 +680,11 @@ main(int argc, char **argv) /* init one TX queue logical core on each port */ fflush(stdout); + txq_conf = dev_info.default_txconf; + txq_conf.offloads = local_port_conf.txmode.offloads; ret = rte_eth_tx_queue_setup(portid, 0, nb_txd, rte_eth_dev_socket_id(portid), - NULL); + &txq_conf); if (ret < 0) rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d,port=%u\n", ret, (unsigned) portid); @@ -675,7 +713,11 @@ main(int argc, char **argv) ret, (unsigned) portid); printf("done:\n"); - rte_eth_promiscuous_enable(portid); + ret = rte_eth_promiscuous_enable(portid); + if (ret != 0) + rte_exit(EXIT_FAILURE, + "rte_eth_promiscuous_enable: err=%s, port=%u\n", + rte_strerror(-ret), portid); printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n", (unsigned) portid,