Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Jul 2016 07:35:01 +0000 (UTC)
From:      Sepherosa Ziehau <sephe@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r302884 - head/sys/dev/hyperv/vmbus
Message-ID:  <201607150735.u6F7Z1Ik024161@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Fri Jul 15 07:35:01 2016
New Revision: 302884
URL: https://svnweb.freebsd.org/changeset/base/302884

Log:
  hyperv/vmbus: Factor out macros to do channel packet length conversion.
  
  MFC after:	1 week
  Sponsored by:	Microsoft OSTC
  Differential Revision:	https://reviews.freebsd.org/D7194

Modified:
  head/sys/dev/hyperv/vmbus/hv_channel.c
  head/sys/dev/hyperv/vmbus/vmbus_reg.h

Modified: head/sys/dev/hyperv/vmbus/hv_channel.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/hv_channel.c	Fri Jul 15 07:26:31 2016	(r302883)
+++ head/sys/dev/hyperv/vmbus/hv_channel.c	Fri Jul 15 07:35:01 2016	(r302884)
@@ -633,12 +633,12 @@ vmbus_chan_send(struct hv_vmbus_channel 
 
 	hlen = sizeof(pkt);
 	pktlen = hlen + dlen;
-	pad_pktlen = roundup2(pktlen, VMBUS_CHANPKT_SIZE_ALIGN);
+	pad_pktlen = VMBUS_CHANPKT_TOTLEN(pktlen);
 
 	pkt.cp_hdr.cph_type = type;
 	pkt.cp_hdr.cph_flags = flags;
-	pkt.cp_hdr.cph_hlen = hlen >> VMBUS_CHANPKT_SIZE_SHIFT;
-	pkt.cp_hdr.cph_tlen = pad_pktlen >> VMBUS_CHANPKT_SIZE_SHIFT;
+	VMBUS_CHANPKT_SETLEN(pkt.cp_hdr.cph_hlen, hlen);
+	VMBUS_CHANPKT_SETLEN(pkt.cp_hdr.cph_tlen, pad_pktlen);
 	pkt.cp_hdr.cph_xactid = xactid;
 
 	iov[0].iov_base = &pkt;
@@ -669,12 +669,12 @@ vmbus_chan_send_sglist(struct hv_vmbus_c
 
 	hlen = __offsetof(struct vmbus_chanpkt_sglist, cp_gpa[sglen]);
 	pktlen = hlen + dlen;
-	pad_pktlen = roundup2(pktlen, VMBUS_CHANPKT_SIZE_ALIGN);
+	pad_pktlen = VMBUS_CHANPKT_TOTLEN(pktlen);
 
 	pkt.cp_hdr.cph_type = VMBUS_CHANPKT_TYPE_GPA;
 	pkt.cp_hdr.cph_flags = VMBUS_CHANPKT_FLAG_RC;
-	pkt.cp_hdr.cph_hlen = hlen >> VMBUS_CHANPKT_SIZE_SHIFT;
-	pkt.cp_hdr.cph_tlen = pad_pktlen >> VMBUS_CHANPKT_SIZE_SHIFT;
+	VMBUS_CHANPKT_SETLEN(pkt.cp_hdr.cph_hlen, hlen);
+	VMBUS_CHANPKT_SETLEN(pkt.cp_hdr.cph_tlen, pad_pktlen);
 	pkt.cp_hdr.cph_xactid = xactid;
 	pkt.cp_rsvd = 0;
 	pkt.cp_gpa_cnt = sglen;
@@ -711,12 +711,12 @@ vmbus_chan_send_prplist(struct hv_vmbus_
 	hlen = __offsetof(struct vmbus_chanpkt_prplist,
 	    cp_range[0].gpa_page[prp_cnt]);
 	pktlen = hlen + dlen;
-	pad_pktlen = roundup2(pktlen, VMBUS_CHANPKT_SIZE_ALIGN);
+	pad_pktlen = VMBUS_CHANPKT_TOTLEN(pktlen);
 
 	pkt.cp_hdr.cph_type = VMBUS_CHANPKT_TYPE_GPA;
 	pkt.cp_hdr.cph_flags = VMBUS_CHANPKT_FLAG_RC;
-	pkt.cp_hdr.cph_hlen = hlen >> VMBUS_CHANPKT_SIZE_SHIFT;
-	pkt.cp_hdr.cph_tlen = pad_pktlen >> VMBUS_CHANPKT_SIZE_SHIFT;
+	VMBUS_CHANPKT_SETLEN(pkt.cp_hdr.cph_hlen, hlen);
+	VMBUS_CHANPKT_SETLEN(pkt.cp_hdr.cph_tlen, pad_pktlen);
 	pkt.cp_hdr.cph_xactid = xactid;
 	pkt.cp_rsvd = 0;
 	pkt.cp_range_cnt = 1;

Modified: head/sys/dev/hyperv/vmbus/vmbus_reg.h
==============================================================================
--- head/sys/dev/hyperv/vmbus/vmbus_reg.h	Fri Jul 15 07:26:31 2016	(r302883)
+++ head/sys/dev/hyperv/vmbus/vmbus_reg.h	Fri Jul 15 07:35:01 2016	(r302884)
@@ -115,6 +115,14 @@ CTASSERT(sizeof(struct vmbus_mnf) == PAG
 #define VMBUS_CHANPKT_SIZE_SHIFT	3
 #define VMBUS_CHANPKT_SIZE_ALIGN	(1 << VMBUS_CHANPKT_SIZE_SHIFT)
 
+#define VMBUS_CHANPKT_SETLEN(pktlen, len)		\
+do {							\
+	(pktlen) = (len) >> VMBUS_CHANPKT_SIZE_SHIFT;	\
+} while (0)
+
+#define VMBUS_CHANPKT_TOTLEN(tlen)	\
+	roundup2((tlen), VMBUS_CHANPKT_SIZE_ALIGN)
+
 struct vmbus_chanpkt_hdr {
 	uint16_t	cph_type;
 	uint16_t	cph_hlen;	/* header len, in 8 bytes */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201607150735.u6F7Z1Ik024161>