Author: jhb
Date: Fri Nov  4 03:25:34 2016
New Revision: 308281
URL: https://svnweb.freebsd.org/changeset/base/308281

Log:
  MFC 277763,280146,287631: Various fixes to DDP.
  
  277763:
  Lock the socket buffer before jumping to the 'out' label if sblock()
  fails in t4_soreceive_ddp().
  
  280146:
  Move special DDP handling for closing a connection into a new
  handle_ddp_close() function in t4_ddp.c as the logic is similar
  to handle_ddp_data().  This allows all knowledge of the special
  DDP mbufs to be private to t4_ddp.c as well.
  
  287631:
  Add a comment to clarify how to determine the amount of received DDP
  data.
  
  Sponsored by: Chelsio Communications

Modified:
  stable/10/sys/dev/cxgbe/tom/t4_cpl_io.c
  stable/10/sys/dev/cxgbe/tom/t4_ddp.c
  stable/10/sys/dev/cxgbe/tom/t4_tom.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/cxgbe/tom/t4_cpl_io.c
==============================================================================
--- stable/10/sys/dev/cxgbe/tom/t4_cpl_io.c     Fri Nov  4 01:56:29 2016        
(r308280)
+++ stable/10/sys/dev/cxgbe/tom/t4_cpl_io.c     Fri Nov  4 03:25:34 2016        
(r308281)
@@ -1102,19 +1102,7 @@ do_peer_close(struct sge_iq *iq, const s
        sb = &so->so_rcv;
        SOCKBUF_LOCK(sb);
        if (__predict_false(toep->ddp_flags & (DDP_BUF0_ACTIVE | 
DDP_BUF1_ACTIVE))) {
-               m = get_ddp_mbuf(be32toh(cpl->rcv_nxt) - tp->rcv_nxt);
-               tp->rcv_nxt = be32toh(cpl->rcv_nxt);
-               toep->ddp_flags &= ~(DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE);
-
-               KASSERT(toep->sb_cc >= sb->sb_cc,
-                   ("%s: sb %p has more data (%d) than last time (%d).",
-                   __func__, sb, sb->sb_cc, toep->sb_cc));
-               toep->rx_credits += toep->sb_cc - sb->sb_cc;
-#ifdef USE_DDP_RX_FLOW_CONTROL
-               toep->rx_credits -= m->m_len;   /* adjust for F_RX_FC_DDP */
-#endif
-               sbappendstream_locked(sb, m);
-               toep->sb_cc = sb->sb_cc;
+               handle_ddp_close(toep, tp, sb, cpl->rcv_nxt);
        }
        socantrcvmore_locked(so);       /* unlocks the sockbuf */
 

Modified: stable/10/sys/dev/cxgbe/tom/t4_ddp.c
==============================================================================
--- stable/10/sys/dev/cxgbe/tom/t4_ddp.c        Fri Nov  4 01:56:29 2016        
(r308280)
+++ stable/10/sys/dev/cxgbe/tom/t4_ddp.c        Fri Nov  4 03:25:34 2016        
(r308281)
@@ -72,6 +72,8 @@ VNET_DECLARE(int, tcp_autorcvbuf_inc);
 VNET_DECLARE(int, tcp_autorcvbuf_max);
 #define V_tcp_autorcvbuf_max VNET(tcp_autorcvbuf_max)
 
+static struct mbuf *get_ddp_mbuf(int len);
+
 #define PPOD_SZ(n)     ((n) * sizeof(struct pagepod))
 #define PPOD_SIZE      (PPOD_SZ(1))
 
@@ -403,6 +405,19 @@ handle_ddp_data(struct toepcb *toep, __b
        }
 
        tp = intotcpcb(inp);
+
+       /*
+        * For RX_DDP_COMPLETE, len will be zero and rcv_nxt is the
+        * sequence number of the next byte to receive.  The length of
+        * the data received for this message must be computed by
+        * comparing the new and old values of rcv_nxt.
+        * 
+        * For RX_DATA_DDP, len might be non-zero, but it is only the
+        * length of the most recent DMA.  It does not include the
+        * total length of the data received since the previous update
+        * for this DDP buffer.  rcv_nxt is the sequence number of the
+        * first received byte from the most recent DMA.
+        */
        len += be32toh(rcv_nxt) - tp->rcv_nxt;
        tp->rcv_nxt += len;
        tp->t_rcvtime = ticks;
@@ -454,6 +469,37 @@ wakeup:
        return (0);
 }
 
