Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

irda: vlsi_ir: Replace timeval with ktime_t

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 <zhang.chunyan@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Chunyan Zhang and committed by
David S. Miller
497ec1f2 89a07e17

+14 -34
+13 -33
drivers/net/irda/vlsi_ir.c
··· 33 33 /********************************************************/ 34 34 35 35 #include <linux/kernel.h> 36 + #include <linux/ktime.h> 36 37 #include <linux/init.h> 37 38 #include <linux/interrupt.h> 38 39 #include <linux/pci.h> ··· 41 40 #include <linux/netdevice.h> 42 41 #include <linux/skbuff.h> 43 42 #include <linux/delay.h> 44 - #include <linux/time.h> 45 43 #include <linux/proc_fs.h> 46 44 #include <linux/seq_file.h> 45 + #include <linux/math64.h> 47 46 #include <linux/mutex.h> 48 47 #include <asm/uaccess.h> 49 48 #include <asm/byteorder.h> ··· 181 180 vlsi_irda_dev_t *idev = netdev_priv(ndev); 182 181 u8 byte; 183 182 u16 word; 184 - unsigned delta1, delta2; 185 - struct timeval now; 183 + s32 sec, usec; 186 184 unsigned iobase = ndev->base_addr; 187 185 188 186 seq_printf(seq, "\n%s link state: %s / %s / %s / %s\n", ndev->name, ··· 277 277 seq_printf(seq, "\nsw-state:\n"); 278 278 seq_printf(seq, "IrPHY setup: %d baud - %s encoding\n", idev->baud, 279 279 (idev->mode==IFF_SIR)?"SIR":((idev->mode==IFF_MIR)?"MIR":"FIR")); 280 - do_gettimeofday(&now); 281 - if (now.tv_usec >= idev->last_rx.tv_usec) { 282 - delta2 = now.tv_usec - idev->last_rx.tv_usec; 283 - delta1 = 0; 284 - } 285 - else { 286 - delta2 = 1000000 + now.tv_usec - idev->last_rx.tv_usec; 287 - delta1 = 1; 288 - } 289 - seq_printf(seq, "last rx: %lu.%06u sec\n", 290 - now.tv_sec - idev->last_rx.tv_sec - delta1, delta2); 280 + sec = div_s64_rem(ktime_us_delta(ktime_get(), idev->last_rx), 281 + USEC_PER_SEC, &usec); 282 + seq_printf(seq, "last rx: %ul.%06u sec\n", sec, usec); 291 283 292 284 seq_printf(seq, "RX: packets=%lu / bytes=%lu / errors=%lu / dropped=%lu", 293 285 ndev->stats.rx_packets, ndev->stats.rx_bytes, ndev->stats.rx_errors, ··· 653 661 } 654 662 } 655 663 656 - do_gettimeofday(&idev->last_rx); /* remember "now" for later mtt delay */ 664 + idev->last_rx = ktime_get(); /* remember "now" for later mtt delay */ 657 665 658 666 vlsi_fill_rx(r); 659 667 ··· 850 858 unsigned iobase = ndev->base_addr; 851 859 u8 status; 852 860 u16 config; 853 - int mtt; 861 + int mtt, diff; 854 862 int len, speed; 855 - struct timeval now, ready; 856 863 char *msg = NULL; 857 864 858 865 speed = irda_get_next_speed(skb); ··· 931 940 spin_unlock_irqrestore(&idev->lock, flags); 932 941 933 942 if ((mtt = irda_get_mtt(skb)) > 0) { 934 - 935 - ready.tv_usec = idev->last_rx.tv_usec + mtt; 936 - ready.tv_sec = idev->last_rx.tv_sec; 937 - if (ready.tv_usec >= 1000000) { 938 - ready.tv_usec -= 1000000; 939 - ready.tv_sec++; /* IrLAP 1.1: mtt always < 1 sec */ 940 - } 941 - for(;;) { 942 - do_gettimeofday(&now); 943 - if (now.tv_sec > ready.tv_sec || 944 - (now.tv_sec==ready.tv_sec && now.tv_usec>=ready.tv_usec)) 945 - break; 946 - udelay(100); 943 + diff = ktime_us_delta(ktime_get(), idev->last_rx); 944 + if (mtt > diff) 945 + udelay(mtt - diff); 947 946 /* must not sleep here - called under netif_tx_lock! */ 948 - } 949 947 } 950 948 951 949 /* tx buffer already owned by CPU due to pci_dma_sync_single_for_cpu() ··· 1313 1333 1314 1334 vlsi_fill_rx(idev->rx_ring); 1315 1335 1316 - do_gettimeofday(&idev->last_rx); /* first mtt may start from now on */ 1336 + idev->last_rx = ktime_get(); /* first mtt may start from now on */ 1317 1337 1318 1338 outw(0, iobase+VLSI_PIO_PROMPT); /* kick hw state machine */ 1319 1339 ··· 1500 1520 if (!idev->irlap) 1501 1521 goto errout_free_ring; 1502 1522 1503 - do_gettimeofday(&idev->last_rx); /* first mtt may start from now on */ 1523 + idev->last_rx = ktime_get(); /* first mtt may start from now on */ 1504 1524 1505 1525 idev->new_baud = 9600; /* start with IrPHY using 9600(SIR) mode */ 1506 1526
+1 -1
drivers/net/irda/vlsi_ir.h
··· 723 723 void *virtaddr; 724 724 struct vlsi_ring *tx_ring, *rx_ring; 725 725 726 - struct timeval last_rx; 726 + ktime_t last_rx; 727 727 728 728 spinlock_t lock; 729 729 struct mutex mtx;