From: Gaetan Rivet Date: Tue, 18 Apr 2017 12:17:40 +0000 (+0200) Subject: app/testpmd: add generic event handler X-Git-Tag: spdx-start~3436 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=76ad4a2d82d4d72c3a7ed4675d77268b5fae3cc9;p=dpdk.git app/testpmd: add generic event handler This is a rather simple handler that prints a message with the name of the current event. It can be used to check PMD callback registration and triggers. Signed-off-by: Gaetan Rivet --- diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 2ab50915cb..28d9b26da0 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -351,6 +351,9 @@ struct rte_stats_bitrates *bitrate_data; /* Forward function declarations */ static void map_port_queue_stats_mapping_registers(uint8_t pi, struct rte_port *port); static void check_all_ports_link_status(uint32_t port_mask); +static void eth_event_callback(uint8_t port_id, + enum rte_eth_event_type type, + void *param); /* * Check if all the ports are started. @@ -1347,6 +1350,7 @@ start_port(portid_t pid) queueid_t qi; struct rte_port *port; struct ether_addr mac_addr; + enum rte_eth_event_type event_type; if (port_id_is_invalid(pid, ENABLED_WARN)) return 0; @@ -1458,6 +1462,21 @@ start_port(portid_t pid) return -1; } } + + for (event_type = RTE_ETH_EVENT_UNKNOWN; + event_type < RTE_ETH_EVENT_MAX; + event_type++) { + diag = rte_eth_dev_callback_register(pi, + event_type, + eth_event_callback, + NULL); + if (diag) { + printf("Failed to setup even callback for event %d\n", + event_type); + return -1; + } + } + /* start port */ if (rte_eth_dev_start(pi) < 0) { printf("Fail to start port %d\n", pi); @@ -1730,6 +1749,34 @@ check_all_ports_link_status(uint32_t port_mask) } } +/* This function is used by the interrupt thread */ +static void +eth_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param) +{ + static const char * const event_desc[] = { + [RTE_ETH_EVENT_UNKNOWN] = "Unknown", + [RTE_ETH_EVENT_INTR_LSC] = "LSC", + [RTE_ETH_EVENT_QUEUE_STATE] = "Queue state", + [RTE_ETH_EVENT_INTR_RESET] = "Interrupt reset", + [RTE_ETH_EVENT_VF_MBOX] = "VF Mbox", + [RTE_ETH_EVENT_MACSEC] = "MACsec", + [RTE_ETH_EVENT_INTR_RMV] = "device removal", + [RTE_ETH_EVENT_MAX] = NULL, + }; + + RTE_SET_USED(param); + + if (type >= RTE_ETH_EVENT_MAX) { + fprintf(stderr, "\nPort %" PRIu8 ": %s called upon invalid event %d\n", + port_id, __func__, type); + fflush(stderr); + } else { + printf("\nPort %" PRIu8 ": %s event\n", port_id, + event_desc[type]); + fflush(stdout); + } +} + static int set_tx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port) {