[openib-general] [PATCH] mthca: cosmetic replace 4096 with MTHCA_ICM_PAGE_SIZE

Michael S. Tsirkin mst at mellanox.co.il
Mon Jan 16 06:05:56 PST 2006


The following looks to me like a good idea.
Roland?

---

Use a constant for the size of icm page in arbel.

Signed-off-by: Ishai Rabinovitz <ishai at mellanox.co.il>
Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>

Index: last_stable/drivers/infiniband/hw/mthca/mthca_cmd.c
===================================================================
--- last_stable.orig/drivers/infiniband/hw/mthca/mthca_cmd.c	2006-01-12 15:37:02.000000000 +0200
+++ last_stable/drivers/infiniband/hw/mthca/mthca_cmd.c	2006-01-12 16:52:41.000000000 +0200
@@ -599,8 +599,9 @@ static int mthca_map_cmd(struct mthca_de
 		 * address or size and use that as our log2 size.
 		 */
 		lg = ffs(mthca_icm_addr(&iter) | mthca_icm_size(&iter)) - 1;
-		if (lg < 12) {
-			mthca_warn(dev, "Got FW area not aligned to 4K (%llx/%lx).\n",
+		if (lg < MTHCA_ICM_PAGE_SHIFT) {
+			mthca_warn(dev, "Got FW area not aligned to %d (%llx/%lx).\n",
+				   MTHCA_ICM_PAGE_SIZE,
 				   (unsigned long long) mthca_icm_addr(&iter),
 				   mthca_icm_size(&iter));
 			err = -EINVAL;
@@ -612,8 +613,9 @@ static int mthca_map_cmd(struct mthca_de
 				virt += 1 << lg;
 			}
 
-			pages[nent * 2 + 1] = cpu_to_be64((mthca_icm_addr(&iter) +
-							   (i << lg)) | (lg - 12));
+			pages[nent * 2 + 1] = 
+				cpu_to_be64((mthca_icm_addr(&iter) + (i << lg)) |
+				 	    (lg - MTHCA_ICM_PAGE_SHIFT));
 			ts += 1 << (lg - 10);
 			++tc;
 
Index: last_stable/drivers/infiniband/hw/mthca/mthca_memfree.c
===================================================================
--- last_stable.orig/drivers/infiniband/hw/mthca/mthca_memfree.c	2006-01-12 15:33:08.000000000 +0200
+++ last_stable/drivers/infiniband/hw/mthca/mthca_memfree.c	2006-01-12 15:41:45.000000000 +0200
@@ -202,7 +202,7 @@ void mthca_table_put(struct mthca_dev *d
 
 	if (--table->icm[i]->refcount == 0) {
 		mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE,
-				MTHCA_TABLE_CHUNK_SIZE >> 12, &status);
+				MTHCA_TABLE_CHUNK_SIZE >> MTHCA_ICM_PAGE_SHIFT, &status);
 		mthca_free_icm(dev, table->icm[i]);
 		table->icm[i] = NULL;
 	}
@@ -336,7 +336,8 @@ err:
 	for (i = 0; i < num_icm; ++i)
 		if (table->icm[i]) {
 			mthca_UNMAP_ICM(dev, virt + i * MTHCA_TABLE_CHUNK_SIZE,
-					MTHCA_TABLE_CHUNK_SIZE >> 12, &status);
+					MTHCA_TABLE_CHUNK_SIZE >> MTHCA_ICM_PAGE_SHIFT,
+				        &status);
 			mthca_free_icm(dev, table->icm[i]);
 		}
 
@@ -353,7 +354,7 @@ void mthca_free_icm_table(struct mthca_d
 	for (i = 0; i < table->num_icm; ++i)
 		if (table->icm[i]) {
 			mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE,
-					MTHCA_TABLE_CHUNK_SIZE >> 12, &status);
+					MTHCA_TABLE_CHUNK_SIZE >> MTHCA_ICM_PAGE_SHIFT, &status);
 			mthca_free_icm(dev, table->icm[i]);
 		}
 
@@ -364,7 +365,7 @@ static u64 mthca_uarc_virt(struct mthca_
 {
 	return dev->uar_table.uarc_base +
 		uar->index * dev->uar_table.uarc_size +
-		page * 4096;
+		page << MTHCA_ICM_PAGE_SHIFT;
 }
 
 int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
@@ -401,7 +402,7 @@ int mthca_map_user_db(struct mthca_dev *
 	if (ret < 0)
 		goto out;
 
-	db_tab->page[i].mem.length = 4096;
+	db_tab->page[i].mem.length = MTHCA_ICM_PAGE_SIZE;
 	db_tab->page[i].mem.offset = uaddr & ~PAGE_MASK;
 
 	ret = pci_map_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
@@ -455,7 +456,7 @@ struct mthca_user_db_table *mthca_init_u
 	if (!mthca_is_memfree(dev))
 		return NULL;
 
-	npages = dev->uar_table.uarc_size / 4096;
+	npages = dev->uar_table.uarc_size >> MTHCA_ICM_PAGE_SHIFT;
 	db_tab = kmalloc(sizeof *db_tab + npages * sizeof *db_tab->page, GFP_KERNEL);
 	if (!db_tab)
 		return ERR_PTR(-ENOMEM);
@@ -478,7 +479,7 @@ void mthca_cleanup_user_db_tab(struct mt
 	if (!mthca_is_memfree(dev))
 		return;
 
-	for (i = 0; i < dev->uar_table.uarc_size / 4096; ++i) {
+	for (i = 0; i < dev->uar_table.uarc_size >> MTHCA_ICM_PAGE_SHIFT; ++i) {
 		if (db_tab->page[i].uvirt) {
 			mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, uar, i), 1, &status);
 			pci_unmap_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
@@ -551,20 +552,20 @@ int mthca_alloc_db(struct mthca_dev *dev
 	page = dev->db_tab->page + end;
 
 alloc:
-	page->db_rec = dma_alloc_coherent(&dev->pdev->dev, 4096,
+	page->db_rec = dma_alloc_coherent(&dev->pdev->dev, MTHCA_ICM_PAGE_SIZE,
 					  &page->mapping, GFP_KERNEL);
 	if (!page->db_rec) {
 		ret = -ENOMEM;
 		goto out;
 	}
-	memset(page->db_rec, 0, 4096);
+	memset(page->db_rec, 0, MTHCA_ICM_PAGE_SIZE);
 
 	ret = mthca_MAP_ICM_page(dev, page->mapping,
 				 mthca_uarc_virt(dev, &dev->driver_uar, i), &status);
 	if (!ret && status)
 		ret = -EINVAL;
 	if (ret) {
-		dma_free_coherent(&dev->pdev->dev, 4096,
+		dma_free_coherent(&dev->pdev->dev, MTHCA_ICM_PAGE_SIZE,
 				  page->db_rec, page->mapping);
 		goto out;
 	}
@@ -612,7 +613,7 @@ void mthca_free_db(struct mthca_dev *dev
 	    i >= dev->db_tab->max_group1 - 1) {
 		mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, &dev->driver_uar, i), 1, &status);
 
-		dma_free_coherent(&dev->pdev->dev, 4096,
+		dma_free_coherent(&dev->pdev->dev, MTHCA_ICM_PAGE_SIZE,
 				  page->db_rec, page->mapping);
 		page->db_rec = NULL;
 
@@ -640,7 +641,7 @@ int mthca_init_db_tab(struct mthca_dev *
 
 	init_MUTEX(&dev->db_tab->mutex);
 
-	dev->db_tab->npages     = dev->uar_table.uarc_size / 4096;
+	dev->db_tab->npages     = dev->uar_table.uarc_size >> MTHCA_ICM_PAGE_SHIFT;
 	dev->db_tab->max_group1 = 0;
 	dev->db_tab->min_group2 = dev->db_tab->npages - 1;
 
@@ -681,7 +682,7 @@ void mthca_cleanup_db_tab(struct mthca_d
 
 		mthca_UNMAP_ICM(dev, mthca_uarc_virt(dev, &dev->driver_uar, i), 1, &status);
 
-		dma_free_coherent(&dev->pdev->dev, 4096,
+		dma_free_coherent(&dev->pdev->dev, MTHCA_ICM_PAGE_SIZE,
 				  dev->db_tab->page[i].db_rec,
 				  dev->db_tab->page[i].mapping);
 	}
Index: last_stable/drivers/infiniband/hw/mthca/mthca_memfree.h
===================================================================
--- last_stable.orig/drivers/infiniband/hw/mthca/mthca_memfree.h	2006-01-12 15:33:08.000000000 +0200
+++ last_stable/drivers/infiniband/hw/mthca/mthca_memfree.h	2006-01-12 16:49:23.000000000 +0200
@@ -54,6 +54,9 @@ typedef unsigned int gfp_t;
 	((256 - sizeof (struct list_head) - 2 * sizeof (int)) /		\
 	 (sizeof (struct scatterlist)))
 
+#define MTHCA_ICM_PAGE_SHIFT 12
+#define MTHCA_ICM_PAGE_SIZE (1 << MTHCA_ICM_PAGE_SHIFT)
+
 struct mthca_icm_chunk {
 	struct list_head   list;
 	int                npages;
@@ -141,7 +144,7 @@ static inline unsigned long mthca_icm_si
 }
 
 enum {
-	MTHCA_DB_REC_PER_PAGE = 4096 / 8
+	MTHCA_DB_REC_PER_PAGE = MTHCA_ICM_PAGE_SIZE / 8
 };
 
 struct mthca_db_page {
Index: last_stable/drivers/infiniband/hw/mthca/mthca_eq.c
===================================================================
--- last_stable.orig/drivers/infiniband/hw/mthca/mthca_eq.c	2006-01-12 15:22:45.000000000 +0200
+++ last_stable/drivers/infiniband/hw/mthca/mthca_eq.c	2006-01-12 16:55:46.000000000 +0200
@@ -40,6 +40,7 @@
 
 #include "mthca_dev.h"
 #include "mthca_cmd.h"
+#include "mthca_memfree.h"
 #include "mthca_config_reg.h"
 
 enum {
@@ -823,7 +824,8 @@ void __devexit mthca_unmap_eq_icm(struct
 {
 	u8 status;
 
-	mthca_UNMAP_ICM(dev, dev->eq_table.icm_virt, PAGE_SIZE / 4096, &status);
+	mthca_UNMAP_ICM(dev, dev->eq_table.icm_virt,
+			PAGE_SIZE >> MTHCA_ICM_PAGE_SHIFT, &status);
 	pci_unmap_page(dev->pdev, dev->eq_table.icm_dma, PAGE_SIZE,
 		       PCI_DMA_BIDIRECTIONAL);
 	__free_page(dev->eq_table.icm_page);

-- 
MST



More information about the general mailing list