diff mbox series

[net-next,03/15] qed: move chain methods to a separate file

Message ID 20200722155349.747-4-alobakin@marvell.com
State Changes Requested
Delegated to: David Miller
Headers show
Series qed/qede: improve chain API and add XDP_REDIRECT support | expand

Commit Message

Alexander Lobakin July 22, 2020, 3:53 p.m. UTC
Move chain allocation/freeing functions to a new file to not mix it with
hardware-related code.

Signed-off-by: Alexander Lobakin <alobakin@marvell.com>
Signed-off-by: Igor Russkikh <irusskikh@marvell.com>
Signed-off-by: Michal Kalderon <michal.kalderon@marvell.com>
---
 drivers/net/ethernet/qlogic/qed/Makefile    |   1 +
 drivers/net/ethernet/qlogic/qed/qed_chain.c | 300 ++++++++++++++++++++
 drivers/net/ethernet/qlogic/qed/qed_dev.c   | 273 ------------------
 3 files changed, 301 insertions(+), 273 deletions(-)
 create mode 100644 drivers/net/ethernet/qlogic/qed/qed_chain.c

Comments

kernel test robot July 22, 2020, 9:32 p.m. UTC | #1
Hi Alexander,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Alexander-Lobakin/qed-qede-improve-chain-API-and-add-XDP_REDIRECT-support/20200723-000000
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git fa56a987449bcf4c1cb68369a187af3515b85c78
config: alpha-allmodconfig (attached as .config)
compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   drivers/net/ethernet/qlogic/qed/qed_chain.c: In function 'qed_chain_free_pbl':
>> drivers/net/ethernet/qlogic/qed/qed_chain.c:70:2: error: implicit declaration of function 'vfree'; did you mean 'kvfree'? [-Werror=implicit-function-declaration]
      70 |  vfree(chain->pbl.pp_addr_tbl);
         |  ^~~~~
         |  kvfree
   drivers/net/ethernet/qlogic/qed/qed_chain.c: In function 'qed_chain_alloc_pbl':
>> drivers/net/ethernet/qlogic/qed/qed_chain.c:200:13: error: implicit declaration of function 'vzalloc'; did you mean 'kvzalloc'? [-Werror=implicit-function-declaration]
     200 |  addr_tbl = vzalloc(size);
         |             ^~~~~~~
         |             kvzalloc
>> drivers/net/ethernet/qlogic/qed/qed_chain.c:200:11: warning: assignment to 'struct addr_tbl_entry *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     200 |  addr_tbl = vzalloc(size);
         |           ^
   cc1: some warnings being treated as errors

