From patchwork Fri Apr 1 16:44:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Kiss X-Patchwork-Id: 64893 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp838445lbc; Fri, 1 Apr 2016 09:44:56 -0700 (PDT) X-Received: by 10.50.87.7 with SMTP id t7mr4765934igz.65.1459529096649; Fri, 01 Apr 2016 09:44:56 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p3si30934387iga.53.2016.04.01.09.44.56; Fri, 01 Apr 2016 09:44:56 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B786561B79; Fri, 1 Apr 2016 16:44:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 59B3D61B00; Fri, 1 Apr 2016 16:44:50 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3023B61B17; Fri, 1 Apr 2016 16:44:48 +0000 (UTC) Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) by lists.linaro.org (Postfix) with ESMTPS id F159D61B00 for ; Fri, 1 Apr 2016 16:44:46 +0000 (UTC) Received: by mail-wm0-f44.google.com with SMTP id 20so29963333wmh.1 for ; Fri, 01 Apr 2016 09:44:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/lNocgekeogjzPfp2xmv6zynE0C2+Q6Tyju5IgetFVM=; b=Ejjeey9o78DMgR1ZuiCCSSfyHwzqLu0rA4rugYif7QoJjfEHdbg1xYm3mzVmeyY9S8 qSW2ZrdW99hWoDwtBgyLArVlVJdXOsK5SaGpIoMy6IbPr2lkqrGmbVOsOOwa/1WjlPUo 01MQOz7/twDuntIn/8+XyA3XMR8Hv5di0No9/123d/WUg5AA9U5o2nau4DIp8L3mgdZ9 znkeTVzjgNPGzO7Dt66bUbSBXdk13gBhJFc0x22U+q6vI/ySlupP7a24t4+2lbJWdjhy DNKQWMk1MuqVuLi/87eiaaTXX9td8Eobsa2gNonJe98ZoD0vLhW0wihaVB9E71C2H2QS 90NA== X-Gm-Message-State: AD7BkJLQKmr4dH3/xzAqDLF8jp/Kk4UBTiwZYoTmvWFw27JJeDwXEAAB6W7bxmQgR7SRVkx3Tdo= X-Received: by 10.28.184.148 with SMTP id i142mr5271627wmf.22.1459529086093; Fri, 01 Apr 2016 09:44:46 -0700 (PDT) Received: from localhost.localdomain ([195.11.233.227]) by smtp.googlemail.com with ESMTPSA id i2sm14857951wje.22.2016.04.01.09.44.45 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 01 Apr 2016 09:44:45 -0700 (PDT) From: Zoltan Kiss To: lng-odp@lists.linaro.org Date: Fri, 1 Apr 2016 17:44:04 +0100 Message-Id: <1459529044-25396-1-git-send-email-zoltan.kiss@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Cc: petri.savolainen@nokia.com Subject: [lng-odp] [PATCH] linux-generic: packet_io: fix state handling X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" The current two state doesn't tell odp_pktio_close() whether the device has ever been started, which is important to decide whether it should flush anything or not. The new OPENED state only happen after odp_pktio_open(), after a start -> stop transition it goes to a STOPPED state. Both valid for configuration, so instead of "== STATE_STOPPED", check "!= STATE_STARTED". Signed-off-by: Zoltan Kiss diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 7636768..cca5c39 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -89,8 +89,10 @@ struct pktio_entry { pkt_tap_t pkt_tap; /**< using TAP for IO */ }; enum { - STATE_START = 0, - STATE_STOP + STATE_OPENED = 0, /**< After open() */ + STATE_STARTED, /**< After start() */ + STATE_STOPPED /**< Same as OPENED, but only happens + after STARTED */ } state; classifier_t cls; /**< classifier linked with this pktio*/ odp_pktio_stats_t stats; /**< statistic counters for pktio */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 9192be2..f927c15 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -228,7 +228,7 @@ static odp_pktio_t setup_pktio_entry(const char *name, odp_pool_t pool, } else { snprintf(pktio_entry->s.name, sizeof(pktio_entry->s.name), "%s", name); - pktio_entry->s.state = STATE_STOP; + pktio_entry->s.state = STATE_OPENED; } unlock_entry(pktio_entry); @@ -343,7 +343,8 @@ int odp_pktio_close(odp_pktio_t id) if (entry == NULL) return -1; - flush_in_queues(entry); + if (entry->s.state == STATE_STOPPED) + flush_in_queues(entry); lock_entry(entry); @@ -374,14 +375,14 @@ int odp_pktio_start(odp_pktio_t id) return -1; lock_entry(entry); - if (entry->s.state == STATE_START) { + if (entry->s.state == STATE_STARTED) { unlock_entry(entry); return -1; } if (entry->s.ops->start) res = entry->s.ops->start(entry); if (!res) - entry->s.state = STATE_START; + entry->s.state = STATE_STARTED; unlock_entry(entry); @@ -409,13 +410,13 @@ static int _pktio_stop(pktio_entry_t *entry) { int res = 0; - if (entry->s.state == STATE_STOP) + if (entry->s.state != STATE_STARTED) return -1; if (entry->s.ops->stop) res = entry->s.ops->stop(entry); if (!res) - entry->s.state = STATE_STOP; + entry->s.state = STATE_STOPPED; return res; } @@ -502,7 +503,7 @@ static int _odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], int len) return -1; odp_ticketlock_lock(&pktio_entry->s.txl); - if (pktio_entry->s.state == STATE_STOP || + if (pktio_entry->s.state != STATE_STARTED || pktio_entry->s.param.out_mode == ODP_PKTOUT_MODE_DISABLED) { odp_ticketlock_unlock(&pktio_entry->s.txl); __odp_errno = EPERM; @@ -650,7 +651,7 @@ int pktin_poll(pktio_entry_t *entry, int num_queue, int index[]) if (odp_unlikely(entry->s.num_in_queue == 0)) return -1; - if (entry->s.state == STATE_STOP) + if (entry->s.state != STATE_STARTED) return 0; for (idx = 0; idx < num_queue; idx++) { @@ -725,7 +726,7 @@ int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable) ODP_DBG("already freed pktio\n"); return -1; } - if (entry->s.state != STATE_STOP) { + if (entry->s.state == STATE_STARTED) { unlock_entry(entry); return -1; } @@ -891,8 +892,10 @@ void odp_pktio_print(odp_pktio_t id) " type %s\n", entry->s.ops->name); len += snprintf(&str[len], n - len, " state %s\n", - entry->s.state == STATE_START ? "start" : - (entry->s.state == STATE_STOP ? "stop" : "unknown")); + entry->s.state == STATE_STARTED ? "start" : + (entry->s.state == STATE_STOPPED ? "stop" : + (entry->s.state == STATE_OPENED ? "opened" : + "unknown"))); memset(addr, 0, sizeof(addr)); odp_pktio_mac_addr(id, addr, ETH_ALEN); len += snprintf(&str[len], n - len, @@ -923,7 +926,7 @@ int odp_pktio_term_global(void) continue; lock_entry(pktio_entry); - if (pktio_entry->s.state != STATE_STOP) { + if (pktio_entry->s.state == STATE_STARTED) { ret = _pktio_stop(pktio_entry); if (ret) ODP_ABORT("unable to stop pktio %s\n", @@ -1041,7 +1044,7 @@ int odp_pktin_queue_config(odp_pktio_t pktio, return -1; } - if (entry->s.state != STATE_STOP) { + if (entry->s.state == STATE_STARTED) { ODP_DBG("pktio %s: not stopped\n", entry->s.name); return -1; } @@ -1148,7 +1151,7 @@ int odp_pktout_queue_config(odp_pktio_t pktio, return -1; } - if (entry->s.state != STATE_STOP) { + if (entry->s.state == STATE_STARTED) { ODP_DBG("pktio %s: not stopped\n", entry->s.name); return -1; } diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index 8be8462..d1458bf 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -212,7 +212,7 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, odp_packet_t pkts[], uint32_t pkt_len; pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; - if (pktio_entry->s.state == STATE_STOP) + if (pktio_entry->s.state != STATE_STARTED) return 0; if (!pcap->rx) @@ -295,7 +295,7 @@ static int pcapif_send_pkt(pktio_entry_t *pktio_entry, odp_packet_t pkts[], pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; unsigned i; - ODP_ASSERT(pktio_entry->s.state == STATE_START); + ODP_ASSERT(pktio_entry->s.state == STATE_STARTED); for (i = 0; i < len; ++i) { int pkt_len = odp_packet_len(pkts[i]);