X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fvmdq_dcb%2Fmain.c;h=67c6e8820d4379be0e6af65c2055ecb93bccca7c;hb=1c1d4d7a923d4804f1926fc5264f9ecdd8977b04;hp=99d51e025718cf27b37b8efcfcb7f46ef9cd41f9;hpb=041cdbf947fa7eb732e67b1c691c2572c7513461;p=dpdk.git diff --git a/examples/vmdq_dcb/main.c b/examples/vmdq_dcb/main.c index 99d51e0257..67c6e8820d 100644 --- a/examples/vmdq_dcb/main.c +++ b/examples/vmdq_dcb/main.c @@ -1,35 +1,34 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2012 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2013 Intel Corporation. All rights reserved. * All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions * are met: * - * * Redistributions of source code must retain the above copyright + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * */ #include @@ -37,12 +36,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include @@ -74,21 +73,18 @@ #include "main.h" /* basic constants used in application */ -#define SOCKET0 0 -#define SOCKET1 1 - #define NUM_QUEUES 128 #define NUM_MBUFS 64*1024 #define MBUF_CACHE_SIZE 64 #define MBUF_SIZE (2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM) -/* Basic application settings */ -#define NUM_POOLS ETH_16_POOLS /* can be ETH_16_POOLS or ETH_32_POOLS */ - #define RX_PORT 0 #define TX_PORT 1 +/* number of pools (if user does not specify any, 16 by default */ +static enum rte_eth_nb_pools num_pools = ETH_16_POOLS; + /* * RX and TX Prefetch, Host, and Write-back threshold values should be * carefully set for optimal performance. Consult the network @@ -122,7 +118,7 @@ static const struct rte_eth_txconf tx_conf_default = { /* empty vmdq+dcb configuration structure. Filled in programatically */ static const struct rte_eth_conf vmdq_dcb_conf_default = { .rxmode = { - .mq_mode = ETH_VMDQ_DCB, + .mq_mode = ETH_MQ_RX_VMDQ_DCB, .split_hdr_size = 0, .header_split = 0, /**< Header Split disabled */ .hw_ip_checksum = 0, /**< IP checksum offload disabled */ @@ -130,7 +126,7 @@ static const struct rte_eth_conf vmdq_dcb_conf_default = { .jumbo_frame = 0, /**< Jumbo Frame Support disabled */ }, .txmode = { - .mq_mode = ETH_DCB_NONE, + .mq_mode = ETH_MQ_TX_NONE, }, .rx_adv_conf = { /* @@ -138,7 +134,7 @@ static const struct rte_eth_conf vmdq_dcb_conf_default = { * appropriate values */ .vmdq_dcb_conf = { - .nb_queue_pools = NUM_POOLS, + .nb_queue_pools = ETH_16_POOLS, .enable_default_pool = 0, .default_pool = 0, .nb_pool_maps = 0, @@ -170,6 +166,7 @@ get_eth_conf(struct rte_eth_conf *eth_conf, enum rte_eth_nb_pools num_pools) conf.nb_queue_pools = num_pools; conf.enable_default_pool = 0; + conf.default_pool = 0; /* set explicit value, even if not used */ conf.nb_pool_maps = sizeof( vlan_tags )/sizeof( vlan_tags[ 0 ]); for (i = 0; i < conf.nb_pool_maps; i++){ conf.pool_map[i].vlan_id = vlan_tags[ i ]; @@ -178,9 +175,9 @@ get_eth_conf(struct rte_eth_conf *eth_conf, enum rte_eth_nb_pools num_pools) for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++){ conf.dcb_queue[i] = (uint8_t)(i % (NUM_QUEUES/num_pools)); } - rte_memcpy(eth_conf, &vmdq_dcb_conf_default, sizeof(*eth_conf)); - rte_memcpy(ð_conf->rx_adv_conf.vmdq_dcb_conf, &conf, - sizeof(eth_conf->rx_adv_conf.vmdq_dcb_conf)); + (void)(rte_memcpy(eth_conf, &vmdq_dcb_conf_default, sizeof(*eth_conf))); + (void)(rte_memcpy(ð_conf->rx_adv_conf.vmdq_dcb_conf, &conf, + sizeof(eth_conf->rx_adv_conf.vmdq_dcb_conf))); return 0; } @@ -198,7 +195,9 @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool) int retval; uint16_t q; - get_eth_conf(&port_conf, NUM_POOLS); + retval = get_eth_conf(&port_conf, num_pools); + if (retval < 0) + return retval; if (port >= rte_eth_dev_count()) return -1; @@ -208,7 +207,7 @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool) for (q = 0; q < rxRings; q ++) { retval = rte_eth_rx_queue_setup(port, q, rxRingSize, - SOCKET0, &rx_conf_default, + rte_eth_dev_socket_id(port), &rx_conf_default, mbuf_pool); if (retval < 0) return retval; @@ -216,7 +215,7 @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool) for (q = 0; q < txRings; q ++) { retval = rte_eth_tx_queue_setup(port, q, txRingSize, - SOCKET0, &tx_conf_default); + rte_eth_dev_socket_id(port), &tx_conf_default); if (retval < 0) return retval; } @@ -225,9 +224,81 @@ port_init(uint8_t port, struct rte_mempool *mbuf_pool) 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; +} + +/* Check num_pools parameter and set it if OK*/ +static int +vmdq_parse_num_pools(const char *q_arg) +{ + char *end = NULL; + int n; + + /* parse number string */ + n = strtol(q_arg, &end, 10); + if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0')) + return -1; + if (n != 16 && n != 32) + return -1; + if (n == 16) + num_pools = ETH_16_POOLS; + else + num_pools = ETH_32_POOLS; + + return 0; +} + +/* Display usage */ +static void +vmdq_usage(const char *prgname) +{ + printf("%s [EAL options] -- [-nb-pools NP]\n" + " -nb-pools NP: number of pools (16 default, 32)\n", + prgname); +} + +/* Parse the argument (num_pools) given in the command line of the application */ +static int +vmdq_parse_args(int argc, char **argv) +{ + int opt; + int option_index; + const char *prgname = argv[0]; + + static struct option long_option[] = { + {"nb-pools", required_argument, NULL, 0}, + {NULL, 0, 0, 0} + }; + + /* Parse command line */ + while ((opt = getopt_long_only(argc, argv, "",long_option,&option_index)) != EOF) { + switch (opt) { + case 0: + if (vmdq_parse_num_pools(optarg) == -1){ + printf("invalid number of pools\n"); + vmdq_usage(prgname); + return -1; + } + break; + default: + vmdq_usage(prgname); + return -1; + } + } return 0; + + } + #ifndef RTE_EXEC_ENV_BAREMETAL /* When we receive a HUP signal, print out our stats */ static void @@ -235,8 +306,8 @@ sighup_handler(int signum) { unsigned q; for (q = 0; q < NUM_QUEUES; q ++) { - if (q % (NUM_QUEUES/NUM_POOLS) == 0) - printf("\nPool %u: ", q/(NUM_QUEUES/NUM_POOLS)); + if (q % (NUM_QUEUES/num_pools) == 0) + printf("\nPool %u: ", q/(NUM_QUEUES/num_pools)); printf("%lu ", rxPackets[ q ]); } printf("\nFinished handling signal %d\n", signum); @@ -288,15 +359,25 @@ MAIN(int argc, char *argv[]) struct rte_mempool *mbuf_pool; unsigned lcore_id; uintptr_t i; + int ret; #ifndef RTE_EXEC_ENV_BAREMETAL signal(SIGHUP, sighup_handler); #endif - if (rte_eal_init(argc, argv) < 0) + /* init EAL */ + ret = rte_eal_init(argc, argv); + if (ret < 0) rte_exit(EXIT_FAILURE, "Error with EAL initialization\n"); - if (rte_igb_pmd_init() != 0 || - rte_ixgbe_pmd_init() != 0 || + argc -= ret; + argv += ret; + + /* parse app arguments */ + ret = vmdq_parse_args(argc, argv); + if (ret < 0) + rte_exit(EXIT_FAILURE, "Invalid VMDQ argument\n"); + + if (rte_ixgbe_pmd_init() != 0 || rte_eal_pci_probe() != 0) rte_exit(EXIT_FAILURE, "Error with NIC driver initialization\n"); @@ -311,7 +392,7 @@ MAIN(int argc, char *argv[]) sizeof(struct rte_pktmbuf_pool_private), rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL, - SOCKET0, 0); + rte_socket_id(), 0); if (mbuf_pool == NULL) rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");