vim +70 drivers/net/ethernet/qlogic/qed/qed_chain.c

    45	
    46	static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *chain)
    47	{
    48		struct device *dev = &cdev->pdev->dev;
    49		struct addr_tbl_entry *entry;
    50		u32 pbl_size, i;
    51	
    52		if (!chain->pbl.pp_addr_tbl)
    53			return;
    54	
    55		for (i = 0; i < chain->page_cnt; i++) {
    56			entry = chain->pbl.pp_addr_tbl + i;
    57			if (!entry->virt_addr)
    58				break;
    59	
    60			dma_free_coherent(dev, QED_CHAIN_PAGE_SIZE, entry->virt_addr,
    61					  entry->dma_map);
    62		}
    63	
    64		pbl_size = chain->page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
    65	
    66		if (!chain->b_external_pbl)
    67			dma_free_coherent(dev, pbl_size, chain->pbl_sp.p_virt_table,
    68					  chain->pbl_sp.p_phys_table);
    69	
  > 70		vfree(chain->pbl.pp_addr_tbl);
    71		chain->pbl.pp_addr_tbl = NULL;
    72	}
    73	
    74	/**
    75	 * qed_chain_free() - Free chain DMA memory.
    76	 *
    77	 * @cdev: Main device structure.
    78	 * @chain: Chain to free.
    79	 */
    80	void qed_chain_free(struct qed_dev *cdev, struct qed_chain *chain)
    81	{
    82		switch (chain->mode) {
    83		case QED_CHAIN_MODE_NEXT_PTR:
    84			qed_chain_free_next_ptr(cdev, chain);
    85			break;
    86		case QED_CHAIN_MODE_SINGLE:
    87			qed_chain_free_single(cdev, chain);
    88			break;
    89		case QED_CHAIN_MODE_PBL:
    90			qed_chain_free_pbl(cdev, chain);
    91			break;
    92		default:
    93			break;
    94		}
    95	}
    96	
    97	static int
    98	qed_chain_alloc_sanity_check(struct qed_dev *cdev,
    99				     enum qed_chain_cnt_type cnt_type,
   100				     size_t elem_size, u32 page_cnt)
   101	{
   102		u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
   103	
   104		/* The actual chain size can be larger than the maximal possible value
   105		 * after rounding up the requested elements number to pages, and after
   106		 * taking into account the unusuable elements (next-ptr elements).
   107		 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
   108		 * size/capacity fields are of u32 type.
   109		 */
   110		switch (cnt_type) {
   111		case QED_CHAIN_CNT_TYPE_U16:
   112			if (chain_size > U16_MAX + 1)
   113				break;
   114	
   115			return 0;
   116		case QED_CHAIN_CNT_TYPE_U32:
   117			if (chain_size > U32_MAX)
   118				break;
   119	
   120			return 0;
   121		default:
   122			return -EINVAL;
   123		}
   124	
   125		DP_NOTICE(cdev,
   126			  "The actual chain size (0x%llx) is larger than the maximal possible value\n",
   127			  chain_size);
   128	
   129		return -EINVAL;
   130	}
   131	
   132	static int qed_chain_alloc_next_ptr(struct qed_dev *cdev,
   133					    struct qed_chain *chain)
   134	{
   135		struct device *dev = &cdev->pdev->dev;
   136		void *virt, *virt_prev = NULL;
   137		dma_addr_t phys;
   138		u32 i;
   139	
   140		for (i = 0; i < chain->page_cnt; i++) {
   141			virt = dma_alloc_coherent(dev, QED_CHAIN_PAGE_SIZE, &phys,
   142						  GFP_KERNEL);
   143			if (!virt)
   144				return -ENOMEM;
   145	
   146			if (i == 0) {
   147				qed_chain_init_mem(chain, virt, phys);
   148				qed_chain_reset(chain);
   149			} else {
   150				qed_chain_init_next_ptr_elem(chain, virt_prev, virt,
   151							     phys);
   152			}
   153	
   154			virt_prev = virt;
   155		}
   156	
   157		/* Last page's next element should point to the beginning of the
   158		 * chain.
   159		 */
   160		qed_chain_init_next_ptr_elem(chain, virt_prev, chain->p_virt_addr,
   161					     chain->p_phys_addr);
   162	
   163		return 0;
   164	}
   165	
   166	static int qed_chain_alloc_single(struct qed_dev *cdev,
   167					  struct qed_chain *chain)
   168	{
   169		dma_addr_t phys;
   170		void *virt;
   171	
   172		virt = dma_alloc_coherent(&cdev->pdev->dev, QED_CHAIN_PAGE_SIZE,
   173					  &phys, GFP_KERNEL);
   174		if (!virt)
   175			return -ENOMEM;
   176	
   177		qed_chain_init_mem(chain, virt, phys);
   178		qed_chain_reset(chain);
   179	
   180		return 0;
   181	}
   182	
   183	static int qed_chain_alloc_pbl(struct qed_dev *cdev, struct qed_chain *chain,
   184				       struct qed_chain_ext_pbl *ext_pbl)
   185	{
   186		struct device *dev = &cdev->pdev->dev;
   187		struct addr_tbl_entry *addr_tbl;
   188		dma_addr_t phys, pbl_phys;
   189		void *pbl_virt;
   190		u32 page_cnt, i;
   191		size_t size;
   192		void *virt;
   193	
   194		page_cnt = chain->page_cnt;
   195	
   196		size = array_size(page_cnt, sizeof(*addr_tbl));
   197		if (unlikely(size == SIZE_MAX))
   198			return -EOVERFLOW;
   199	
 > 200		addr_tbl = vzalloc(size);
   201		if (!addr_tbl)
   202			return -ENOMEM;
   203	
   204		chain->pbl.pp_addr_tbl = addr_tbl;
   205	
   206		if (ext_pbl) {
   207			size = 0;
   208			pbl_virt = ext_pbl->p_pbl_virt;
   209			pbl_phys = ext_pbl->p_pbl_phys;
   210	
   211			chain->b_external_pbl = true;
   212		} else {
   213			size = array_size(page_cnt, QED_CHAIN_PBL_ENTRY_SIZE);
   214			if (unlikely(size == SIZE_MAX))
   215				return -EOVERFLOW;
   216	
   217			pbl_virt = dma_alloc_coherent(dev, size, &pbl_phys,
   218						      GFP_KERNEL);
   219		}
   220	
   221		if (!pbl_virt)
   222			return -ENOMEM;
   223	
   224		chain->pbl_sp.p_virt_table = pbl_virt;
   225		chain->pbl_sp.p_phys_table = pbl_phys;
   226	
   227		for (i = 0; i < page_cnt; i++) {
   228			virt = dma_alloc_coherent(dev, QED_CHAIN_PAGE_SIZE, &phys,
   229						  GFP_KERNEL);
   230			if (!virt)
   231				return -ENOMEM;
   232	
   233			if (i == 0) {
   234				qed_chain_init_mem(chain, virt, phys);
   235				qed_chain_reset(chain);
   236			}
   237	
   238			/* Fill the PBL table with the physical address of the page */
   239			*(dma_addr_t *)pbl_virt = phys;
   240			pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
   241	
   242			/* Keep the virtual address of the page */
   243			addr_tbl[i].virt_addr = virt;
   244			addr_tbl[i].dma_map = phys;
   245		}
   246	
   247		return 0;
   248	}
   249	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Alexander Lobakin July 22, 2020, 9:52 p.m. UTC | #2
