From patchwork Thu Jan 8 04:01:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Zhang X-Patchwork-Id: 42865 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2B33B2055F for ; Thu, 8 Jan 2015 04:03:45 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id gd6sf3870020lab.0 for ; Wed, 07 Jan 2015 20:03:43 -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=tCZovd/u12BdPx4xNL9XknrrHkrh/EL/EoEcndGNJec=; b=KhkrPdzlQDeM2I7a4Y41u+G5ECw459ZqVbJiHIQ/4Yw2TcfOJrb7CNm/HLSWv4bAiT 2pNpO1thC+xR0ISBSXAq7LQ6gg3FmYqppvfApGN5n5r2ZtQQNlqmlyvtbjLrSlsWFz9f XR0H8Xz+9UNJRju604v1g4c8himVxDdD+9ULOgCqRtmjiaaCtXtze3Dqe07V98h+aZsV bezzle757NTaU5N4rvsSHsi/uTXXyPTfPyuuArR7RanF2itdK5oaZIQlhFLBHe6wOvYC 8t/3UZ1iJSdhYCxvJ0Bi7mv1fGIEshzNb6Xa7sUtT/1aNSxpl/CQUFxnjeP4IdeWZiCB RjxQ== X-Gm-Message-State: ALoCoQmW4XxQKfu2L1w5T5fObSL7GCSqbNXBkQTyq8AnE0EpNJRoEuR/u59CSgW7SBE65niUxGIX X-Received: by 10.180.189.116 with SMTP id gh20mr949803wic.2.1420689823932; Wed, 07 Jan 2015 20:03:43 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.131 with SMTP id e3ls267900lam.91.gmail; Wed, 07 Jan 2015 20:03:43 -0800 (PST) X-Received: by 10.112.119.139 with SMTP id ku11mr4888342lbb.76.1420689823668; Wed, 07 Jan 2015 20:03:43 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id uk4si6030571lbb.68.2015.01.07.20.03.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 Jan 2015 20:03:43 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id gd6so7210263lab.3 for ; Wed, 07 Jan 2015 20:03:43 -0800 (PST) X-Received: by 10.152.45.4 with SMTP id i4mr10078614lam.74.1420689823557; Wed, 07 Jan 2015 20:03:43 -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 c8csp145841lbb; Wed, 7 Jan 2015 20:03:42 -0800 (PST) X-Received: by 10.70.61.37 with SMTP id m5mr1414931pdr.34.1420689814009; Wed, 07 Jan 2015 20:03:34 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si6383327pdj.119.2015.01.07.20.03.33; Wed, 07 Jan 2015 20:03:34 -0800 (PST) Received-SPF: none (google.com: netdev-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 S932210AbbAHEDA (ORCPT + 3 others); Wed, 7 Jan 2015 23:03:00 -0500 Received: from mail-pd0-f176.google.com ([209.85.192.176]:48806 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932200AbbAHEC6 (ORCPT ); Wed, 7 Jan 2015 23:02:58 -0500 Received: by mail-pd0-f176.google.com with SMTP id r10so8717190pdi.7 for ; Wed, 07 Jan 2015 20:02:57 -0800 (PST) X-Received: by 10.68.202.98 with SMTP id kh2mr11536499pbc.6.1420689777611; Wed, 07 Jan 2015 20:02:57 -0800 (PST) Received: from chunyanzhangubtpc.spreadtrum.com ([203.160.240.81]) by mx.google.com with ESMTPSA id mw3sm3067779pdb.70.2015.01.07.20.02.54 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jan 2015 20:02:56 -0800 (PST) From: Chunyan Zhang To: samuel@sortiz.org Cc: arnd@arndb.de, zhang.lyra@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] irda: vlsi_ir: Replace timeval with ktime_t Date: Thu, 8 Jan 2015 12:01:32 +0800 Message-Id: <1420689692-8760-7-git-send-email-zhang.chunyan@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1420689692-8760-1-git-send-email-zhang.chunyan@linaro.org> References: <1420689692-8760-1-git-send-email-zhang.chunyan@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: netdev@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.215.44 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: , The vlsi ir driver uses 'timeval', which we try to remove in the kernel because all 32-bit time types will break in the year 2038. 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 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 Reviewed-by: Arnd Bergmann --- drivers/net/irda/vlsi_ir.c | 46 +++++++++++++------------------------------- drivers/net/irda/vlsi_ir.h | 2 +- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c index ac39d9f..a0849f4 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,7 @@ 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; + s32 sec, usec; unsigned iobase = ndev->base_addr; seq_printf(seq, "\n%s link state: %s / %s / %s / %s\n", ndev->name, @@ -277,17 +277,9 @@ 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); + sec = div_s64_rem(ktime_us_delta(ktime_get(), 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 +653,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 +850,8 @@ 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; char *msg = NULL; speed = irda_get_next_speed(skb); @@ -940,21 +931,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); + diff = ktime_us_delta(ktime_get(), idev->last_rx); + if (mtt > diff) + udelay(mtt - diff); /* must not sleep here - called under netif_tx_lock! */ - } } /* tx buffer already owned by CPU due to pci_dma_sync_single_for_cpu() @@ -1333,7 +1313,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 +1500,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;