nfp: move area mapping helper into nfpcore
authorJakub Kicinski <jakub.kicinski@netronome.com>
Tue, 27 Jun 2017 07:50:16 +0000 (00:50 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 27 Jun 2017 19:48:47 +0000 (15:48 -0400)
nfp_net_map_area() is a helper for mapping areas of NFP memory
defined in nfp_net_main.c.  Move it to nfpcore to allow reuse
and rename accordingly.  Create an additional helper -
nfp_cpp_area_alloc_acquire() the opposite of already existing
nfp_cpp_area_release_free().

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/nfp_net_main.c
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpplib.c

index 3169400dd4744ffc5fc508e3990ee14612f25c1b..16ee904db0cd6e16a9b23e16d37cd3c64052d37f 100644 (file)
@@ -80,58 +80,6 @@ static int nfp_is_ready(struct nfp_pf *pf)
        return state == 15;
 }
 
-/**
- * nfp_net_map_area() - Help function to map an area
- * @cpp:    NFP CPP handler
- * @name:   Name for the area
- * @target: CPP target
- * @addr:   CPP address
- * @size:   Size of the area
- * @area:   Area handle (returned).
- *
- * This function is primarily to simplify the code in the main probe
- * function. To undo the effect of this functions call
- * @nfp_cpp_area_release_free(*area);
- *
- * Return: Pointer to memory mapped area or ERR_PTR
- */
-static u8 __iomem *nfp_net_map_area(struct nfp_cpp *cpp,
-                                   const char *name, int isl, int target,
-                                   unsigned long long addr, unsigned long size,
-                                   struct nfp_cpp_area **area)
-{
-       u8 __iomem *res;
-       u32 dest;
-       int err;
-
-       dest = NFP_CPP_ISLAND_ID(target, NFP_CPP_ACTION_RW, 0, isl);
-
-       *area = nfp_cpp_area_alloc_with_name(cpp, dest, name, addr, size);
-       if (!*area) {
-               err = -EIO;
-               goto err_area;
-       }
-
-       err = nfp_cpp_area_acquire(*area);
-       if (err < 0)
-               goto err_acquire;
-
-       res = nfp_cpp_area_iomem(*area);
-       if (!res) {
-               err = -EIO;
-               goto err_map;
-       }
-
-       return res;
-
-err_map:
-       nfp_cpp_area_release(*area);
-err_acquire:
-       nfp_cpp_area_free(*area);
-err_area:
-       return (u8 __iomem *)ERR_PTR(err);
-}
-
 /**
  * nfp_net_get_mac_addr() - Get the MAC address.
  * @pf:       NFP PF handle
@@ -242,7 +190,7 @@ nfp_net_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt,
                return (u8 __iomem *)ERR_PTR(-EINVAL);
        }
 
-       mem = nfp_net_map_area(pf->cpp, name, sym->domain, sym->target,
+       mem = nfp_cpp_map_area(pf->cpp, name, sym->domain, sym->target,
                               sym->addr, sym->size, area);
        if (IS_ERR(mem)) {
                nfp_err(pf->cpp, "Failed to map PF symbol %s: %ld\n",
@@ -617,7 +565,7 @@ static int nfp_net_pci_map_mem(struct nfp_pf *pf)
                pf->vf_cfg_mem = NULL;
        }
 
-       mem = nfp_net_map_area(pf->cpp, "net.qc", 0, 0,
+       mem = nfp_cpp_map_area(pf->cpp, "net.qc", 0, 0,
                               NFP_PCIE_QUEUE(0), NFP_QCP_QUEUE_AREA_SZ,
                               &pf->qc_area);
        if (IS_ERR(mem)) {
index 25a967158ce9cb6706e617d79d642f05630bcc99..235dd023d9b9cc031e439165934e628add8af0ef 100644 (file)
@@ -230,6 +230,9 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp,
 struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, u32 cpp_id,
                                        unsigned long long address,
                                        unsigned long size);
+struct nfp_cpp_area *
+nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, const char *name, u32 cpp_id,
+                          unsigned long long address, unsigned long size);
 void nfp_cpp_area_free(struct nfp_cpp_area *area);
 int nfp_cpp_area_acquire(struct nfp_cpp_area *area);
 int nfp_cpp_area_acquire_nonblocking(struct nfp_cpp_area *area);
@@ -278,6 +281,10 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, u32 cpp_id,
 int nfp_cpp_writeq(struct nfp_cpp *cpp, u32 cpp_id,
                   unsigned long long address, u64 value);
 
+u8 __iomem *
+nfp_cpp_map_area(struct nfp_cpp *cpp, const char *name, int domain, int target,
+                u64 addr, unsigned long size, struct nfp_cpp_area **area);
+
 struct nfp_cpp_mutex;
 
 int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target,
index 9b69dcf87be934b10d57727626388a2b0b76e958..7d5d7293efed07fef686f27ba450ef9492109cd1 100644 (file)
@@ -360,6 +360,41 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, u32 dest,
        return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size);
 }
 
+/**
+ * nfp_cpp_area_alloc_acquire() - allocate a new CPP area and lock it down
+ * @cpp:       CPP handle
+ * @name:      Name of region
+ * @dest:      CPP id
+ * @address:   Start address on CPP target
+ * @size:      Size of area
+ *
+ * Allocate and initialize a CPP area structure, and lock it down so
+ * that it can be accessed directly.
+ *
+ * NOTE: @address and @size must be 32-bit aligned values.
+ *
+ * NOTE: The area must also be 'released' when the structure is freed.
+ *
+ * Return: NFP CPP Area handle, or NULL
+ */
+struct nfp_cpp_area *
+nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, const char *name, u32 dest,
+                          unsigned long long address, unsigned long size)
+{
+       struct nfp_cpp_area *area;
+
+       area = nfp_cpp_area_alloc_with_name(cpp, dest, name, address, size);
+       if (!area)
+               return NULL;
+
+       if (nfp_cpp_area_acquire(area)) {
+               nfp_cpp_area_free(area);
+               return NULL;
+       }
+
+       return area;
+}
+
 /**
  * nfp_cpp_area_free() - free up the CPP area
  * @area:      CPP area handle
index 0ba0379b8f7581bab817b1c5ab65fe024b55451e..ab86bceb93f2dbc907bcf88bb1653a7d8a8b87c4 100644 (file)
@@ -279,3 +279,43 @@ exit_release:
 
        return err;
 }
+
+/**
+ * nfp_cpp_map_area() - Helper function to map an area
+ * @cpp:    NFP CPP handler
+ * @name:   Name for the area
+ * @domain: CPP domain
+ * @target: CPP target
+ * @addr:   CPP address
+ * @size:   Size of the area
+ * @area:   Area handle (output)
+ *
+ * Map an area of IOMEM access.  To undo the effect of this function call
+ * @nfp_cpp_area_release_free(*area).
+ *
+ * Return: Pointer to memory mapped area or ERR_PTR
+ */
+u8 __iomem *
+nfp_cpp_map_area(struct nfp_cpp *cpp, const char *name, int domain, int target,
+                u64 addr, unsigned long size, struct nfp_cpp_area **area)
+{
+       u8 __iomem *res;
+       u32 dest;
+
+       dest = NFP_CPP_ISLAND_ID(target, NFP_CPP_ACTION_RW, 0, domain);
+
+       *area = nfp_cpp_area_alloc_acquire(cpp, name, dest, addr, size);
+       if (!*area)
+               goto err_eio;
+
+       res = nfp_cpp_area_iomem(*area);
+       if (!res)
+               goto err_release_free;
+
+       return res;
+
+err_release_free:
+       nfp_cpp_area_release_free(*area);
+err_eio:
+       return (u8 __iomem *)ERR_PTR(-EIO);
+}