From patchwork Fri May 12 15:10:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 761691 X-Patchwork-Delegate: dlu998@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wPYQC1hwrz9s3w for ; Sat, 13 May 2017 01:13:23 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7CDD3BBF; Fri, 12 May 2017 15:11:15 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id A3EC2B80 for ; Fri, 12 May 2017 15:11:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9A71A1F5 for ; Fri, 12 May 2017 15:11:13 +0000 (UTC) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OPU00KWVI6MIO30@mailout2.w1.samsung.com> for dev@openvswitch.org; Fri, 12 May 2017 16:11:11 +0100 (BST) Received: from eusmges4.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170512151110eucas1p2bf21838ae31c970eed21b03654159cc2~95HuJn5ct2892828928eucas1p23; Fri, 12 May 2017 15:11:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges4.samsung.com (EUCPMTA) with SMTP id DC.45.04729.E80D5195; Fri, 12 May 2017 16:11:10 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170512151109eucas1p11596bf9094816d1a0503b1fca1fef388~95HthM0OT0480804808eucas1p1k; Fri, 12 May 2017 15:11:09 +0000 (GMT) X-AuditID: cbfec7f4-f79806d000001279-00-5915d08e8e08 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 78.8E.20206.DA0D5195; Fri, 12 May 2017 16:11:41 +0100 (BST) Received: from imaximets.rnd.samsung.ru ([106.109.129.180]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OPU00L2WI5RWP70@eusync3.samsung.com>; Fri, 12 May 2017 16:11:09 +0100 (BST) From: Ilya Maximets To: dev@openvswitch.org, Daniele Di Proietto , Darrell Ball Date: Fri, 12 May 2017 18:10:28 +0300 Message-id: <1494601828-30999-4-git-send-email-i.maximets@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1494601828-30999-1-git-send-email-i.maximets@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEIsWRmVeSWpSXmKPExsWy7djPc7p9F0QjDa78FLH49eYBu8WryQ2M Fi39M5ktnr9YyGxx9PQeZou7P1YwWUz7fJvd4kr7T3YHDo/Fe14yeTy7+Z/R4/m1HhaP9/uu snn0bVnF6PFu/lu2ALYoLpuU1JzMstQifbsEroxJT98xF7SFVLTv7WRpYLxu08XIySEhYCLx 79BUZghbTOLCvfVsXYxcHEICSxklZhx9CeV8ZpSYsngrI0zHu60/2EBsIYFljBLX/ylA2M1M Ej0nSkFsNgEdiVOrjwDVc3CICKRKPFosCRJmFtjBKLFioiBIWFjAVmLtP16QMIuAqkRf/wqw G3gF3CROrT3BBrF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GsuDL3EKMEB7OSCG/OCaAQb0piZVVqUX58UWlOavEhRlOgoyYyS4km5wMjL68k 3tDE0NzS0MjYwsLcyEhJnHfqhyvhQgLpiSWp2ampBalFMH1MHJxSDYzafVpzNbq+5Fjrp+Ww ue1ZItpWYXvn4rxlwmdfRm9UnDmrZd9kk0VurYdl1otUOp2+dIyv8oDI1m8qU8uPHOuTfzm9 /Gd2jWjTikOMwv0X3S7EzC4t3jU7303f8HmI/ErTD3vqJx+0duw40uD5+/fTf8kp984IrXnu EbEs7O0kRudt07qTN2xRYinOSDTUYi4qTgQAcEGlCIQCAAA= X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170512151109eucas1p11596bf9094816d1a0503b1fca1fef388 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?SWx5YSBNYXhpbWV0cxtTUlItVmlydHVhbGl6YXRpb24gTGFi?= =?UTF-8?B?G+yCvOyEseyghOyekBtMZWFkaW5nIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?SWx5YSBNYXhpbWV0cxtTUlItVmlydHVhbGl6YXRpb24gTGFi?= =?UTF-8?B?G1NhbXN1bmcgRWxlY3Ryb25pY3MbTGVhZGluZyBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0NJU0hRG0MxMEdEMDFHRDAxMDE1NA==?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170512151109eucas1p11596bf9094816d1a0503b1fca1fef388 X-RootMTR: 20170512151109eucas1p11596bf9094816d1a0503b1fca1fef388 References: <1494601828-30999-1-git-send-email-i.maximets@samsung.com> X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ilya Maximets , Heetae Ahn Subject: [ovs-dev] [PATCH v2 3/3] netdev-dpdk: Use uint8_t for port_id. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Currently, signed integer is used for 'port_id' variable and '-1' as identifier of bad or uninitialized 'port_id'. This inconsistent with dpdk library and, also, in few cases, leads to passing '-1' to dpdk functions where uint8_t expected. Such behaviour doesn't produce any issues, but it's better to use same type as in dpdk library for consistency. Also, magic number '-1' replaced with DPDK_ETH_PORT_ID_INVALID macro. Signed-off-by: Ilya Maximets --- lib/netdev-dpdk.c | 59 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index baac7c3..1ed25b2 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -140,6 +140,8 @@ BUILD_ASSERT_DECL((MAX_NB_MBUF / ROUND_DOWN_POW2(MAX_NB_MBUF/MIN_NB_MBUF)) #define OVS_VHOST_QUEUE_DISABLED (-2) /* Queue was disabled by guest and not * yet mapped to another queue. */ +#define DPDK_ETH_PORT_ID_INVALID RTE_MAX_ETHPORTS + #define VHOST_ENQ_RETRY_NUM 8 #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ) @@ -309,7 +311,7 @@ struct dpdk_ring { struct rte_ring *cring_tx; struct rte_ring *cring_rx; unsigned int user_port_id; /* User given port no, parsed from port name */ - int eth_port_id; /* ethernet device port id */ + uint8_t eth_port_id; /* ethernet device port id */ struct ovs_list list_node OVS_GUARDED_BY(dpdk_mutex); }; @@ -325,7 +327,7 @@ enum dpdk_hw_ol_features { struct netdev_dpdk { struct netdev up; - int port_id; + uint8_t port_id; int max_packet_len; enum dpdk_dev_type type; @@ -402,7 +404,7 @@ struct netdev_dpdk { struct netdev_rxq_dpdk { struct netdev_rxq up; - int port_id; + uint8_t port_id; }; static int netdev_dpdk_class_init(void); @@ -603,12 +605,12 @@ check_link_status(struct netdev_dpdk *dev) dev->link_reset_cnt++; dev->link = link; if (dev->link.link_status) { - VLOG_DBG_RL(&rl, "Port %d Link Up - speed %u Mbps - %s", + VLOG_DBG_RL(&rl, "Port %"PRIu8" Link Up - speed %u Mbps - %s", dev->port_id, (unsigned) dev->link.link_speed, (dev->link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex")); } else { - VLOG_DBG_RL(&rl, "Port %d Link Down", dev->port_id); + VLOG_DBG_RL(&rl, "Port %"PRIu8" Link Down", dev->port_id); } } } @@ -726,8 +728,8 @@ dpdk_eth_checksum_offload_configure(struct netdev_dpdk *dev) if (rx_csum_ol_flag && (info.rx_offload_capa & rx_chksm_offload_capa) != rx_chksm_offload_capa) { - VLOG_WARN_ONCE("Rx checksum offload is not supported on device %d", - dev->port_id); + VLOG_WARN_ONCE("Rx checksum offload is not supported on device %"PRIu8, + dev->port_id); dev->hw_ol_features &= ~NETDEV_RX_CHECKSUM_OFFLOAD; return; } @@ -738,7 +740,8 @@ static void dpdk_eth_flow_ctrl_setup(struct netdev_dpdk *dev) OVS_REQUIRES(dev->mutex) { if (rte_eth_dev_flow_ctrl_set(dev->port_id, &dev->fc_conf)) { - VLOG_WARN("Failed to enable flow control on device %d", dev->port_id); + VLOG_WARN("Failed to enable flow control on device %"PRIu8, + dev->port_id); } } @@ -776,7 +779,7 @@ dpdk_eth_dev_init(struct netdev_dpdk *dev) memset(ð_addr, 0x0, sizeof(eth_addr)); rte_eth_macaddr_get(dev->port_id, ð_addr); - VLOG_INFO_RL(&rl, "Port %d: "ETH_ADDR_FMT, + VLOG_INFO_RL(&rl, "Port %"PRIu8": "ETH_ADDR_FMT, dev->port_id, ETH_ADDR_BYTES_ARGS(eth_addr.addr_bytes)); memcpy(dev->hwaddr.ea, eth_addr.addr_bytes, ETH_ADDR_LEN); @@ -788,7 +791,7 @@ dpdk_eth_dev_init(struct netdev_dpdk *dev) /* Get the Flow control configuration for DPDK-ETH */ diag = rte_eth_dev_flow_ctrl_get(dev->port_id, &dev->fc_conf); if (diag) { - VLOG_DBG("cannot get flow control parameters on port=%d, err=%d", + VLOG_DBG("cannot get flow control parameters on port=%"PRIu8", err=%d", dev->port_id, diag); } @@ -833,7 +836,7 @@ netdev_dpdk_alloc_txq(unsigned int n_txqs) } static int -common_construct(struct netdev *netdev, unsigned int port_no, +common_construct(struct netdev *netdev, uint8_t port_no, enum dpdk_dev_type type, int socket_id) OVS_REQUIRES(dpdk_mutex) { @@ -918,7 +921,8 @@ vhost_common_construct(struct netdev *netdev) return ENOMEM; } - return common_construct(netdev, -1, DPDK_DEV_VHOST, socket_id); + return common_construct(netdev, DPDK_ETH_PORT_ID_INVALID, + DPDK_DEV_VHOST, socket_id); } static int @@ -978,7 +982,8 @@ netdev_dpdk_construct(struct netdev *netdev) int err; ovs_mutex_lock(&dpdk_mutex); - err = common_construct(netdev, -1, DPDK_DEV_ETH, SOCKET0); + err = common_construct(netdev, DPDK_ETH_PORT_ID_INVALID, + DPDK_DEV_ETH, SOCKET0); ovs_mutex_unlock(&dpdk_mutex); return err; } @@ -1112,7 +1117,7 @@ netdev_dpdk_get_config(const struct netdev *netdev, struct smap *args) } static struct netdev_dpdk * -netdev_dpdk_lookup_by_port_id(int port_id) +netdev_dpdk_lookup_by_port_id(uint8_t port_id) OVS_REQUIRES(dpdk_mutex) { struct netdev_dpdk *dev; @@ -1126,13 +1131,13 @@ netdev_dpdk_lookup_by_port_id(int port_id) return NULL; } -static int +static uint8_t netdev_dpdk_process_devargs(struct netdev_dpdk *dev, const char *devargs, char **errp) { /* Get the name up to the first comma. */ char *name = xmemdup0(devargs, strcspn(devargs, ",")); - uint8_t new_port_id = UINT8_MAX; + uint8_t new_port_id = DPDK_ETH_PORT_ID_INVALID; if (!rte_eth_dev_count() || rte_eth_dev_get_port_by_name(name, &new_port_id) @@ -1145,7 +1150,7 @@ netdev_dpdk_process_devargs(struct netdev_dpdk *dev, } else { /* Attach unsuccessful */ VLOG_WARN_BUF(errp, "Error attaching device '%s' to DPDK", devargs); - return -1; + new_port_id = DPDK_ETH_PORT_ID_INVALID; } } @@ -1226,8 +1231,8 @@ netdev_dpdk_set_config(struct netdev *netdev, const struct smap *args, * is valid */ if (!(dev->devargs && !strcmp(dev->devargs, new_devargs) && rte_eth_dev_is_valid_port(dev->port_id))) { - int new_port_id = netdev_dpdk_process_devargs(dev, new_devargs, - errp); + uint8_t new_port_id = netdev_dpdk_process_devargs(dev, new_devargs, + errp); if (!rte_eth_dev_is_valid_port(new_port_id)) { err = EINVAL; } else if (new_port_id == dev->port_id) { @@ -1235,6 +1240,7 @@ netdev_dpdk_set_config(struct netdev *netdev, const struct smap *args, err = 0; } else { struct netdev_dpdk *dup_dev; + dup_dev = netdev_dpdk_lookup_by_port_id(new_port_id); if (dup_dev) { VLOG_WARN_BUF(errp, "'%s' is trying to use device '%s' " @@ -1244,6 +1250,7 @@ netdev_dpdk_set_config(struct netdev *netdev, const struct smap *args, err = EADDRINUSE; } else { int sid = rte_eth_dev_socket_id(new_port_id); + dev->requested_socket_id = sid < 0 ? SOCKET0 : sid; dev->devargs = xstrdup(new_devargs); dev->port_id = new_port_id; @@ -2049,7 +2056,7 @@ netdev_dpdk_get_stats(const struct netdev *netdev, struct netdev_stats *stats) int rte_xstats_len, rte_xstats_new_len, rte_xstats_ret; if (rte_eth_stats_get(dev->port_id, &rte_stats)) { - VLOG_ERR("Can't get ETH statistics for port: %i.", dev->port_id); + VLOG_ERR("Can't get ETH statistics for port: %"PRIu8, dev->port_id); ovs_mutex_unlock(&dev->mutex); return EPROTO; } @@ -2057,7 +2064,7 @@ netdev_dpdk_get_stats(const struct netdev *netdev, struct netdev_stats *stats) /* Get length of statistics */ rte_xstats_len = rte_eth_xstats_get_names(dev->port_id, NULL, 0); if (rte_xstats_len < 0) { - VLOG_WARN("Cannot get XSTATS values for port: %i", dev->port_id); + VLOG_WARN("Cannot get XSTATS values for port: %"PRIu8, dev->port_id); goto out; } /* Reserve memory for xstats names and values */ @@ -2069,7 +2076,7 @@ netdev_dpdk_get_stats(const struct netdev *netdev, struct netdev_stats *stats) rte_xstats_names, rte_xstats_len); if (rte_xstats_new_len != rte_xstats_len) { - VLOG_WARN("Cannot get XSTATS names for port: %i.", dev->port_id); + VLOG_WARN("Cannot get XSTATS names for port: %"PRIu8, dev->port_id); goto out; } /* Retreive xstats values */ @@ -2080,7 +2087,7 @@ netdev_dpdk_get_stats(const struct netdev *netdev, struct netdev_stats *stats) netdev_dpdk_convert_xstats(stats, rte_xstats, rte_xstats_names, rte_xstats_len); } else { - VLOG_WARN("Cannot get XSTATS values for port: %i.", dev->port_id); + VLOG_WARN("Cannot get XSTATS values for port: %"PRIu8, dev->port_id); } out: @@ -2756,7 +2763,7 @@ netdev_dpdk_vhost_class_init(void) static int dpdk_ring_create(const char dev_name[], unsigned int port_no, - unsigned int *eth_port_id) + uint8_t *eth_port_id) { struct dpdk_ring *ring_pair; char *ring_name; @@ -2808,7 +2815,7 @@ dpdk_ring_create(const char dev_name[], unsigned int port_no, } static int -dpdk_ring_open(const char dev_name[], unsigned int *eth_port_id) +dpdk_ring_open(const char dev_name[], uint8_t *eth_port_id) OVS_REQUIRES(dpdk_mutex) { struct dpdk_ring *ring_pair; @@ -2857,7 +2864,7 @@ netdev_dpdk_ring_send(struct netdev *netdev, int qid, static int netdev_dpdk_ring_construct(struct netdev *netdev) { - unsigned int port_no = 0; + uint8_t port_no = 0; int err = 0; ovs_mutex_lock(&dpdk_mutex);