From patchwork Wed Jan 7 03:39:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Zhang X-Patchwork-Id: 42806 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A0EB92062F for ; Wed, 7 Jan 2015 03:41:39 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf251753wgh.1 for ; Tue, 06 Jan 2015 19:41:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=V0N39e5lmgcmz1AWiY9J6o/i9yVLxl2fNNo17hWu+1U=; b=GNm7TP3KEsKSyZoOFDKl6cZoz2GOz42Ri0L96lGdEHFejX8lkC2ODFURWyQ40Iai1O uAOVG/iRoCpo8XH59LbidmhXSHsAu+s/G3zgZoKruGgp4naQmoAD/736bIp6In/MWEEu 6EIbXtabDGsPRitXzDLMy8hplARTg6cdjcXS3uWw8KbPSHVofg4Xxd+rv9CZmtcNWb7Z xvS2bL/xnrZ2sXr7bY0XecwHu+vzZsLDfxnD/0plBfSkAripQsu0NCJWxOqdgqVX6VHX P0rOy5p5vIeKUFwo7ik9BRGrzZR+Yb/Wx3Qq9ggOcY+TXIvwfVotlqSpkrEJ6eQOFraY 59NA== X-Gm-Message-State: ALoCoQkrPBYUPpu+6aVQvXbDudd3DoQxf6WifftxwaG6lncyo6ZawKyGeat2QFSqXMu4KqtXJ+qr X-Received: by 10.152.2.40 with SMTP id 8mr7354lar.7.1420602098799; Tue, 06 Jan 2015 19:41:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.101 with SMTP id 5ls121007lal.72.gmail; Tue, 06 Jan 2015 19:41:38 -0800 (PST) X-Received: by 10.152.8.225 with SMTP id u1mr812019laa.21.1420602098525; Tue, 06 Jan 2015 19:41:38 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id wm7si488620lbb.72.2015.01.06.19.41.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 Jan 2015 19:41:38 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id 10so411955lbg.5 for ; Tue, 06 Jan 2015 19:41:38 -0800 (PST) X-Received: by 10.152.115.146 with SMTP id jo18mr833310lab.9.1420602098363; Tue, 06 Jan 2015 19:41:38 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp1355705lbb; Tue, 6 Jan 2015 19:41:37 -0800 (PST) X-Received: by 10.68.212.229 with SMTP id nn5mr1449320pbc.52.1420602096511; Tue, 06 Jan 2015 19:41:36 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si712128pdc.58.2015.01.06.19.41.35; Tue, 06 Jan 2015 19:41:36 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757604AbbAGDlc (ORCPT + 27 others); Tue, 6 Jan 2015 22:41:32 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:36854 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757099AbbAGDlI (ORCPT ); Tue, 6 Jan 2015 22:41:08 -0500 Received: by mail-pa0-f44.google.com with SMTP id et14so2031025pad.3 for ; Tue, 06 Jan 2015 19:41:08 -0800 (PST) X-Received: by 10.66.253.34 with SMTP id zx2mr1377229pac.96.1420602068133; Tue, 06 Jan 2015 19:41:08 -0800 (PST) Received: from chunyanzhangubtpc.spreadtrum.com ([203.160.240.81]) by mx.google.com with ESMTPSA id pf10sm261320pbc.82.2015.01.06.19.41.04 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Jan 2015 19:41:07 -0800 (PST) From: Chunyan Zhang To: samuel@sortiz.org Cc: arnd@linaro.org, zhang.lyra@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] driver/net/irda: Replace timeval with ktime_t in vlsi_ir Date: Wed, 7 Jan 2015 11:39:38 +0800 Message-Id: <1420601978-15866-7-git-send-email-zhang.chunyan@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1420601978-15866-1-git-send-email-zhang.chunyan@linaro.org> References: <1420601978-15866-1-git-send-email-zhang.chunyan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: zhang.chunyan@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch changes the 32-bit time type (timeval) to the 64-bit one (ktime_t), since 32-bit time types will break in the year 2038. So, I use ktime_t instead of all uses of timeval. This patch also changes do_gettimeofday() to ktime_get() accordingly, since ktime_get returns a ktime_t, but do_gettimeofday returns a struct timeval, and the other reason is that ktime_get() uses the monotonic clock. This patch uses ktime_us_delta to get the elapsed time of microsecond, and uses div_s64_rem to get what seconds & microseconds time elapsed for printing. This patch also changes the code of function 'vlsi_hard_start_xmit' to do the same things as the others drivers, that is passing the remaining time into udelay() instead of looping until enough time has passed. Signed-off-by: Chunyan Zhang --- drivers/net/irda/vlsi_ir.c | 51 +++++++++++++++----------------------------- drivers/net/irda/vlsi_ir.h | 2 +- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c index ac39d9f..a60a73d 100644 --- a/drivers/net/irda/vlsi_ir.c +++ b/drivers/net/irda/vlsi_ir.c @@ -33,6 +33,7 @@ MODULE_LICENSE("GPL"); /********************************************************/ #include +#include #include #include #include @@ -40,9 +41,9 @@ MODULE_LICENSE("GPL"); #include #include #include -#include #include #include +#include #include #include #include @@ -180,8 +181,8 @@ static void vlsi_proc_ndev(struct seq_file *seq, struct net_device *ndev) vlsi_irda_dev_t *idev = netdev_priv(ndev); u8 byte; u16 word; - unsigned delta1, delta2; - struct timeval now; + ktime_t now; + s32 sec, usec; unsigned iobase = ndev->base_addr; seq_printf(seq, "\n%s link state: %s / %s / %s / %s\n", ndev->name, @@ -277,17 +278,10 @@ static void vlsi_proc_ndev(struct seq_file *seq, struct net_device *ndev) seq_printf(seq, "\nsw-state:\n"); seq_printf(seq, "IrPHY setup: %d baud - %s encoding\n", idev->baud, (idev->mode==IFF_SIR)?"SIR":((idev->mode==IFF_MIR)?"MIR":"FIR")); - do_gettimeofday(&now); - if (now.tv_usec >= idev->last_rx.tv_usec) { - delta2 = now.tv_usec - idev->last_rx.tv_usec; - delta1 = 0; - } - else { - delta2 = 1000000 + now.tv_usec - idev->last_rx.tv_usec; - delta1 = 1; - } - seq_printf(seq, "last rx: %lu.%06u sec\n", - now.tv_sec - idev->last_rx.tv_sec - delta1, delta2); + now = ktime_get(); + sec = div_s64_rem(ktime_us_delta(now, idev->last_rx), + USEC_PER_SEC, &usec); + seq_printf(seq, "last rx: %ul.%06u sec\n", sec, usec); seq_printf(seq, "RX: packets=%lu / bytes=%lu / errors=%lu / dropped=%lu", ndev->stats.rx_packets, ndev->stats.rx_bytes, ndev->stats.rx_errors, @@ -661,7 +655,7 @@ static void vlsi_rx_interrupt(struct net_device *ndev) } } - do_gettimeofday(&idev->last_rx); /* remember "now" for later mtt delay */ + idev->last_rx = ktime_get(); /* remember "now" for later mtt delay */ vlsi_fill_rx(r); @@ -858,9 +852,9 @@ static netdev_tx_t vlsi_hard_start_xmit(struct sk_buff *skb, unsigned iobase = ndev->base_addr; u8 status; u16 config; - int mtt; + int mtt, diff; int len, speed; - struct timeval now, ready; + ktime_t now; char *msg = NULL; speed = irda_get_next_speed(skb); @@ -940,21 +934,10 @@ static netdev_tx_t vlsi_hard_start_xmit(struct sk_buff *skb, spin_unlock_irqrestore(&idev->lock, flags); if ((mtt = irda_get_mtt(skb)) > 0) { - - ready.tv_usec = idev->last_rx.tv_usec + mtt; - ready.tv_sec = idev->last_rx.tv_sec; - if (ready.tv_usec >= 1000000) { - ready.tv_usec -= 1000000; - ready.tv_sec++; /* IrLAP 1.1: mtt always < 1 sec */ - } - for(;;) { - do_gettimeofday(&now); - if (now.tv_sec > ready.tv_sec || - (now.tv_sec==ready.tv_sec && now.tv_usec>=ready.tv_usec)) - break; - udelay(100); - /* must not sleep here - called under netif_tx_lock! */ - } + now = ktime_get(); + diff = ktime_us_delta(now, idev->last_rx); + if (mtt > diff) + udelay(mtt - diff); } /* tx buffer already owned by CPU due to pci_dma_sync_single_for_cpu() @@ -1333,7 +1316,7 @@ static int vlsi_start_hw(vlsi_irda_dev_t *idev) vlsi_fill_rx(idev->rx_ring); - do_gettimeofday(&idev->last_rx); /* first mtt may start from now on */ + idev->last_rx = ktime_get(); /* first mtt may start from now on */ outw(0, iobase+VLSI_PIO_PROMPT); /* kick hw state machine */ @@ -1520,7 +1503,7 @@ static int vlsi_open(struct net_device *ndev) if (!idev->irlap) goto errout_free_ring; - do_gettimeofday(&idev->last_rx); /* first mtt may start from now on */ + idev->last_rx = ktime_get(); /* first mtt may start from now on */ idev->new_baud = 9600; /* start with IrPHY using 9600(SIR) mode */ diff --git a/drivers/net/irda/vlsi_ir.h b/drivers/net/irda/vlsi_ir.h index f9119c6..f9db2ce 100644 --- a/drivers/net/irda/vlsi_ir.h +++ b/drivers/net/irda/vlsi_ir.h @@ -723,7 +723,7 @@ typedef struct vlsi_irda_dev { void *virtaddr; struct vlsi_ring *tx_ring, *rx_ring; - struct timeval last_rx; + ktime_t last_rx; spinlock_t lock; struct mutex mtx;