svn commit: r353581 - stable/11/sys/dev/ioat

Alexander Motin mav at FreeBSD.org
Tue Oct 15 18:42:07 UTC 2019


Author: mav
Date: Tue Oct 15 18:42:06 2019
New Revision: 353581
URL: https://svnweb.freebsd.org/changeset/base/353581

Log:
  MFC r352787: Replace argument checks with assertions.
  
  Those functions are used by kernel, and we can't check all possible argument
  errors in production kernel.  Plus according to docs many of those errors
  are checked by hardware.  Assertions should just help with code debugging.

Modified:
  stable/11/sys/dev/ioat/ioat.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/ioat/ioat.c
==============================================================================
--- stable/11/sys/dev/ioat/ioat.c	Tue Oct 15 18:39:32 2019	(r353580)
+++ stable/11/sys/dev/ioat/ioat.c	Tue Oct 15 18:42:06 2019	(r353581)
@@ -1002,17 +1002,14 @@ ioat_op_generic(struct ioat_softc *ioat, uint8_t op,
 
 	KASSERT((flags & ~_DMA_GENERIC_FLAGS) == 0,
 	    ("Unrecognized flag(s): %#x", flags & ~_DMA_GENERIC_FLAGS));
+	KASSERT(size <= ioat->max_xfer_size, ("%s: size too big (%u > %u)",
+	    __func__, (unsigned)size, ioat->max_xfer_size));
+
 	if ((flags & DMA_NO_WAIT) != 0)
 		mflags = M_NOWAIT;
 	else
 		mflags = M_WAITOK;
 
-	if (size > ioat->max_xfer_size) {
-		ioat_log_message(0, "%s: max_xfer_size = %d, requested = %u\n",
-		    __func__, ioat->max_xfer_size, (unsigned)size);
-		return (NULL);
-	}
-
 	if (ioat_reserve_space(ioat, 1, mflags) != 0)
 		return (NULL);
 
@@ -1070,11 +1067,8 @@ ioat_copy(bus_dmaengine_t dmaengine, bus_addr_t dst,
 
 	ioat = to_ioat_softc(dmaengine);
 
-	if (((src | dst) & (0xffffull << 48)) != 0) {
-		ioat_log_message(0, "%s: High 16 bits of src/dst invalid\n",
-		    __func__);
-		return (NULL);
-	}
+	KASSERT(((src | dst) & (0xffffull << 48)) == 0,
+	    ("%s: high 16 bits of src/dst are not zero", __func__));
 
 	desc = ioat_op_generic(ioat, IOAT_OP_COPY, len, src, dst, callback_fn,
 	    callback_arg, flags);
@@ -1103,16 +1097,10 @@ ioat_copy_8k_aligned(bus_dmaengine_t dmaengine, bus_ad
 	ioat = to_ioat_softc(dmaengine);
 	CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
 
-	if (((src1 | src2 | dst1 | dst2) & (0xffffull << 48)) != 0) {
-		ioat_log_message(0, "%s: High 16 bits of src/dst invalid\n",
-		    __func__);
-		return (NULL);
-	}
-	if (((src1 | src2 | dst1 | dst2) & PAGE_MASK) != 0) {
-		ioat_log_message(0, "%s: Addresses must be page-aligned\n",
-		    __func__);
-		return (NULL);
-	}
+	KASSERT(((src1 | src2 | dst1 | dst2) & (0xffffull << 48)) == 0,
+	    ("%s: high 16 bits of src/dst are not zero", __func__));
+	KASSERT(((src1 | src2 | dst1 | dst2) & PAGE_MASK) == 0,
+	    ("%s: addresses are not page-aligned", __func__));
 
 	desc = ioat_op_generic(ioat, IOAT_OP_COPY, 2 * PAGE_SIZE, src1, dst1,
 	    callback_fn, callback_arg, flags);
@@ -1150,26 +1138,15 @@ ioat_copy_crc(bus_dmaengine_t dmaengine, bus_addr_t ds
 	ioat = to_ioat_softc(dmaengine);
 	CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
 
-	if ((ioat->capabilities & IOAT_DMACAP_MOVECRC) == 0) {
-		ioat_log_message(0, "%s: Device lacks MOVECRC capability\n",
-		    __func__);
-		return (NULL);
-	}
-	if (((src | dst) & (0xffffffull << 40)) != 0) {
-		ioat_log_message(0, "%s: High 24 bits of src/dst invalid\n",
-		    __func__);
-		return (NULL);
-	}
+	KASSERT((ioat->capabilities & IOAT_DMACAP_MOVECRC) != 0,
+	    ("%s: device lacks MOVECRC capability", __func__));
+	KASSERT(((src | dst) & (0xffffffull << 40)) == 0,
+	    ("%s: high 24 bits of src/dst are not zero", __func__));
 	teststore = (flags & _DMA_CRC_TESTSTORE);
-	if (teststore == _DMA_CRC_TESTSTORE) {
-		ioat_log_message(0, "%s: TEST and STORE invalid\n", __func__);
-		return (NULL);
-	}
-	if (teststore == 0 && (flags & DMA_CRC_INLINE) != 0) {
-		ioat_log_message(0, "%s: INLINE invalid without TEST or STORE\n",
-		    __func__);
-		return (NULL);
-	}
+	KASSERT(teststore != _DMA_CRC_TESTSTORE,
+	    ("%s: TEST and STORE invalid", __func__));
+	KASSERT(teststore != 0 || (flags & DMA_CRC_INLINE) == 0,
+	    ("%s: INLINE invalid without TEST or STORE", __func__));
 
 	switch (teststore) {
 	case DMA_CRC_STORE:
@@ -1184,12 +1161,9 @@ ioat_copy_crc(bus_dmaengine_t dmaengine, bus_addr_t ds
 		break;
 	}
 
-	if ((flags & DMA_CRC_INLINE) == 0 &&
-	    (crcptr & (0xffffffull << 40)) != 0) {
-		ioat_log_message(0,
-		    "%s: High 24 bits of crcptr invalid\n", __func__);
-		return (NULL);
-	}
+	KASSERT((flags & DMA_CRC_INLINE) != 0 ||
+	    (crcptr & (0xffffffull << 40)) == 0,
+	    ("%s: high 24 bits of crcptr are not zero", __func__));
 
 	desc = ioat_op_generic(ioat, op, len, src, dst, callback_fn,
 	    callback_arg, flags & ~_DMA_CRC_FLAGS);
@@ -1229,26 +1203,15 @@ ioat_crc(bus_dmaengine_t dmaengine, bus_addr_t src, bu
 	ioat = to_ioat_softc(dmaengine);
 	CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
 
-	if ((ioat->capabilities & IOAT_DMACAP_CRC) == 0) {
-		ioat_log_message(0, "%s: Device lacks CRC capability\n",
-		    __func__);
-		return (NULL);
-	}
-	if ((src & (0xffffffull << 40)) != 0) {
-		ioat_log_message(0, "%s: High 24 bits of src invalid\n",
-		    __func__);
-		return (NULL);
-	}
+	KASSERT((ioat->capabilities & IOAT_DMACAP_CRC) != 0,
+	    ("%s: device lacks CRC capability", __func__));
+	KASSERT((src & (0xffffffull << 40)) == 0,
+	    ("%s: high 24 bits of src are not zero", __func__));
 	teststore = (flags & _DMA_CRC_TESTSTORE);
-	if (teststore == _DMA_CRC_TESTSTORE) {
-		ioat_log_message(0, "%s: TEST and STORE invalid\n", __func__);
-		return (NULL);
-	}
-	if (teststore == 0 && (flags & DMA_CRC_INLINE) != 0) {
-		ioat_log_message(0, "%s: INLINE invalid without TEST or STORE\n",
-		    __func__);
-		return (NULL);
-	}
+	KASSERT(teststore != _DMA_CRC_TESTSTORE,
+	    ("%s: TEST and STORE invalid", __func__));
+	KASSERT(teststore != 0 || (flags & DMA_CRC_INLINE) == 0,
+	    ("%s: INLINE invalid without TEST or STORE", __func__));
 
 	switch (teststore) {
 	case DMA_CRC_STORE:
@@ -1263,12 +1226,9 @@ ioat_crc(bus_dmaengine_t dmaengine, bus_addr_t src, bu
 		break;
 	}
 
-	if ((flags & DMA_CRC_INLINE) == 0 &&
-	    (crcptr & (0xffffffull << 40)) != 0) {
-		ioat_log_message(0,
-		    "%s: High 24 bits of crcptr invalid\n", __func__);
-		return (NULL);
-	}
+	KASSERT((flags & DMA_CRC_INLINE) != 0 ||
+	    (crcptr & (0xffffffull << 40)) == 0,
+	    ("%s: high 24 bits of crcptr are not zero", __func__));
 
 	desc = ioat_op_generic(ioat, op, len, src, 0, callback_fn,
 	    callback_arg, flags & ~_DMA_CRC_FLAGS);
@@ -1306,18 +1266,11 @@ ioat_blockfill(bus_dmaengine_t dmaengine, bus_addr_t d
 	ioat = to_ioat_softc(dmaengine);
 	CTR2(KTR_IOAT, "%s channel=%u", __func__, ioat->chan_idx);
 
-	if ((ioat->capabilities & IOAT_DMACAP_BFILL) == 0) {
-		ioat_log_message(0, "%s: Device lacks BFILL capability\n",
-		    __func__);
-		return (NULL);
-	}
+	KASSERT((ioat->capabilities & IOAT_DMACAP_BFILL) != 0,
+	    ("%s: device lacks BFILL capability", __func__));
+	KASSERT((dst & (0xffffull << 48)) == 0,
+	    ("%s: high 16 bits of crcptr are not zero", __func__));
 
-	if ((dst & (0xffffull << 48)) != 0) {
-		ioat_log_message(0, "%s: High 16 bits of dst invalid\n",
-		    __func__);
-		return (NULL);
-	}
-
 	desc = ioat_op_generic(ioat, IOAT_OP_FILL, len, fillpattern, dst,
 	    callback_fn, callback_arg, flags);
 	if (desc == NULL)
@@ -1473,7 +1426,7 @@ ioat_poll_timer_callback(void *arg)
 	struct ioat_softc *ioat;
 
 	ioat = arg;
-	ioat_log_message(3, "%s\n", __func__);
+	CTR1(KTR_IOAT, "%s", __func__);
 
 	ioat_process_events(ioat, FALSE);
 


More information about the svn-src-all mailing list