nfp: add support for indirect HWinfo lookup
authorJakub Kicinski <jakub.kicinski@netronome.com>
Tue, 28 Aug 2018 20:20:36 +0000 (13:20 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 28 Aug 2018 23:01:47 +0000 (16:01 -0700)
Management FW can adjust some of the information in the HWinfo table
at runtime.  In some cases reading the table directly will not yield
correct results.  Add a NSP command for looking up information.
Up until now we weren't making use of any of the values which may
get adjusted.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.h

index 9eb7b5a91bb138692a895c153632ca9c51eb431c..bf593a6b26a1a145fb2b557129a2cf56c953a733 100644 (file)
@@ -90,6 +90,8 @@
 #define NFP_FW_LOAD_RET_MAJOR  GENMASK(15, 8)
 #define NFP_FW_LOAD_RET_MINOR  GENMASK(23, 16)
 
+#define NFP_HWINFO_LOOKUP_SIZE GENMASK(11, 0)
+
 enum nfp_nsp_cmd {
        SPCODE_NOOP             = 0, /* No operation */
        SPCODE_SOFT_RESET       = 1, /* Soft reset the NFP */
@@ -104,6 +106,7 @@ enum nfp_nsp_cmd {
        SPCODE_NSP_SENSORS      = 12, /* Read NSP sensor(s) */
        SPCODE_NSP_IDENTIFY     = 13, /* Read NSP version */
        SPCODE_FW_STORED        = 16, /* If no FW loaded, load flash app FW */
+       SPCODE_HWINFO_LOOKUP    = 17, /* Lookup HWinfo with overwrites etc. */
 };
 
 static const struct {
@@ -703,3 +706,38 @@ int nfp_nsp_load_stored_fw(struct nfp_nsp *state)
        nfp_nsp_load_fw_extended_msg(state, ret);
        return 0;
 }
+
+static int
+__nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, unsigned int size)
+{
+       struct nfp_nsp_command_buf_arg hwinfo_lookup = {
+               {
+                       .code           = SPCODE_HWINFO_LOOKUP,
+                       .option         = size,
+               },
+               .in_buf         = buf,
+               .in_size        = size,
+               .out_buf        = buf,
+               .out_size       = size,
+       };
+
+       return nfp_nsp_command_buf(state, &hwinfo_lookup);
+}
+
+int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, unsigned int size)
+{
+       int err;
+
+       size = min_t(u32, size, NFP_HWINFO_LOOKUP_SIZE);
+
+       err = __nfp_nsp_hwinfo_lookup(state, buf, size);
+       if (err)
+               return err;
+
+       if (strnlen(buf, size) == size) {
+               nfp_err(state->cpp, "NSP HWinfo value not NULL-terminated\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
index 65f2d4a6de02274ffc6b8fa4c6a5c94aa984d796..bd6c9071c8e920f9743bc5031e041dc1b4d3da70 100644 (file)
@@ -51,6 +51,7 @@ int nfp_nsp_load_fw(struct nfp_nsp *state, const struct firmware *fw);
 int nfp_nsp_write_flash(struct nfp_nsp *state, const struct firmware *fw);
 int nfp_nsp_mac_reinit(struct nfp_nsp *state);
 int nfp_nsp_load_stored_fw(struct nfp_nsp *state);
+int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, unsigned int size);
 
 static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state)
 {
@@ -62,6 +63,11 @@ static inline bool nfp_nsp_has_stored_fw_load(struct nfp_nsp *state)
        return nfp_nsp_get_abi_ver_minor(state) > 23;
 }
 
+static inline bool nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state)
+{
+       return nfp_nsp_get_abi_ver_minor(state) > 24;
+}
+
 enum nfp_eth_interface {
        NFP_INTERFACE_NONE      = 0,
        NFP_INTERFACE_SFP       = 1,