Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 27922b4260f65d317aabda37e42bbbff > files > 349

kernel-2.6.18-238.el5.src.rpm

From: Tomas Henzl <thenzl@redhat.com>
Date: Sun, 29 Aug 2010 15:49:42 -0400
Subject: [block] cciss: simplify scatter gather code
Message-id: <1283097002-3341-44-git-send-email-thenzl@redhat.com>
Patchwork-id: 27907
O-Subject: [RHEL6 PATCH 43/63] cciss: simplify scatter gather code
Bugzilla: 568830
RH-Acked-by: Neil Horman <nhorman@redhat.com>

Instead of allocating an array of pointers to a structure
containing an SGDescriptor structure, and two other elements
that aren't really used, just allocate SGDescriptor structs.

diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 669cac5..7016974 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -247,7 +247,7 @@ static void log_unit_to_scsi3addr(ctlr_info_t *h, unsigned char scsi3addr[],
 		sizeof(h->drv[log_unit]->LunID));
 }
 
-static void cciss_free_sg_chain_blocks(struct Cmd_sg_list **cmd_sg_list,
+static void cciss_free_sg_chain_blocks(SGDescriptor_struct **cmd_sg_list,
 	int nr_cmds)
 {
 	int i;
@@ -255,20 +255,17 @@ static void cciss_free_sg_chain_blocks(struct Cmd_sg_list **cmd_sg_list,
 	if (!cmd_sg_list)
 		return;
 	for (i = 0; i < nr_cmds; i++) {
-		if (cmd_sg_list[i]) {
-			kfree(cmd_sg_list[i]->sgchain);
-			kfree(cmd_sg_list[i]);
-			cmd_sg_list[i] = NULL;
-		}
+		kfree(cmd_sg_list[i]);
+		cmd_sg_list[i] = NULL;
 	}
 	kfree(cmd_sg_list);
 }
 
-static struct Cmd_sg_list **cciss_allocate_sg_chain_blocks(ctlr_info_t *h,
-	int chainsize, int nr_cmds)
+static SGDescriptor_struct **cciss_allocate_sg_chain_blocks(
+	ctlr_info_t *h, int chainsize, int nr_cmds)
 {
 	int j;
-	struct Cmd_sg_list **cmd_sg_list;
+	SGDescriptor_struct **cmd_sg_list;
 
 	if (chainsize <= 0)
 		return NULL;
@@ -279,16 +276,10 @@ static struct Cmd_sg_list **cciss_allocate_sg_chain_blocks(ctlr_info_t *h,
 
 	/* Build up chain blocks for each command */
 	for (j = 0; j < nr_cmds; j++) {
-		cmd_sg_list[j] = kmalloc(sizeof(*cmd_sg_list[j]), GFP_KERNEL);
-		if (!cmd_sg_list[j]) {
-			dev_err(&h->pdev->dev, "Cannot get memory "
-				"for chain block.\n");
-			goto clean;
-		}
 		/* Need a block of chainsized s/g elements. */
-		cmd_sg_list[j]->sgchain = kmalloc((chainsize *
-			sizeof(SGDescriptor_struct)), GFP_KERNEL);
-		if (!cmd_sg_list[j]->sgchain) {
+		cmd_sg_list[j] = kmalloc((chainsize *
+			sizeof(*cmd_sg_list[j])), GFP_KERNEL);
+		if (!cmd_sg_list[j]) {
 			dev_err(&h->pdev->dev, "Cannot get memory "
 				"for s/g chains.\n");
 			goto clean;
@@ -1789,7 +1780,7 @@ static void cciss_softirq_done(struct request *rq)
 			pci_unmap_single(h->pdev, temp64.val,
 						cmd->SG[i].Len, ddir);
 			/* Point to the next block */
-			curr_sg = h->cmd_sg_list[cmd->cmdindex]->sgchain;
+			curr_sg = h->cmd_sg_list[cmd->cmdindex];
 			sg_index = 0;
 		}
 		temp64.val32.lower = curr_sg[sg_index].Addr.lower;
@@ -3265,7 +3256,7 @@ static void do_cciss_request(request_queue_t *q)
 			curr_sg[sg_index].Ext = CCISS_SG_CHAIN;
 
 			/* Point to next chain block. */
-			curr_sg = h->cmd_sg_list[c->cmdindex]->sgchain;
+			curr_sg = h->cmd_sg_list[c->cmdindex];
 			sg_index = 0;
 			chained = 1;
 		}
@@ -3282,6 +3273,7 @@ static void do_cciss_request(request_queue_t *q)
 
 	if (chained) {
 		int len;
+		dma_addr_t dma_addr;
 		curr_sg = c->SG;
 		sg_index = h->max_cmd_sgentries - 1;
 		len = curr_sg[sg_index].Len;
@@ -3290,16 +3282,11 @@ static void do_cciss_request(request_queue_t *q)
 		 * block with address of next chain block.
 		 */
 		temp64.val = pci_map_single(h->pdev,
-					h->cmd_sg_list[c->cmdindex]->sgchain,
-					len, dir);
-
-		h->cmd_sg_list[c->cmdindex]->sg_chain_dma = temp64.val;
+					h->cmd_sg_list[c->cmdindex], len, dir);
+		dma_addr = temp64.val;
 		curr_sg[sg_index].Addr.lower = temp64.val32.lower;
 		curr_sg[sg_index].Addr.upper = temp64.val32.upper;
-
-		pci_dma_sync_single_for_device(h->pdev,
-				h->cmd_sg_list[c->cmdindex]->sg_chain_dma,
-				len, dir);
+		pci_dma_sync_single_for_device(h->pdev, dma_addr, len, dir);
 	}
 
 	/* track how many SG entries we are using */
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index 8899249..9018b50 100644
--- a/drivers/block/cciss.h
+++ b/drivers/block/cciss.h
@@ -56,12 +56,6 @@ typedef struct _drive_info_struct
 	char device_initialized;     /* indicates whether dev is initialized */
 } drive_info_struct;
 
-struct Cmd_sg_list {
-	SGDescriptor_struct	*sgchain;
-	dma_addr_t		sg_chain_dma;
-	int			chain_block_size;
-};
-
 struct ctlr_info 
 {
 	int	ctlr;
@@ -90,7 +84,7 @@ struct ctlr_info
 	int	maxsgentries;
 	int	chainsize;
 	int	max_cmd_sgentries;
-	struct Cmd_sg_list **cmd_sg_list;
+	SGDescriptor_struct **cmd_sg_list;
 
 #	define DOORBELL_INT	0
 #	define PERF_MODE_INT	1