]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
nfp: add RTsym access helpers
authorJakub Kicinski <jakub.kicinski@netronome.com>
Tue, 28 Aug 2018 20:20:42 +0000 (13:20 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 28 Aug 2018 23:01:47 +0000 (16:01 -0700)
RTsyms may have special encodings for more complex symbol types.
For example symbols which are placed in external memory unit's
cache directly, constants or local memory.  Add set of helpers
which will check for those special encodings and handle them
correctly.

For now only add direct cache accesses, we don't have a need to
access the other ones in foreseeable future.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Francois H. Theron <francois.theron@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nffw.h
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_rtsym.c

index df599d5b6bb35c148b31caf20118087f346e4631..04700278d00d15df8416fc8aacf0553c5bf3e694 100644 (file)
@@ -98,6 +98,31 @@ const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx);
 const struct nfp_rtsym *
 nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name);
 
+int __nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                    u8 action, u8 token, u64 off, void *buf, size_t len);
+int nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                  void *buf, size_t len);
+int __nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                     u8 action, u8 token, u64 off, u32 *value);
+int nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                   u32 *value);
+int __nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                     u8 action, u8 token, u64 off, u64 *value);
+int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                   u64 *value);
+int __nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                     u8 action, u8 token, u64 off, void *buf, size_t len);
+int nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                   void *buf, size_t len);
+int __nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                      u8 action, u8 token, u64 off, u32 value);
+int nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                    u32 value);
+int __nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                      u8 action, u8 token, u64 off, u64 value);
+int nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                    u64 value);
+
 u64 nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name,
                      int *error);
 int nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, const char *name,
index 9e34216578daf7acf876e2957900c43fdacc5513..1c0b1b11b69f50c1efabbcdfbc6f73fdf96b1d50 100644 (file)
@@ -233,6 +233,152 @@ nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name)
        return NULL;
 }
 
+static int
+nfp_rtsym_to_dest(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                 u8 action, u8 token, u64 off, u32 *cpp_id, u64 *addr)
+{
+       *addr = sym->addr + off;
+
+       if (sym->target == NFP_RTSYM_TARGET_EMU_CACHE) {
+               int locality_off = nfp_cpp_mu_locality_lsb(cpp);
+
+               *addr &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off);
+               *addr |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off;
+
+               *cpp_id = NFP_CPP_ISLAND_ID(NFP_CPP_TARGET_MU, action, token,
+                                           sym->domain);
+       } else if (sym->target < 0) {
+               nfp_err(cpp, "Unhandled RTsym target encoding: %d\n",
+                       sym->target);
+               return -EINVAL;
+       } else {
+               *cpp_id = NFP_CPP_ISLAND_ID(sym->target, action, token,
+                                           sym->domain);
+       }
+
+       return 0;
+}
+
+int __nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                    u8 action, u8 token, u64 off, void *buf, size_t len)
+{
+       u32 cpp_id;
+       u64 addr;
+       int err;
+
+       err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
+       if (err)
+               return err;
+
+       return nfp_cpp_read(cpp, cpp_id, addr, buf, len);
+}
+
+int nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                  void *buf, size_t len)
+{
+       return __nfp_rtsym_read(cpp, sym, NFP_CPP_ACTION_RW, 0, off, buf, len);
+}
+
+int __nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                     u8 action, u8 token, u64 off, u32 *value)
+{
+       u32 cpp_id;
+       u64 addr;
+       int err;
+
+       err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
+       if (err)
+               return err;
+
+       return nfp_cpp_readl(cpp, cpp_id, addr, value);
+}
+
+int nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                   u32 *value)
+{
+       return __nfp_rtsym_readl(cpp, sym, NFP_CPP_ACTION_RW, 0, off, value);
+}
+
+int __nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                     u8 action, u8 token, u64 off, u64 *value)
+{
+       u32 cpp_id;
+       u64 addr;
+       int err;
+
+       err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
+       if (err)
+               return err;
+
+       return nfp_cpp_readq(cpp, cpp_id, addr, value);
+}
+
+int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                   u64 *value)
+{
+       return __nfp_rtsym_readq(cpp, sym, NFP_CPP_ACTION_RW, 0, off, value);
+}
+
+int __nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                     u8 action, u8 token, u64 off, void *buf, size_t len)
+{
+       u32 cpp_id;
+       u64 addr;
+       int err;
+
+       err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
+       if (err)
+               return err;
+
+       return nfp_cpp_write(cpp, cpp_id, addr, buf, len);
+}
+
+int nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                   void *buf, size_t len)
+{
+       return __nfp_rtsym_write(cpp, sym, NFP_CPP_ACTION_RW, 0, off, buf, len);
+}
+
+int __nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                      u8 action, u8 token, u64 off, u32 value)
+{
+       u32 cpp_id;
+       u64 addr;
+       int err;
+
+       err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
+       if (err)
+               return err;
+
+       return nfp_cpp_writel(cpp, cpp_id, addr, value);
+}
+
+int nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                    u32 value)
+{
+       return __nfp_rtsym_writel(cpp, sym, NFP_CPP_ACTION_RW, 0, off, value);
+}
+
+int __nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym,
+                      u8 action, u8 token, u64 off, u64 value)
+{
+       u32 cpp_id;
+       u64 addr;
+       int err;
+
+       err = nfp_rtsym_to_dest(cpp, sym, action, token, off, &cpp_id, &addr);
+       if (err)
+               return err;
+
+       return nfp_cpp_writeq(cpp, cpp_id, addr, value);
+}
+
+int nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, u64 off,
+                    u64 value)
+{
+       return __nfp_rtsym_writeq(cpp, sym, NFP_CPP_ACTION_RW, 0, off, value);
+}
+
 /**
  * nfp_rtsym_read_le() - Read a simple unsigned scalar value from symbol
  * @rtbl:      NFP RTsym table