+void
+handle_ddp_close(struct toepcb *toep, struct tcpcb *tp, struct sockbuf *sb,
+    __be32 rcv_nxt)
+{
+       struct mbuf *m;
+       int len;
+
+       SOCKBUF_LOCK_ASSERT(sb);
+       INP_WLOCK_ASSERT(toep->inp);
+       len = be32toh(rcv_nxt) - tp->rcv_nxt;
+
+       /* Signal handle_ddp() to break out of its sleep loop. */
+       toep->ddp_flags &= ~(DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE);
+       if (len == 0)
+               return;
+
+       tp->rcv_nxt += len;
+       KASSERT(toep->sb_cc >= sb->sb_cc,
+           ("%s: sb %p has more data (%d) than last time (%d).",
+           __func__, sb, sb->sb_cc, toep->sb_cc));
+       toep->rx_credits += toep->sb_cc - sb->sb_cc;
+#ifdef USE_DDP_RX_FLOW_CONTROL
+       toep->rx_credits -= len;        /* adjust for F_RX_FC_DDP */
+#endif
+
+       m = get_ddp_mbuf(len);
+
+       sbappendstream_locked(sb, m);
+       toep->sb_cc = sb->sb_cc;
+}
+
 #define DDP_ERR (F_DDP_PPOD_MISMATCH | F_DDP_LLIMIT_ERR | F_DDP_ULIMIT_ERR |\
         F_DDP_PPOD_PARITY_ERR | F_DDP_PADDING_ERR | F_DDP_OFFSET_ERR |\
         F_DDP_INVALID_TAG | F_DDP_COLOR_ERR | F_DDP_TID_MISMATCH |\
@@ -991,7 +1037,7 @@ soreceive_rcvoob(struct socket *so, stru
 
 static char ddp_magic_str[] = "nothing to see here";
 
-struct mbuf *
+static struct mbuf *
 get_ddp_mbuf(int len)
 {
        struct mbuf *m;
@@ -1078,9 +1124,9 @@ t4_soreceive_ddp(struct socket *so, stru
 
        /* Prevent other readers from entering the socket. */
        error = sblock(sb, SBLOCKWAIT(flags));
+       SOCKBUF_LOCK(sb);
        if (error)
                goto out;
-       SOCKBUF_LOCK(sb);
 
        /* Easy one, no space to copyout anything. */
        if (uio->uio_resid == 0) {

Modified: stable/10/sys/dev/cxgbe/tom/t4_tom.h
==============================================================================
--- stable/10/sys/dev/cxgbe/tom/t4_tom.h        Fri Nov  4 01:56:29 2016        
(r308280)
+++ stable/10/sys/dev/cxgbe/tom/t4_tom.h        Fri Nov  4 03:25:34 2016        
(r308281)
@@ -281,9 +281,10 @@ void t4_init_ddp(struct adapter *, struc
 void t4_uninit_ddp(struct adapter *, struct tom_data *);
 int t4_soreceive_ddp(struct socket *, struct sockaddr **, struct uio *,
     struct mbuf **, struct mbuf **, int *);
-struct mbuf *get_ddp_mbuf(int);
 void enable_ddp(struct adapter *, struct toepcb *toep);
 void release_ddp_resources(struct toepcb *toep);
+void handle_ddp_close(struct toepcb *, struct tcpcb *, struct sockbuf *,
+    uint32_t);
 void insert_ddp_data(struct toepcb *, uint32_t);
 
 /* ULP related */
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to