diff options
author | Chunyan Zhang <zhang.chunyan@linaro.org> | 2015-01-07 23:01:32 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-01-11 21:39:40 -0500 |
commit | 497ec1f2a086878d6a42334eda72bfef079dd484 (patch) | |
tree | 12931bcf7d7bbdb8c6fe58a42b23de4d5e925bef | |
parent | 89a07e1726534957fc987b39742048d592ec9aae (diff) |
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>
-rw-r--r-- | drivers/net/irda/vlsi_ir.c | 46 | ||||
-rw-r--r-- | 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 ac39d9f33d5f..a0849f49bbec 100644 --- a/drivers/net/irda/vlsi_ir.c +++ b/drivers/net/irda/vlsi_ir.c | |||
@@ -33,6 +33,7 @@ MODULE_LICENSE("GPL"); | |||
33 | /********************************************************/ | 33 | /********************************************************/ |
34 | 34 | ||
35 | #include <linux/kernel.h> | 35 | #include <linux/kernel.h> |
36 | #include <linux/ktime.h> | ||
36 | #include <linux/init.h> | 37 | #include <linux/init.h> |
37 | #include <linux/interrupt.h> | 38 | #include <linux/interrupt.h> |
38 | #include <linux/pci.h> | 39 | #include <linux/pci.h> |
@@ -40,9 +41,9 @@ MODULE_LICENSE("GPL"); | |||
40 | #include <linux/netdevice.h> | 41 | #include <linux/netdevice.h> |
41 | #include <linux/skbuff.h> | 42 | #include <linux/skbuff.h> |
42 | #include <linux/delay.h> | 43 | #include <linux/delay.h> |
43 | #include <linux/time.h> | ||
44 | #include <linux/proc_fs.h> | 44 | #include <linux/proc_fs.h> |
45 | #include <linux/seq_file.h> | 45 | #include <linux/seq_file.h> |
46 | #include <linux/math64.h> | ||
46 | #include <linux/mutex.h> | 47 | #include <linux/mutex.h> |
47 | #include <asm/uaccess.h> | 48 | #include <asm/uaccess.h> |
48 | #include <asm/byteorder.h> | 49 | #include <asm/byteorder.h> |
@@ -180,8 +181,7 @@ static void vlsi_proc_ndev(struct seq_file *seq, struct net_device *ndev) | |||
180 | vlsi_irda_dev_t *idev = netdev_priv(ndev); | 181 | vlsi_irda_dev_t *idev = netdev_priv(ndev); |
181 | u8 byte; | 182 | u8 byte; |
182 | u16 word; | 183 | u16 word; |
183 | unsigned delta1, delta2; | 184 | s32 sec, usec; |
184 | struct timeval now; | ||
185 | unsigned iobase = ndev->base_addr; | 185 | unsigned iobase = ndev->base_addr; |
186 | 186 | ||
187 | seq_printf(seq, "\n%s link state: %s / %s / %s / %s\n", ndev->name, | 187 | 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) | |||
277 | seq_printf(seq, "\nsw-state:\n"); | 277 | seq_printf(seq, "\nsw-state:\n"); |
278 | seq_printf(seq, "IrPHY setup: %d baud - %s encoding\n", idev->baud, | 278 | seq_printf(seq, "IrPHY setup: %d baud - %s encoding\n", idev->baud, |
279 | (idev->mode==IFF_SIR)?"SIR":((idev->mode==IFF_MIR)?"MIR":"FIR")); | 279 | (idev->mode==IFF_SIR)?"SIR":((idev->mode==IFF_MIR)?"MIR":"FIR")); |
280 | do_gettimeofday(&now); | 280 | sec = div_s64_rem(ktime_us_delta(ktime_get(), idev->last_rx), |
281 | if (now.tv_usec >= idev->last_rx.tv_usec) { | 281 | USEC_PER_SEC, &usec); |
282 | delta2 = now.tv_usec - idev->last_rx.tv_usec; | 282 | seq_printf(seq, "last rx: %ul.%06u sec\n", sec, 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); | ||
291 | 283 | ||
292 | seq_printf(seq, "RX: packets=%lu / bytes=%lu / errors=%lu / dropped=%lu", | 284 | seq_printf(seq, "RX: packets=%lu / bytes=%lu / errors=%lu / dropped=%lu", |
293 | ndev->stats.rx_packets, ndev->stats.rx_bytes, ndev->stats.rx_errors, | 285 | 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) | |||
661 | } | 653 | } |
662 | } | 654 | } |
663 | 655 | ||
664 | do_gettimeofday(&idev->last_rx); /* remember "now" for later mtt delay */ | 656 | idev->last_rx = ktime_get(); /* remember "now" for later mtt delay */ |
665 | 657 | ||
666 | vlsi_fill_rx(r); | 658 | vlsi_fill_rx(r); |
667 | 659 | ||
@@ -858,9 +850,8 @@ static netdev_tx_t vlsi_hard_start_xmit(struct sk_buff *skb, | |||
858 | unsigned iobase = ndev->base_addr; | 850 | unsigned iobase = ndev->base_addr; |
859 | u8 status; | 851 | u8 status; |
860 | u16 config; | 852 | u16 config; |
861 | int mtt; | 853 | int mtt, diff; |
862 | int len, speed; | 854 | int len, speed; |
863 | struct timeval now, ready; | ||
864 | char *msg = NULL; | 855 | char *msg = NULL; |
865 | 856 | ||
866 | speed = irda_get_next_speed(skb); | 857 | speed = irda_get_next_speed(skb); |
@@ -940,21 +931,10 @@ static netdev_tx_t vlsi_hard_start_xmit(struct sk_buff *skb, | |||
940 | spin_unlock_irqrestore(&idev->lock, flags); | 931 | spin_unlock_irqrestore(&idev->lock, flags); |
941 | 932 | ||
942 | if ((mtt = irda_get_mtt(skb)) > 0) { | 933 | if ((mtt = irda_get_mtt(skb)) > 0) { |
943 | 934 | diff = ktime_us_delta(ktime_get(), idev->last_rx); | |
944 | ready.tv_usec = idev->last_rx.tv_usec + mtt; | 935 | if (mtt > diff) |
945 | ready.tv_sec = idev->last_rx.tv_sec; | 936 | udelay(mtt - diff); |
946 | if (ready.tv_usec >= 1000000) { | ||
947 | ready.tv_usec -= 1000000; | ||
948 | ready.tv_sec++; /* IrLAP 1.1: mtt always < 1 sec */ | ||
949 | } | ||
950 | for(;;) { | ||
951 | do_gettimeofday(&now); | ||
952 | if (now.tv_sec > ready.tv_sec || | ||
953 | (now.tv_sec==ready.tv_sec && now.tv_usec>=ready.tv_usec)) | ||
954 | break; | ||
955 | udelay(100); | ||
956 | /* must not sleep here - called under netif_tx_lock! */ | 937 | /* must not sleep here - called under netif_tx_lock! */ |
957 | } | ||
958 | } | 938 | } |
959 | 939 | ||
960 | /* tx buffer already owned by CPU due to pci_dma_sync_single_for_cpu() | 940 | /* 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) | |||
1333 | 1313 | ||
1334 | vlsi_fill_rx(idev->rx_ring); | 1314 | vlsi_fill_rx(idev->rx_ring); |
1335 | 1315 | ||
1336 | do_gettimeofday(&idev->last_rx); /* first mtt may start from now on */ | 1316 | idev->last_rx = ktime_get(); /* first mtt may start from now on */ |
1337 | 1317 | ||
1338 | outw(0, iobase+VLSI_PIO_PROMPT); /* kick hw state machine */ | 1318 | outw(0, iobase+VLSI_PIO_PROMPT); /* kick hw state machine */ |
1339 | 1319 | ||
@@ -1520,7 +1500,7 @@ static int vlsi_open(struct net_device *ndev) | |||
1520 | if (!idev->irlap) | 1500 | if (!idev->irlap) |
1521 | goto errout_free_ring; | 1501 | goto errout_free_ring; |
1522 | 1502 | ||
1523 | do_gettimeofday(&idev->last_rx); /* first mtt may start from now on */ | 1503 | idev->last_rx = ktime_get(); /* first mtt may start from now on */ |
1524 | 1504 | ||
1525 | idev->new_baud = 9600; /* start with IrPHY using 9600(SIR) mode */ | 1505 | idev->new_baud = 9600; /* start with IrPHY using 9600(SIR) mode */ |
1526 | 1506 | ||
diff --git a/drivers/net/irda/vlsi_ir.h b/drivers/net/irda/vlsi_ir.h index f9119c6d2a09..f9db2ce4c5c6 100644 --- a/drivers/net/irda/vlsi_ir.h +++ b/drivers/net/irda/vlsi_ir.h | |||
@@ -723,7 +723,7 @@ typedef struct vlsi_irda_dev { | |||
723 | void *virtaddr; | 723 | void *virtaddr; |
724 | struct vlsi_ring *tx_ring, *rx_ring; | 724 | struct vlsi_ring *tx_ring, *rx_ring; |
725 | 725 | ||
726 | struct timeval last_rx; | 726 | ktime_t last_rx; |
727 | 727 | ||
728 | spinlock_t lock; | 728 | spinlock_t lock; |
729 | struct mutex mtx; | 729 | struct mutex mtx; |