Kbuild test robot triggered a build error on Alpha, sorry. Will send
v2 soon.

Al
diff mbox series

Patch

diff --git a/drivers/net/ethernet/qlogic/qed/Makefile b/drivers/net/ethernet/qlogic/qed/Makefile
index 3c75e4fa9b02..f947b105cf14 100644
--- a/drivers/net/ethernet/qlogic/qed/Makefile
+++ b/drivers/net/ethernet/qlogic/qed/Makefile
@@ -4,6 +4,7 @@ 
 obj-$(CONFIG_QED) := qed.o
 
 qed-y :=			\
+	qed_chain.o		\
 	qed_cxt.o		\
 	qed_dcbx.o		\
 	qed_debug.o		\
diff --git a/drivers/net/ethernet/qlogic/qed/qed_chain.c b/drivers/net/ethernet/qlogic/qed/qed_chain.c
new file mode 100644
index 000000000000..40cc26f7f20b
--- /dev/null
+++ b/drivers/net/ethernet/qlogic/qed/qed_chain.c
@@ -0,0 +1,300 @@ 
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
+/* Copyright (c) 2020 Marvell International Ltd. */
+
+#include <linux/qed/qed_chain.h>
+
+#include "qed_dev_api.h"
+
+static void qed_chain_free_next_ptr(struct qed_dev *cdev,
+				    struct qed_chain *chain)
+{
+	struct device *dev = &cdev->pdev->dev;
+	struct qed_chain_next *next;
+	dma_addr_t phys, phys_next;
+	void *virt, *virt_next;
+	u32 size, i;
+
+	size = chain->elem_size * chain->usable_per_page;
+	virt = chain->p_virt_addr;
+	phys = chain->p_phys_addr;
+
+	for (i = 0; i < chain->page_cnt; i++) {
+		if (!virt)
+			break;
+
+		next = virt + size;
+		virt_next = next->next_virt;
+		phys_next = HILO_DMA_REGPAIR(next->next_phys);
+
+		dma_free_coherent(dev, QED_CHAIN_PAGE_SIZE, virt, phys);
+
+		virt = virt_next;
+		phys = phys_next;
+	}
+}
+
+static void qed_chain_free_single(struct qed_dev *cdev,
+				  struct qed_chain *chain)
+{
+	if (!chain->p_virt_addr)
+		return;
+
+	dma_free_coherent(&cdev->pdev->dev, QED_CHAIN_PAGE_SIZE,
+			  chain->p_virt_addr, chain->p_phys_addr);
+}
+
+static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *chain)
+{
+	struct device *dev = &cdev->pdev->dev;
+	struct addr_tbl_entry *entry;
+	u32 pbl_size, i;
+
+	if (!chain->pbl.pp_addr_tbl)
+		return;
+
+	for (i = 0; i < chain->page_cnt; i++) {
+		entry = chain->pbl.pp_addr_tbl + i;
+		if (!entry->virt_addr)
+			break;
+
+		dma_free_coherent(dev, QED_CHAIN_PAGE_SIZE, entry->virt_addr,
+				  entry->dma_map);
+	}
+
+	pbl_size = chain->page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
+
+	if (!chain->b_external_pbl)
+		dma_free_coherent(dev, pbl_size, chain->pbl_sp.p_virt_table,
+				  chain->pbl_sp.p_phys_table);
+
+	vfree(chain->pbl.pp_addr_tbl);
+	chain->pbl.pp_addr_tbl = NULL;
+}
+
+/**
+ * qed_chain_free() - Free chain DMA memory.
+ *
+ * @cdev: Main device structure.
+ * @chain: Chain to free.
+ */
+void qed_chain_free(struct qed_dev *cdev, struct qed_chain *chain)
+{
+	switch (chain->mode) {
+	case QED_CHAIN_MODE_NEXT_PTR:
+		qed_chain_free_next_ptr(cdev, chain);
+		break;
+	case QED_CHAIN_MODE_SINGLE:
+		qed_chain_free_single(cdev, chain);
+		break;
+	case QED_CHAIN_MODE_PBL:
+		qed_chain_free_pbl(cdev, chain);
+		break;
+	default:
+		break;
+	}
+}
+
+static int
+qed_chain_alloc_sanity_check(struct qed_dev *cdev,
+			     enum qed_chain_cnt_type cnt_type,
+			     size_t elem_size, u32 page_cnt)
+{
+	u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
+
+	/* The actual chain size can be larger than the maximal possible value
+	 * after rounding up the requested elements number to pages, and after
+	 * taking into account the unusuable elements (next-ptr elements).
+	 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
+	 * size/capacity fields are of u32 type.
+	 */
+	switch (cnt_type) {
+	case QED_CHAIN_CNT_TYPE_U16:
+		if (chain_size > U16_MAX + 1)
+			break;
+
+		return 0;
+	case QED_CHAIN_CNT_TYPE_U32:
+		if (chain_size > U32_MAX)
+			break;
+
+		return 0;
+	default:
+		return -EINVAL;
+	}
+
+	DP_NOTICE(cdev,
+		  "The actual chain size (0x%llx) is larger than the maximal possible value\n",
+		  chain_size);
+
+	return -EINVAL;
+}
+
+static int qed_chain_alloc_next_ptr(struct qed_dev *cdev,
+				    struct qed_chain *chain)
+{
+	struct device *dev = &cdev->pdev->dev;
+	void *virt, *virt_prev = NULL;
+	dma_addr_t phys;
+	u32 i;
+
+	for (i = 0; i < chain->page_cnt; i++) {
+		virt = dma_alloc_coherent(dev, QED_CHAIN_PAGE_SIZE, &phys,
+					  GFP_KERNEL);
+		if (!virt)
+			return -ENOMEM;
+
+		if (i == 0) {
+			qed_chain_init_mem(chain, virt, phys);
+			qed_chain_reset(chain);
+		} else {
+			qed_chain_init_next_ptr_elem(chain, virt_prev, virt,
+						     phys);
+		}
+
+		virt_prev = virt;
+	}
+
+	/* Last page's next element should point to the beginning of the
+	 * chain.
+	 */
+	qed_chain_init_next_ptr_elem(chain, virt_prev, chain->p_virt_addr,
+				     chain->p_phys_addr);
+
+	return 0;
+}
+
+static int qed_chain_alloc_single(struct qed_dev *cdev,
+				  struct qed_chain *chain)
+{
+	dma_addr_t phys;
+	void *virt;
+
+	virt = dma_alloc_coherent(&cdev->pdev->dev, QED_CHAIN_PAGE_SIZE,
+				  &phys, GFP_KERNEL);
+	if (!virt)
+		return -ENOMEM;
+
+	qed_chain_init_mem(chain, virt, phys);
+	qed_chain_reset(chain);
+
+	return 0;
+}
+
+static int qed_chain_alloc_pbl(struct qed_dev *cdev, struct qed_chain *chain,
+			       struct qed_chain_ext_pbl *ext_pbl)
+{
+	struct device *dev = &cdev->pdev->dev;
+	struct addr_tbl_entry *addr_tbl;
+	dma_addr_t phys, pbl_phys;
+	void *pbl_virt;
+	u32 page_cnt, i;
+	size_t size;
+	void *virt;
+
+	page_cnt = chain->page_cnt;
+
+	size = array_size(page_cnt, sizeof(*addr_tbl));
+	if (unlikely(size == SIZE_MAX))
+		return -EOVERFLOW;
+
+	addr_tbl = vzalloc(size);
+	if (!addr_tbl)
+		return -ENOMEM;
+
+	chain->pbl.pp_addr_tbl = addr_tbl;
+
+	if (ext_pbl) {
+		size = 0;
+		pbl_virt = ext_pbl->p_pbl_virt;
+		pbl_phys = ext_pbl->p_pbl_phys;
+
+		chain->b_external_pbl = true;
+	} else {
+		size = array_size(page_cnt, QED_CHAIN_PBL_ENTRY_SIZE);
+		if (unlikely(size == SIZE_MAX))
+			return -EOVERFLOW;
+
+		pbl_virt = dma_alloc_coherent(dev, size, &pbl_phys,
+					      GFP_KERNEL);
+	}
+
+	if (!pbl_virt)
+		return -ENOMEM;
+
+	chain->pbl_sp.p_virt_table = pbl_virt;
+	chain->pbl_sp.p_phys_table = pbl_phys;
+
+	for (i = 0; i < page_cnt; i++) {
+		virt = dma_alloc_coherent(dev, QED_CHAIN_PAGE_SIZE, &phys,
+					  GFP_KERNEL);
+		if (!virt)
+			return -ENOMEM;
+
+		if (i == 0) {
+			qed_chain_init_mem(chain, virt, phys);
+			qed_chain_reset(chain);
+		}
+
+		/* Fill the PBL table with the physical address of the page */
+		*(dma_addr_t *)pbl_virt = phys;
+		pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
+
+		/* Keep the virtual address of the page */
+		addr_tbl[i].virt_addr = virt;
+		addr_tbl[i].dma_map = phys;
+	}
+
+	return 0;
+}
+
+int qed_chain_alloc(struct qed_dev *cdev,
+		    enum qed_chain_use_mode intended_use,
+		    enum qed_chain_mode mode,
+		    enum qed_chain_cnt_type cnt_type,
+		    u32 num_elems,
+		    size_t elem_size,
+		    struct qed_chain *chain,
+		    struct qed_chain_ext_pbl *ext_pbl)
+{
+	u32 page_cnt;
+	int rc;
+
+	if (mode == QED_CHAIN_MODE_SINGLE)
+		page_cnt = 1;
+	else
+		page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
+
+	rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt);
+	if (rc) {
+		DP_NOTICE(cdev,
+			  "Cannot allocate a chain with the given arguments:\n");
+		DP_NOTICE(cdev,
+			  "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
+			  intended_use, mode, cnt_type, num_elems, elem_size);
+		return rc;
+	}
+
+	qed_chain_init_params(chain, page_cnt, elem_size, intended_use, mode,
+			      cnt_type);
+
+	switch (mode) {
+	case QED_CHAIN_MODE_NEXT_PTR:
+		rc = qed_chain_alloc_next_ptr(cdev, chain);
+		break;
+	case QED_CHAIN_MODE_SINGLE:
+		rc = qed_chain_alloc_single(cdev, chain);
+		break;
+	case QED_CHAIN_MODE_PBL:
+		rc = qed_chain_alloc_pbl(cdev, chain, ext_pbl);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (!rc)
+		return 0;
+
+	qed_chain_free(cdev, chain);
+
+	return rc;
+}
diff --git a/drivers/net/ethernet/qlogic/qed/qed_dev.c b/drivers/net/ethernet/qlogic/qed/qed_dev.c
index 6516a1f921da..d9c7a1a6be94 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dev.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dev.c
@@ -4716,279 +4716,6 @@  void qed_hw_remove(struct qed_dev *cdev)
 	qed_mcp_nvm_info_free(p_hwfn);
 }
 
