net/sfc/base: add API to control UDP tunnel ports
[dpdk.git] / drivers / net / sfc / base / efx_nic.c
index d4b5d08..4a31bca 100644 (file)
@@ -102,78 +102,6 @@ efx_family(
        return (ENOTSUP);
 }
 
-
-#define        EFX_BIU_MAGIC0  0x01234567
-#define        EFX_BIU_MAGIC1  0xfedcba98
-
-       __checkReturn   efx_rc_t
-efx_nic_biu_test(
-       __in            efx_nic_t *enp)
-{
-       efx_oword_t oword;
-       efx_rc_t rc;
-
-       /*
-        * Write magic values to scratch registers 0 and 1, then
-        * verify that the values were written correctly.  Interleave
-        * the accesses to ensure that the BIU is not just reading
-        * back the cached value that was last written.
-        */
-       EFX_POPULATE_OWORD_1(oword, FRF_AZ_DRIVER_DW0, EFX_BIU_MAGIC0);
-       EFX_BAR_TBL_WRITEO(enp, FR_AZ_DRIVER_REG, 0, &oword, B_TRUE);
-
-       EFX_POPULATE_OWORD_1(oword, FRF_AZ_DRIVER_DW0, EFX_BIU_MAGIC1);
-       EFX_BAR_TBL_WRITEO(enp, FR_AZ_DRIVER_REG, 1, &oword, B_TRUE);
-
-       EFX_BAR_TBL_READO(enp, FR_AZ_DRIVER_REG, 0, &oword, B_TRUE);
-       if (EFX_OWORD_FIELD(oword, FRF_AZ_DRIVER_DW0) != EFX_BIU_MAGIC0) {
-               rc = EIO;
-               goto fail1;
-       }
-
-       EFX_BAR_TBL_READO(enp, FR_AZ_DRIVER_REG, 1, &oword, B_TRUE);
-       if (EFX_OWORD_FIELD(oword, FRF_AZ_DRIVER_DW0) != EFX_BIU_MAGIC1) {
-               rc = EIO;
-               goto fail2;
-       }
-
-       /*
-        * Perform the same test, with the values swapped.  This
-        * ensures that subsequent tests don't start with the correct
-        * values already written into the scratch registers.
-        */
-       EFX_POPULATE_OWORD_1(oword, FRF_AZ_DRIVER_DW0, EFX_BIU_MAGIC1);
-       EFX_BAR_TBL_WRITEO(enp, FR_AZ_DRIVER_REG, 0, &oword, B_TRUE);
-
-       EFX_POPULATE_OWORD_1(oword, FRF_AZ_DRIVER_DW0, EFX_BIU_MAGIC0);
-       EFX_BAR_TBL_WRITEO(enp, FR_AZ_DRIVER_REG, 1, &oword, B_TRUE);
-
-       EFX_BAR_TBL_READO(enp, FR_AZ_DRIVER_REG, 0, &oword, B_TRUE);
-       if (EFX_OWORD_FIELD(oword, FRF_AZ_DRIVER_DW0) != EFX_BIU_MAGIC1) {
-               rc = EIO;
-               goto fail3;
-       }
-
-       EFX_BAR_TBL_READO(enp, FR_AZ_DRIVER_REG, 1, &oword, B_TRUE);
-       if (EFX_OWORD_FIELD(oword, FRF_AZ_DRIVER_DW0) != EFX_BIU_MAGIC0) {
-               rc = EIO;
-               goto fail4;
-       }
-
-       return (0);
-
-fail4:
-       EFSYS_PROBE(fail4);
-fail3:
-       EFSYS_PROBE(fail3);
-fail2:
-       EFSYS_PROBE(fail2);
-fail1:
-       EFSYS_PROBE1(fail1, efx_rc_t, rc);
-
-       return (rc);
-}
-
 #if EFSYS_OPT_SIENA
 
 static const efx_nic_ops_t     __efx_nic_siena_ops = {
@@ -616,154 +544,70 @@ efx_nic_cfg_get(
        return (&(enp->en_nic_cfg));
 }
 
-#if EFSYS_OPT_DIAG
-
-       __checkReturn   efx_rc_t
-efx_nic_register_test(
-       __in            efx_nic_t *enp)
+       __checkReturn           efx_rc_t
+efx_nic_get_fw_version(
+       __in                    efx_nic_t *enp,
+       __out                   efx_nic_fw_info_t *enfip)
 {
-       const efx_nic_ops_t *enop = enp->en_enop;
+       uint16_t mc_fw_version[4];
        efx_rc_t rc;
 
-       EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
-       EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
-       EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_NIC));
-
-       if ((rc = enop->eno_register_test(enp)) != 0)
+       if (enfip == NULL) {
+               rc = EINVAL;
                goto fail1;
+       }
 
-       return (0);
-
-fail1:
-       EFSYS_PROBE1(fail1, efx_rc_t, rc);
-
-       return (rc);
-}
-
-       __checkReturn   efx_rc_t
-efx_nic_test_registers(
-       __in            efx_nic_t *enp,
-       __in            efx_register_set_t *rsp,
-       __in            size_t count)
-{
-       unsigned int bit;
-       efx_oword_t original;
-       efx_oword_t reg;
-       efx_oword_t buf;
-       efx_rc_t rc;
-
-       while (count > 0) {
-               /* This function is only suitable for registers */
-               EFSYS_ASSERT(rsp->rows == 1);
-
-               /* bit sweep on and off */
-               EFSYS_BAR_READO(enp->en_esbp, rsp->address, &original,
-                           B_TRUE);
-               for (bit = 0; bit < 128; bit++) {
-                       /* Is this bit in the mask? */
-                       if (~(rsp->mask.eo_u32[bit >> 5]) & (1 << bit))
-                               continue;
-
-                       /* Test this bit can be set in isolation */
-                       reg = original;
-                       EFX_AND_OWORD(reg, rsp->mask);
-                       EFX_SET_OWORD_BIT(reg, bit);
-
-                       EFSYS_BAR_WRITEO(enp->en_esbp, rsp->address, &reg,
-                                   B_TRUE);
-                       EFSYS_BAR_READO(enp->en_esbp, rsp->address, &buf,
-                                   B_TRUE);
-
-                       EFX_AND_OWORD(buf, rsp->mask);
-                       if (memcmp(&reg, &buf, sizeof (reg))) {
-                               rc = EIO;
-                               goto fail1;
-                       }
-
-                       /* Test this bit can be cleared in isolation */
-                       EFX_OR_OWORD(reg, rsp->mask);
-                       EFX_CLEAR_OWORD_BIT(reg, bit);
-
-                       EFSYS_BAR_WRITEO(enp->en_esbp, rsp->address, &reg,
-                                   B_TRUE);
-                       EFSYS_BAR_READO(enp->en_esbp, rsp->address, &buf,
-                                   B_TRUE);
-
-                       EFX_AND_OWORD(buf, rsp->mask);
-                       if (memcmp(&reg, &buf, sizeof (reg))) {
-                               rc = EIO;
-                               goto fail2;
-                       }
-               }
+       EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
+       EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
 
-               /* Restore the old value */
-               EFSYS_BAR_WRITEO(enp->en_esbp, rsp->address, &original,
-                           B_TRUE);
+       rc = efx_mcdi_version(enp, mc_fw_version, NULL, NULL);
+       if (rc != 0)
+               goto fail2;
 
-               --count;
-               ++rsp;
+       rc = efx_mcdi_get_capabilities(enp, NULL,
+           &enfip->enfi_rx_dpcpu_fw_id,
+           &enfip->enfi_tx_dpcpu_fw_id,
+           NULL, NULL);
+       if (rc == 0) {
+               enfip->enfi_dpcpu_fw_ids_valid = B_TRUE;
+       } else if (rc == ENOTSUP) {
+               enfip->enfi_dpcpu_fw_ids_valid = B_FALSE;
+               enfip->enfi_rx_dpcpu_fw_id = 0;
+               enfip->enfi_tx_dpcpu_fw_id = 0;
+       } else {
+               goto fail3;
        }
 
+       memcpy(enfip->enfi_mc_fw_version, mc_fw_version,
+           sizeof (mc_fw_version));
+
        return (0);
 
+fail3:
+       EFSYS_PROBE(fail3);
 fail2:
        EFSYS_PROBE(fail2);
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
 
-       /* Restore the old value */
-       EFSYS_BAR_WRITEO(enp->en_esbp, rsp->address, &original, B_TRUE);
-
        return (rc);
 }
 
+#if EFSYS_OPT_DIAG
+
        __checkReturn   efx_rc_t
-efx_nic_test_tables(
-       __in            efx_nic_t *enp,
-       __in            efx_register_set_t *rsp,
-       __in            efx_pattern_type_t pattern,
-       __in            size_t count)
+efx_nic_register_test(
+       __in            efx_nic_t *enp)
 {
-       efx_sram_pattern_fn_t func;
-       unsigned int index;
-       unsigned int address;
-       efx_oword_t reg;
-       efx_oword_t buf;
+       const efx_nic_ops_t *enop = enp->en_enop;
        efx_rc_t rc;
 
-       EFSYS_ASSERT(pattern < EFX_PATTERN_NTYPES);
-       func = __efx_sram_pattern_fns[pattern];
-
-       while (count > 0) {
-               /* Write */
-               address = rsp->address;
-               for (index = 0; index < rsp->rows; ++index) {
-                       func(2 * index + 0, B_FALSE, &reg.eo_qword[0]);
-                       func(2 * index + 1, B_FALSE, &reg.eo_qword[1]);
-                       EFX_AND_OWORD(reg, rsp->mask);
-                       EFSYS_BAR_WRITEO(enp->en_esbp, address, &reg, B_TRUE);
-
-                       address += rsp->step;
-               }
-
-               /* Read */
-               address = rsp->address;
-               for (index = 0; index < rsp->rows; ++index) {
-                       func(2 * index + 0, B_FALSE, &reg.eo_qword[0]);
-                       func(2 * index + 1, B_FALSE, &reg.eo_qword[1]);
-                       EFX_AND_OWORD(reg, rsp->mask);
-                       EFSYS_BAR_READO(enp->en_esbp, address, &buf, B_TRUE);
-                       if (memcmp(&reg, &buf, sizeof (reg))) {
-                               rc = EIO;
-                               goto fail1;
-                       }
-
-                       address += rsp->step;
-               }
+       EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
+       EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
+       EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_NIC));
 
-               ++rsp;
-               --count;
-       }
+       if ((rc = enop->eno_register_test(enp)) != 0)
+               goto fail1;
 
        return (0);