Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[sfrench/cifs-2.6.git] / include / net / tcp.h
index be6223c586fa05b3ef1dbcb96e73cf7b5dae292d..28b577a35786ddc9b223b54dd387e59910d9c521 100644 (file)
@@ -519,7 +519,7 @@ static inline u32 tcp_cookie_time(void)
 u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
                              u16 *mssp);
 __u32 cookie_v4_init_sequence(const struct sk_buff *skb, __u16 *mss);
-__u32 cookie_init_timestamp(struct request_sock *req);
+u64 cookie_init_timestamp(struct request_sock *req);
 bool cookie_timestamp_decode(struct tcp_options_received *opt);
 bool cookie_ecn_ok(const struct tcp_options_received *opt,
                   const struct net *net, const struct dst_entry *dst);
@@ -574,6 +574,7 @@ void tcp_fin(struct sock *sk);
 void tcp_init_xmit_timers(struct sock *);
 static inline void tcp_clear_xmit_timers(struct sock *sk)
 {
+       hrtimer_cancel(&tcp_sk(sk)->pacing_timer);
        inet_csk_clear_xmit_timers(sk);
 }
 
@@ -699,17 +700,61 @@ u32 __tcp_select_window(struct sock *sk);
 
 void tcp_send_window_probe(struct sock *sk);
 
-/* TCP timestamps are only 32-bits, this causes a slight
- * complication on 64-bit systems since we store a snapshot
- * of jiffies in the buffer control blocks below.  We decided
- * to use only the low 32-bits of jiffies and hide the ugly
- * casts with the following macro.
+/* TCP uses 32bit jiffies to save some space.
+ * Note that this is different from tcp_time_stamp, which
+ * historically has been the same until linux-4.13.
  */
-#define tcp_time_stamp         ((__u32)(jiffies))
+#define tcp_jiffies32 ((u32)jiffies)
+
+/*
+ * Deliver a 32bit value for TCP timestamp option (RFC 7323)
+ * It is no longer tied to jiffies, but to 1 ms clock.
+ * Note: double check if you want to use tcp_jiffies32 instead of this.
+ */
+#define TCP_TS_HZ      1000
+
+static inline u64 tcp_clock_ns(void)
+{
+       return local_clock();
+}
+
+static inline u64 tcp_clock_us(void)
+{
+       return div_u64(tcp_clock_ns(), NSEC_PER_USEC);
+}
+
+/* This should only be used in contexts where tp->tcp_mstamp is up to date */
+static inline u32 tcp_time_stamp(const struct tcp_sock *tp)
+{
+       return div_u64(tp->tcp_mstamp, USEC_PER_SEC / TCP_TS_HZ);
+}
+
+/* Could use tcp_clock_us() / 1000, but this version uses a single divide */
+static inline u32 tcp_time_stamp_raw(void)
+{
+       return div_u64(tcp_clock_ns(), NSEC_PER_SEC / TCP_TS_HZ);
+}
+
+
+/* Refresh 1us clock of a TCP socket,
+ * ensuring monotically increasing values.
+ */
+static inline void tcp_mstamp_refresh(struct tcp_sock *tp)
+{
+       u64 val = tcp_clock_us();
+
+       if (val > tp->tcp_mstamp)
+               tp->tcp_mstamp = val;
+}
+
+static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0)
+{
+       return max_t(s64, t1 - t0, 0);
+}
 
 static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
 {
-       return skb->skb_mstamp.stamp_jiffies;
+       return div_u64(skb->skb_mstamp, USEC_PER_SEC / TCP_TS_HZ);
 }
 
 
@@ -774,9 +819,9 @@ struct tcp_skb_cb {
                        /* pkts S/ACKed so far upon tx of skb, incl retrans: */
                        __u32 delivered;
                        /* start of send pipeline phase */
-                       struct skb_mstamp first_tx_mstamp;
+                       u64 first_tx_mstamp;
                        /* when we reached the "delivered" count */
-                       struct skb_mstamp delivered_mstamp;
+                       u64 delivered_mstamp;
                } tx;   /* only used for outgoing skbs */
                union {
                        struct inet_skb_parm    h4;
@@ -892,7 +937,7 @@ struct ack_sample {
  * A sample is invalid if "delivered" or "interval_us" is negative.
  */
 struct rate_sample {
-       struct  skb_mstamp prior_mstamp; /* starting timestamp for interval */
+       u64  prior_mstamp; /* starting timestamp for interval */
        u32  prior_delivered;   /* tp->delivered at "prior_mstamp" */
        s32  delivered;         /* number of packets delivered over interval */
        long interval_us;       /* time for tp->delivered to incr "delivered" */
@@ -1241,7 +1286,7 @@ static inline void tcp_slow_start_after_idle_check(struct sock *sk)
        if (!sysctl_tcp_slow_start_after_idle || tp->packets_out ||
            ca_ops->cong_control)
                return;
-       delta = tcp_time_stamp - tp->lsndtime;
+       delta = tcp_jiffies32 - tp->lsndtime;
        if (delta > inet_csk(sk)->icsk_rto)
                tcp_cwnd_restart(sk, delta);
 }
@@ -1303,8 +1348,8 @@ static inline u32 keepalive_time_elapsed(const struct tcp_sock *tp)
 {
        const struct inet_connection_sock *icsk = &tp->inet_conn;
 
-       return min_t(u32, tcp_time_stamp - icsk->icsk_ack.lrcvtime,
-                         tcp_time_stamp - tp->rcv_tstamp);
+       return min_t(u32, tcp_jiffies32 - icsk->icsk_ack.lrcvtime,
+                         tcp_jiffies32 - tp->rcv_tstamp);
 }
 
 static inline int tcp_fin_time(const struct sock *sk)
@@ -1858,7 +1903,7 @@ void tcp_init(void);
 /* tcp_recovery.c */
 extern void tcp_rack_mark_lost(struct sock *sk);
 extern void tcp_rack_advance(struct tcp_sock *tp, u8 sacked, u32 end_seq,
-                            const struct skb_mstamp *xmit_time);
+                            u64 xmit_time);
 extern void tcp_rack_reo_timeout(struct sock *sk);
 
 /*
@@ -1945,4 +1990,6 @@ static inline void tcp_listendrop(const struct sock *sk)
        __NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENDROPS);
 }
 
+enum hrtimer_restart tcp_pace_kick(struct hrtimer *timer);
+
 #endif /* _TCP_H */