-static void qed_chain_free_next_ptr(struct qed_dev *cdev,
-				    struct qed_chain *p_chain)
-{
-	void *p_virt = p_chain->p_virt_addr, *p_virt_next = NULL;
-	dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
-	struct qed_chain_next *p_next;
-	u32 size, i;
-
-	if (!p_virt)
-		return;
-
-	size = p_chain->elem_size * p_chain->usable_per_page;
-
-	for (i = 0; i < p_chain->page_cnt; i++) {
-		if (!p_virt)
-			break;
-
-		p_next = (struct qed_chain_next *)((u8 *)p_virt + size);
-		p_virt_next = p_next->next_virt;
-		p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
-
-		dma_free_coherent(&cdev->pdev->dev,
-				  QED_CHAIN_PAGE_SIZE, p_virt, p_phys);
-
-		p_virt = p_virt_next;
-		p_phys = p_phys_next;
-	}
-}
-
-static void qed_chain_free_single(struct qed_dev *cdev,
-				  struct qed_chain *p_chain)
-{
-	if (!p_chain->p_virt_addr)
-		return;
-
-	dma_free_coherent(&cdev->pdev->dev,
-			  QED_CHAIN_PAGE_SIZE,
-			  p_chain->p_virt_addr, p_chain->p_phys_addr);
-}
-
-static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
-{
-	struct addr_tbl_entry *pp_addr_tbl = p_chain->pbl.pp_addr_tbl;
-	u32 page_cnt = p_chain->page_cnt, i, pbl_size;
-
-	if (!pp_addr_tbl)
-		return;
-
-	for (i = 0; i < page_cnt; i++) {
-		if (!pp_addr_tbl[i].virt_addr || !pp_addr_tbl[i].dma_map)
-			break;
-
-		dma_free_coherent(&cdev->pdev->dev,
-				  QED_CHAIN_PAGE_SIZE,
-				  pp_addr_tbl[i].virt_addr,
-				  pp_addr_tbl[i].dma_map);
-	}
-
-	pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
-
-	if (!p_chain->b_external_pbl)
-		dma_free_coherent(&cdev->pdev->dev,
-				  pbl_size,
-				  p_chain->pbl_sp.p_virt_table,
-				  p_chain->pbl_sp.p_phys_table);
-
-	vfree(p_chain->pbl.pp_addr_tbl);
-	p_chain->pbl.pp_addr_tbl = NULL;
-}
-
-void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain)
-{
-	switch (p_chain->mode) {
-	case QED_CHAIN_MODE_NEXT_PTR:
-		qed_chain_free_next_ptr(cdev, p_chain);
-		break;
-	case QED_CHAIN_MODE_SINGLE:
-		qed_chain_free_single(cdev, p_chain);
-		break;
-	case QED_CHAIN_MODE_PBL:
-		qed_chain_free_pbl(cdev, p_chain);
-		break;
-	}
-}
-
-static int
-qed_chain_alloc_sanity_check(struct qed_dev *cdev,
-			     enum qed_chain_cnt_type cnt_type,
-			     size_t elem_size, u32 page_cnt)
-{
-	u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
-
-	/* The actual chain size can be larger than the maximal possible value
-	 * after rounding up the requested elements number to pages, and after
-	 * taking into acount the unusuable elements (next-ptr elements).
-	 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
-	 * size/capacity fields are of a u32 type.
-	 */
-	if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 &&
-	     chain_size > ((u32)U16_MAX + 1)) ||
-	    (cnt_type == QED_CHAIN_CNT_TYPE_U32 && chain_size > U32_MAX)) {
-		DP_NOTICE(cdev,
-			  "The actual chain size (0x%llx) is larger than the maximal possible value\n",
-			  chain_size);
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
-static int
-qed_chain_alloc_next_ptr(struct qed_dev *cdev, struct qed_chain *p_chain)
-{
-	void *p_virt = NULL, *p_virt_prev = NULL;
-	dma_addr_t p_phys = 0;
-	u32 i;
-
-	for (i = 0; i < p_chain->page_cnt; i++) {
-		p_virt = dma_alloc_coherent(&cdev->pdev->dev,
-					    QED_CHAIN_PAGE_SIZE,
-					    &p_phys, GFP_KERNEL);
-		if (!p_virt)
-			return -ENOMEM;
-
-		if (i == 0) {
-			qed_chain_init_mem(p_chain, p_virt, p_phys);
-			qed_chain_reset(p_chain);
-		} else {
-			qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
-						     p_virt, p_phys);
-		}
-
-		p_virt_prev = p_virt;
-	}
-	/* Last page's next element should point to the beginning of the
-	 * chain.
-	 */
-	qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
-				     p_chain->p_virt_addr,
-				     p_chain->p_phys_addr);
-
-	return 0;
-}
-
-static int
-qed_chain_alloc_single(struct qed_dev *cdev, struct qed_chain *p_chain)
-{
-	dma_addr_t p_phys = 0;
-	void *p_virt = NULL;
-
-	p_virt = dma_alloc_coherent(&cdev->pdev->dev,
-				    QED_CHAIN_PAGE_SIZE, &p_phys, GFP_KERNEL);
-	if (!p_virt)
-		return -ENOMEM;
-
-	qed_chain_init_mem(p_chain, p_virt, p_phys);
-	qed_chain_reset(p_chain);
-
-	return 0;
-}
-
-static int
-qed_chain_alloc_pbl(struct qed_dev *cdev,
-		    struct qed_chain *p_chain,
-		    struct qed_chain_ext_pbl *ext_pbl)
-{
-	u32 page_cnt = p_chain->page_cnt, size, i;
-	dma_addr_t p_phys = 0, p_pbl_phys = 0;
-	struct addr_tbl_entry *pp_addr_tbl;
-	u8 *p_pbl_virt = NULL;
-	void *p_virt = NULL;
-
-	size = page_cnt * sizeof(*pp_addr_tbl);
-	pp_addr_tbl =  vzalloc(size);
-	if (!pp_addr_tbl)
-		return -ENOMEM;
-
-	/* The allocation of the PBL table is done with its full size, since it
-	 * is expected to be successive.
-	 * qed_chain_init_pbl_mem() is called even in a case of an allocation
-	 * failure, since tbl was previously allocated, and it
-	 * should be saved to allow its freeing during the error flow.
-	 */
-	size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
-
-	if (!ext_pbl) {
-		p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
-						size, &p_pbl_phys, GFP_KERNEL);
-	} else {
-		p_pbl_virt = ext_pbl->p_pbl_virt;
-		p_pbl_phys = ext_pbl->p_pbl_phys;
-		p_chain->b_external_pbl = true;
-	}
-
-	qed_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys, pp_addr_tbl);
-	if (!p_pbl_virt)
-		return -ENOMEM;
-
-	for (i = 0; i < page_cnt; i++) {
-		p_virt = dma_alloc_coherent(&cdev->pdev->dev,
-					    QED_CHAIN_PAGE_SIZE,
-					    &p_phys, GFP_KERNEL);
-		if (!p_virt)
-			return -ENOMEM;
-
-		if (i == 0) {
-			qed_chain_init_mem(p_chain, p_virt, p_phys);
-			qed_chain_reset(p_chain);
-		}
-
-		/* Fill the PBL table with the physical address of the page */
-		*(dma_addr_t *)p_pbl_virt = p_phys;
-		/* Keep the virtual address of the page */
-		p_chain->pbl.pp_addr_tbl[i].virt_addr = p_virt;
-		p_chain->pbl.pp_addr_tbl[i].dma_map = p_phys;
-
-		p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
-	}
-
-	return 0;
-}
-
-int qed_chain_alloc(struct qed_dev *cdev,
-		    enum qed_chain_use_mode intended_use,
-		    enum qed_chain_mode mode,
-		    enum qed_chain_cnt_type cnt_type,
-		    u32 num_elems,
-		    size_t elem_size,
-		    struct qed_chain *p_chain,
-		    struct qed_chain_ext_pbl *ext_pbl)
-{
-	u32 page_cnt;
-	int rc = 0;
-
-	if (mode == QED_CHAIN_MODE_SINGLE)
-		page_cnt = 1;
-	else
-		page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
-
-	rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt);
-	if (rc) {
-		DP_NOTICE(cdev,
-			  "Cannot allocate a chain with the given arguments:\n");
-		DP_NOTICE(cdev,
-			  "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
-			  intended_use, mode, cnt_type, num_elems, elem_size);
-		return rc;
-	}
-
-	qed_chain_init_params(p_chain, page_cnt, (u8) elem_size, intended_use,
-			      mode, cnt_type);
-
-	switch (mode) {
-	case QED_CHAIN_MODE_NEXT_PTR:
-		rc = qed_chain_alloc_next_ptr(cdev, p_chain);
-		break;
-	case QED_CHAIN_MODE_SINGLE:
-		rc = qed_chain_alloc_single(cdev, p_chain);
-		break;
-	case QED_CHAIN_MODE_PBL:
-		rc = qed_chain_alloc_pbl(cdev, p_chain, ext_pbl);
-		break;
-	}
-	if (rc)
-		goto nomem;
-
-	return 0;
-
-nomem:
-	qed_chain_free(cdev, p_chain);
-	return rc;
-}
-
 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, u16 src_id, u16 *dst_id)
 {
 	if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {