Author: mav
Date: Fri Sep 27 02:09:20 2019
New Revision: 352787
URL: https://svnweb.freebsd.org/changeset/base/352787

Log:
  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.
  
  MFC after:    2 weeks

Modified:
  head/sys/dev/ioat/ioat.c

Modified: head/sys/dev/ioat/ioat.c
==============================================================================
--- head/sys/dev/ioat/ioat.c    Fri Sep 27 00:29:12 2019        (r352786)
+++ head/sys/dev/ioat/ioat.c    Fri Sep 27 02:09:20 2019        (r352787)
@@ -1136,17 +1136,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);
 
@@ -1226,11 +1223,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);
@@ -1262,16 +1256,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, 0, 0,
            callback_fn, callback_arg, flags);
@@ -1349,26 +1337,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:
@@ -1383,12 +1360,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);
@@ -1439,26 +1413,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:
@@ -1473,12 +1436,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);
@@ -1525,18 +1485,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, 0, dst,
            callback_fn, callback_arg, flags);
        if (desc == NULL)
@@ -1693,7 +1646,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);
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to