net/sfc/base: move Rx descs number check to generic place
authorIgor Romanov <igor.romanov@oktetlabs.ru>
Thu, 7 Feb 2019 16:29:18 +0000 (16:29 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 8 Feb 2019 10:35:41 +0000 (11:35 +0100)
Now we have min/max limits in NIC config, so we can do check against
min/max in a generic place instead of NIC family specific functions.
Check that the descriptors number is a power of 2 is also can be
made common. It removes code duplication and makes NIC family
specific functions a bit shorter.

Signed-off-by: Igor Romanov <igor.romanov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
drivers/net/sfc/base/ef10_rx.c
drivers/net/sfc/base/efx_rx.c

index 1f2a6e0..f2b7257 100644 (file)
@@ -1012,18 +1012,9 @@ ef10_rx_qcreate(
        EFSYS_ASSERT3U(label, <, EFX_EV_RX_NLABELS);
        EFSYS_ASSERT3U(enp->en_rx_qcount + 1, <, encp->enc_rxq_limit);
 
-       EFSYS_ASSERT(ISP2(encp->enc_rxq_max_ndescs));
-       EFSYS_ASSERT(ISP2(encp->enc_rxq_min_ndescs));
-
-       if (!ISP2(ndescs) ||
-           (ndescs < encp->enc_rxq_min_ndescs) ||
-           (ndescs > encp->enc_rxq_max_ndescs)) {
-               rc = EINVAL;
-               goto fail1;
-       }
        if (index >= encp->enc_rxq_limit) {
                rc = EINVAL;
-               goto fail2;
+               goto fail1;
        }
 
        switch (type) {
@@ -1034,7 +1025,7 @@ ef10_rx_qcreate(
        case EFX_RXQ_TYPE_PACKED_STREAM:
                if (type_data == NULL) {
                        rc = EINVAL;
-                       goto fail3;
+                       goto fail2;
                }
                switch (type_data->ertd_packed_stream.eps_buf_size) {
                case EFX_RXQ_PACKED_STREAM_BUF_SIZE_1M:
@@ -1054,7 +1045,7 @@ ef10_rx_qcreate(
                        break;
                default:
                        rc = ENOTSUP;
-                       goto fail4;
+                       goto fail3;
                }
                break;
 #endif /* EFSYS_OPT_RX_PACKED_STREAM */
@@ -1062,7 +1053,7 @@ ef10_rx_qcreate(
        case EFX_RXQ_TYPE_ES_SUPER_BUFFER:
                if (type_data == NULL) {
                        rc = EINVAL;
-                       goto fail5;
+                       goto fail4;
                }
                ps_buf_size = 0;
                es_bufs_per_desc =
@@ -1077,7 +1068,7 @@ ef10_rx_qcreate(
 #endif /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
        default:
                rc = ENOTSUP;
-               goto fail6;
+               goto fail5;
        }
 
 #if EFSYS_OPT_RX_PACKED_STREAM
@@ -1085,13 +1076,13 @@ ef10_rx_qcreate(
                /* Check if datapath firmware supports packed stream mode */
                if (encp->enc_rx_packed_stream_supported == B_FALSE) {
                        rc = ENOTSUP;
-                       goto fail7;
+                       goto fail6;
                }
                /* Check if packed stream allows configurable buffer sizes */
                if ((ps_buf_size != MC_CMD_INIT_RXQ_EXT_IN_PS_BUFF_1M) &&
                    (encp->enc_rx_var_packed_stream_supported == B_FALSE)) {
                        rc = ENOTSUP;
-                       goto fail8;
+                       goto fail7;
                }
        }
 #else /* EFSYS_OPT_RX_PACKED_STREAM */
@@ -1102,17 +1093,17 @@ ef10_rx_qcreate(
        if (es_bufs_per_desc > 0) {
                if (encp->enc_rx_es_super_buffer_supported == B_FALSE) {
                        rc = ENOTSUP;
-                       goto fail9;
+                       goto fail8;
                }
                if (!IS_P2ALIGNED(es_max_dma_len,
                            EFX_RX_ES_SUPER_BUFFER_BUF_ALIGNMENT)) {
                        rc = EINVAL;
-                       goto fail10;
+                       goto fail9;
                }
                if (!IS_P2ALIGNED(es_buf_stride,
                            EFX_RX_ES_SUPER_BUFFER_BUF_ALIGNMENT)) {
                        rc = EINVAL;
-                       goto fail11;
+                       goto fail10;
                }
        }
 #else /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
@@ -1134,7 +1125,7 @@ ef10_rx_qcreate(
                    esmp, disable_scatter, want_inner_classes,
                    ps_buf_size, es_bufs_per_desc, es_max_dma_len,
                    es_buf_stride, hol_block_timeout)) != 0)
-               goto fail12;
+               goto fail11;
 
        erp->er_eep = eep;
        erp->er_label = label;
@@ -1145,36 +1136,34 @@ ef10_rx_qcreate(
 
        return (0);
 
-fail12:
-       EFSYS_PROBE(fail12);
-#if EFSYS_OPT_RX_ES_SUPER_BUFFER
 fail11:
        EFSYS_PROBE(fail11);
+#if EFSYS_OPT_RX_ES_SUPER_BUFFER
 fail10:
        EFSYS_PROBE(fail10);
 fail9:
        EFSYS_PROBE(fail9);
-#endif /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
-#if EFSYS_OPT_RX_PACKED_STREAM
 fail8:
        EFSYS_PROBE(fail8);
+#endif /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
+#if EFSYS_OPT_RX_PACKED_STREAM
 fail7:
        EFSYS_PROBE(fail7);
-#endif /* EFSYS_OPT_RX_PACKED_STREAM */
 fail6:
        EFSYS_PROBE(fail6);
-#if EFSYS_OPT_RX_ES_SUPER_BUFFER
+#endif /* EFSYS_OPT_RX_PACKED_STREAM */
 fail5:
        EFSYS_PROBE(fail5);
-#endif /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
-#if EFSYS_OPT_RX_PACKED_STREAM
+#if EFSYS_OPT_RX_ES_SUPER_BUFFER
 fail4:
        EFSYS_PROBE(fail4);
+#endif /* EFSYS_OPT_RX_ES_SUPER_BUFFER */
+#if EFSYS_OPT_RX_PACKED_STREAM
 fail3:
        EFSYS_PROBE(fail3);
-#endif /* EFSYS_OPT_RX_PACKED_STREAM */
 fail2:
        EFSYS_PROBE(fail2);
+#endif /* EFSYS_OPT_RX_PACKED_STREAM */
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
 
index 332f8c8..8910cd5 100644 (file)
@@ -794,17 +794,28 @@ efx_rx_qcreate_internal(
 {
        const efx_rx_ops_t *erxop = enp->en_erxop;
        efx_rxq_t *erp;
+       const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
        efx_rc_t rc;
 
        EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
        EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_RX);
 
+       EFSYS_ASSERT(ISP2(encp->enc_rxq_max_ndescs));
+       EFSYS_ASSERT(ISP2(encp->enc_rxq_min_ndescs));
+
+       if (!ISP2(ndescs) ||
+           ndescs < encp->enc_rxq_min_ndescs ||
+           ndescs > encp->enc_rxq_max_ndescs) {
+               rc = EINVAL;
+               goto fail1;
+       }
+
        /* Allocate an RXQ object */
        EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_rxq_t), erp);
 
        if (erp == NULL) {
                rc = ENOMEM;
-               goto fail1;
+               goto fail2;
        }
 
        erp->er_magic = EFX_RXQ_MAGIC;
@@ -815,17 +826,19 @@ efx_rx_qcreate_internal(
 
        if ((rc = erxop->erxo_qcreate(enp, index, label, type, type_data, esmp,
            ndescs, id, flags, eep, erp)) != 0)
-               goto fail2;
+               goto fail3;
 
        enp->en_rx_qcount++;
        *erpp = erp;
 
        return (0);
 
-fail2:
-       EFSYS_PROBE(fail2);
+fail3:
+       EFSYS_PROBE(fail3);
 
        EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_rxq_t), erp);
+fail2:
+       EFSYS_PROBE(fail2);
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
 
@@ -1590,18 +1603,9 @@ siena_rx_qcreate(
        EFSYS_ASSERT3U(label, <, EFX_EV_RX_NLABELS);
        EFSYS_ASSERT3U(enp->en_rx_qcount + 1, <, encp->enc_rxq_limit);
 
-       EFSYS_ASSERT(ISP2(encp->enc_rxq_max_ndescs));
-       EFSYS_ASSERT(ISP2(encp->enc_rxq_min_ndescs));
-
-       if (!ISP2(ndescs) ||
-           (ndescs < encp->enc_rxq_min_ndescs) ||
-           (ndescs > encp->enc_rxq_max_ndescs)) {
-               rc = EINVAL;
-               goto fail1;
-       }
        if (index >= encp->enc_rxq_limit) {
                rc = EINVAL;
-               goto fail2;
+               goto fail1;
        }
        for (size = 0;
            (1U << size) <= encp->enc_rxq_max_ndescs / encp->enc_rxq_min_ndescs;
@@ -1610,7 +1614,7 @@ siena_rx_qcreate(
                        break;
        if (id + (1 << size) >= encp->enc_buftbl_limit) {
                rc = EINVAL;
-               goto fail3;
+               goto fail2;
        }
 
        switch (type) {
@@ -1619,7 +1623,7 @@ siena_rx_qcreate(
 
        default:
                rc = EINVAL;
-               goto fail4;
+               goto fail3;
        }
 
        if (flags & EFX_RXQ_FLAG_SCATTER) {
@@ -1627,7 +1631,7 @@ siena_rx_qcreate(
                jumbo = B_TRUE;
 #else
                rc = EINVAL;
-               goto fail5;
+               goto fail4;
 #endif /* EFSYS_OPT_RX_SCATTER */
        }
 
@@ -1647,11 +1651,9 @@ siena_rx_qcreate(
        return (0);
 
 #if !EFSYS_OPT_RX_SCATTER
-fail5:
-       EFSYS_PROBE(fail5);
-#endif
 fail4:
        EFSYS_PROBE(fail4);
+#endif
 fail3:
        EFSYS_PROBE(fail3);
 fail2: