net/sfc/base: add advanced function to extract FW version
authorIvan Malov <ivan.malov@oktetlabs.ru>
Thu, 16 Mar 2017 11:01:34 +0000 (11:01 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 4 Apr 2017 16:59:41 +0000 (18:59 +0200)
Some libefx-based drivers might need this functionality to
indicate DPCPU FW IDs as part of FW version info to assist
experienced users.

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andrew Lee <alee@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@solarflare.com>
drivers/net/sfc/base/ef10_nic.c
drivers/net/sfc/base/efx.h
drivers/net/sfc/base/efx_mcdi.c
drivers/net/sfc/base/efx_mcdi.h
drivers/net/sfc/base/efx_nic.c

index 7af8935..3a74320 100644 (file)
@@ -490,59 +490,6 @@ fail1:
        return (rc);
 }
 
-static __checkReturn   efx_rc_t
-efx_mcdi_get_capabilities(
-       __in            efx_nic_t *enp,
-       __out           uint32_t *flagsp,
-       __out           uint32_t *flags2p,
-       __out           uint32_t *tso2ncp)
-{
-       efx_mcdi_req_t req;
-       uint8_t payload[MAX(MC_CMD_GET_CAPABILITIES_IN_LEN,
-                           MC_CMD_GET_CAPABILITIES_V2_OUT_LEN)];
-       efx_rc_t rc;
-
-       (void) memset(payload, 0, sizeof (payload));
-       req.emr_cmd = MC_CMD_GET_CAPABILITIES;
-       req.emr_in_buf = payload;
-       req.emr_in_length = MC_CMD_GET_CAPABILITIES_IN_LEN;
-       req.emr_out_buf = payload;
-       req.emr_out_length = MC_CMD_GET_CAPABILITIES_V2_OUT_LEN;
-
-       efx_mcdi_execute(enp, &req);
-
-       if (req.emr_rc != 0) {
-               rc = req.emr_rc;
-               goto fail1;
-       }
-
-       if (req.emr_out_length_used < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
-               rc = EMSGSIZE;
-               goto fail2;
-       }
-
-       *flagsp = MCDI_OUT_DWORD(req, GET_CAPABILITIES_OUT_FLAGS1);
-
-       if (req.emr_out_length_used < MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) {
-               *flags2p = 0;
-               *tso2ncp = 0;
-       } else {
-               *flags2p = MCDI_OUT_DWORD(req, GET_CAPABILITIES_V2_OUT_FLAGS2);
-               *tso2ncp = MCDI_OUT_WORD(req,
-                               GET_CAPABILITIES_V2_OUT_TX_TSO_V2_N_CONTEXTS);
-       }
-
-       return (0);
-
-fail2:
-       EFSYS_PROBE(fail2);
-fail1:
-       EFSYS_PROBE1(fail1, efx_rc_t, rc);
-
-       return (rc);
-}
-
-
 static __checkReturn   efx_rc_t
 efx_mcdi_alloc_vis(
        __in            efx_nic_t *enp,
@@ -1012,8 +959,8 @@ ef10_get_datapath_caps(
        uint32_t tso2nc;
        efx_rc_t rc;
 
-       if ((rc = efx_mcdi_get_capabilities(enp, &flags, &flags2,
-                                           &tso2nc)) != 0)
+       if ((rc = efx_mcdi_get_capabilities(enp, &flags, NULL, NULL,
+                                           &flags2, &tso2nc)) != 0)
                goto fail1;
 
        if ((rc = ef10_mcdi_get_pf_count(enp, &encp->enc_hw_pf_count)) != 0)
index 6118296..7eabc37 100644 (file)
@@ -1211,6 +1211,24 @@ extern                   const efx_nic_cfg_t *
 efx_nic_cfg_get(
        __in            efx_nic_t *enp);
 
+typedef struct efx_nic_fw_info_s {
+       /* Basic FW version information */
+       uint16_t        enfi_mc_fw_version[4];
+       /*
+        * If datapath capabilities can be detected,
+        * additional FW information is to be shown
+        */
+       boolean_t       enfi_dpcpu_fw_ids_valid;
+       /* Rx and Tx datapath CPU FW IDs */
+       uint16_t        enfi_rx_dpcpu_fw_id;
+       uint16_t        enfi_tx_dpcpu_fw_id;
+} efx_nic_fw_info_t;
+
+extern __checkReturn           efx_rc_t
+efx_nic_get_fw_version(
+       __in                    efx_nic_t *enp,
+       __out                   efx_nic_fw_info_t *enfip);
+
 /* Driver resource limits (minimum required/maximum usable). */
 typedef struct efx_drv_limits_s {
        uint32_t        edl_min_evq_count;
index c9d29a7..c61b943 100644 (file)
@@ -1024,6 +1024,79 @@ fail1:
        return (rc);
 }
 
+       __checkReturn   efx_rc_t
+efx_mcdi_get_capabilities(
+       __in            efx_nic_t *enp,
+       __out_opt       uint32_t *flagsp,
+       __out_opt       uint16_t *rx_dpcpu_fw_idp,
+       __out_opt       uint16_t *tx_dpcpu_fw_idp,
+       __out_opt       uint32_t *flags2p,
+       __out_opt       uint32_t *tso2ncp)
+{
+       efx_mcdi_req_t req;
+       uint8_t payload[MAX(MC_CMD_GET_CAPABILITIES_IN_LEN,
+                           MC_CMD_GET_CAPABILITIES_V2_OUT_LEN)];
+       boolean_t v2_capable;
+       efx_rc_t rc;
+
+       (void) memset(payload, 0, sizeof (payload));
+       req.emr_cmd = MC_CMD_GET_CAPABILITIES;
+       req.emr_in_buf = payload;
+       req.emr_in_length = MC_CMD_GET_CAPABILITIES_IN_LEN;
+       req.emr_out_buf = payload;
+       req.emr_out_length = MC_CMD_GET_CAPABILITIES_V2_OUT_LEN;
+
+       efx_mcdi_execute_quiet(enp, &req);
+
+       if (req.emr_rc != 0) {
+               rc = req.emr_rc;
+               goto fail1;
+       }
+
+       if (req.emr_out_length_used < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
+               rc = EMSGSIZE;
+               goto fail2;
+       }
+
+       if (flagsp != NULL)
+               *flagsp = MCDI_OUT_DWORD(req, GET_CAPABILITIES_OUT_FLAGS1);
+
+       if (rx_dpcpu_fw_idp != NULL)
+               *rx_dpcpu_fw_idp = MCDI_OUT_WORD(req,
+                                       GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
+
+       if (tx_dpcpu_fw_idp != NULL)
+               *tx_dpcpu_fw_idp = MCDI_OUT_WORD(req,
+                                       GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
+
+       if (req.emr_out_length_used < MC_CMD_GET_CAPABILITIES_V2_OUT_LEN)
+               v2_capable = B_FALSE;
+       else
+               v2_capable = B_TRUE;
+
+       if (flags2p != NULL) {
+               *flags2p = (v2_capable) ?
+                       MCDI_OUT_DWORD(req, GET_CAPABILITIES_V2_OUT_FLAGS2) :
+                       0;
+       }
+
+       if (tso2ncp != NULL) {
+               *tso2ncp = (v2_capable) ?
+                       MCDI_OUT_WORD(req,
+                               GET_CAPABILITIES_V2_OUT_TX_TSO_V2_N_CONTEXTS) :
+                       0;
+       }
+
+       return (0);
+
+fail2:
+       EFSYS_PROBE(fail2);
+fail1:
+       EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+       return (rc);
+}
+
 static __checkReturn   efx_rc_t
 efx_mcdi_do_reboot(
        __in            efx_nic_t *enp,
index 7faabbb..2172771 100644 (file)
@@ -135,6 +135,15 @@ efx_mcdi_version(
        __out_opt               uint32_t *buildp,
        __out_opt               efx_mcdi_boot_t *statusp);
 
+extern __checkReturn   efx_rc_t
+efx_mcdi_get_capabilities(
+       __in            efx_nic_t *enp,
+       __out_opt       uint32_t *flagsp,
+       __out_opt       uint16_t *rx_dpcpu_fw_idp,
+       __out_opt       uint16_t *tx_dpcpu_fw_idp,
+       __out_opt       uint32_t *flags2p,
+       __out_opt       uint32_t *tso2ncp);
+
 extern __checkReturn           efx_rc_t
 efx_mcdi_read_assertion(
        __in                    efx_nic_t *enp);
index d4b5d08..76caa74 100644 (file)
@@ -616,6 +616,54 @@ efx_nic_cfg_get(
        return (&(enp->en_nic_cfg));
 }
 
+       __checkReturn           efx_rc_t
+efx_nic_get_fw_version(
+       __in                    efx_nic_t *enp,
+       __out                   efx_nic_fw_info_t *enfip)
+{
+       uint16_t mc_fw_version[4];
+       efx_rc_t rc;
+
+       if (enfip == NULL) {
+               rc = EINVAL;
+               goto fail1;
+       }
+
+       EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
+       EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
+
+       rc = efx_mcdi_version(enp, mc_fw_version, NULL, NULL);
+       if (rc != 0)
+               goto fail2;
+
+       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);
+
+       return (rc);
+}
+
 #if EFSYS_OPT_DIAG
 
        __checkReturn   efx_rc_t