linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* cciss updates for 2.6 [1 of 11]
@ 2004-02-05  0:04 mikem
  2004-02-05  4:30 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: mikem @ 2004-02-05  0:04 UTC (permalink / raw)
  To: axboe, akpm; +Cc: linux-kernel

Patch 1 of 11. Please apply in order.
This patch eliminates the bad assumption that all of our PCI BARs will
always be 32-bits. Tested against the 2.6.2 kernel.
This is required to support the Pinnacles architecture. It is already in
the 2.4 tree.
Please consider this patch for inclusion.
--------------------------------------------------------------------------------------
diff -burN lx261.orig/drivers/block/cciss.c lx261/drivers/block/cciss.c
--- lx261.orig/drivers/block/cciss.c	2004-01-09 01:00:04.000000000 -0600
+++ lx261/drivers/block/cciss.c	2004-01-21 15:55:37.000000000 -0600
@@ -2078,16 +2078,51 @@
 	c->io_mem_addr = 0;
 	c->io_mem_length = 0;
 }
+
+static int find_PCI_BAR_index(struct pci_dev *pdev,
+				unsigned long pci_bar_addr)
+{
+	int i, offset, mem_type, bar_type;
+	if (pci_bar_addr == PCI_BASE_ADDRESS_0) /* looking for BAR zero? */
+		return 0;
+	offset = 0;
+	for (i=0; i<DEVICE_COUNT_RESOURCE; i++) {
+		bar_type = pci_resource_flags(pdev, i) &
+			PCI_BASE_ADDRESS_SPACE;
+		if (bar_type == PCI_BASE_ADDRESS_SPACE_IO)
+			offset += 4;
+		else {
+			mem_type = pci_resource_flags(pdev, i) &
+				PCI_BASE_ADDRESS_MEM_TYPE_MASK;
+			switch (mem_type) {
+				case PCI_BASE_ADDRESS_MEM_TYPE_32:
+				case PCI_BASE_ADDRESS_MEM_TYPE_1M:
+					offset += 4; /* 32 bit */
+					break;
+				case PCI_BASE_ADDRESS_MEM_TYPE_64:
+					offset += 8;
+					break;
+				default: /* reserved in PCI 2.2 */
+					printk(KERN_WARNING "Base address is invalid\n");
+			       		return -1;
+				break;
+			}
+		}
+ 		if (offset == pci_bar_addr - PCI_BASE_ADDRESS_0)
+			return i+1;
+	}
+	return -1;
+}
+
 static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
 {
 	ushort vendor_id, device_id, command;
 	unchar cache_line_size, latency_timer;
 	unchar irq, revision;
-	uint addr[6];
 	__u32 board_id, scratchpad = 0;
-	int cfg_offset;
-	int cfg_base_addr;
-	int cfg_base_addr_index;
+	__u64 cfg_offset;
+	__u32 cfg_base_addr;
+	__u64 cfg_base_addr_index;
 	int i;

 	if (pci_enable_device(pdev))
@@ -2105,9 +2140,6 @@
 	device_id = pdev->device;
 	irq = pdev->irq;

-	for(i=0; i<6; i++)
-		addr[i] = pdev->resource[i].start;
-
 	(void) pci_read_config_word(pdev, PCI_COMMAND,&command);
 	(void) pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
 	(void) pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE,
@@ -2125,14 +2157,13 @@
 	}

 	/* search for our IO range so we can protect it */
-	for(i=0; i<6; i++)
+	for(i=0; i<DEVICE_COUNT_RESOURCE; i++)
 	{
 		/* is this an IO range */
-		if( pdev->resource[i].flags & 0x01 )
-		{
-			c->io_mem_addr = pdev->resource[i].start;
-			c->io_mem_length = pdev->resource[i].end -
-				pdev->resource[i].start +1;
+		if( pdev_resource_flags(pdev, i) & 0x01 ) {
+			c->io_mem_addr = pdev_resource_start(pdev, i);
+			c->io_mem_length = pdev_resource_end(pdev, i) -
+				pdev_resource_start(pdev, i) +1;
 #ifdef CCISS_DEBUG
 			printk("IO value found base_addr[%d] %lx %lx\n", i,
 				c->io_mem_addr, c->io_mem_length);
@@ -2155,7 +2186,7 @@
 	printk("device_id = %x\n", device_id);
 	printk("command = %x\n", command);
 	for(i=0; i<6; i++)
-		printk("addr[%d] = %x\n", i, addr[i]);
+		printk("addr[%d] = %x\n", i, pci_resource_start(pdev, i);
 	printk("revision = %x\n", revision);
 	printk("irq = %x\n", irq);
 	printk("cache_line_size = %x\n", cache_line_size);
@@ -2170,7 +2201,7 @@
          *   table
 	 */

-	c->paddr = addr[0] ; /* addressing mode bits already removed */
+	c->paddr = pci_resource_start(pdev, 0); /* addressing mode bits already removed */
 #ifdef CCISS_DEBUG
 	printk("address 0 = %x\n", c->paddr);
 #endif /* CCISS_DEBUG */
@@ -2192,22 +2223,27 @@

 	/* get the address index number */
 	cfg_base_addr = readl(c->vaddr + SA5_CTCFG_OFFSET);
-	/* I am not prepared to deal with a 64 bit address value */
-	cfg_base_addr &= 0xffff;
+	cfg_base_addr &= (__u32) 0x0000ffff;
 #ifdef CCISS_DEBUG
 	printk("cfg base address = %x\n", cfg_base_addr);
 #endif /* CCISS_DEBUG */
-	cfg_base_addr_index = (cfg_base_addr  - PCI_BASE_ADDRESS_0)/4;
+	cfg_base_addr_index =
+		find_PCI_BAR_index(pdev, cfg_base_addr);
 #ifdef CCISS_DEBUG
 	printk("cfg base address index = %x\n", cfg_base_addr_index);
 #endif /* CCISS_DEBUG */
+	if (cfg_base_addr_index == -1) {
+		printk(KERN_WARNING "cciss: Cannot find cfg_base_addr_index\n");
+		release_io_mem(hba[i]);
+		return -1;
+	}

 	cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET);
 #ifdef CCISS_DEBUG
 	printk("cfg offset = %x\n", cfg_offset);
 #endif /* CCISS_DEBUG */
 	c->cfgtable = (CfgTable_struct *)
-		remap_pci_mem((addr[cfg_base_addr_index] & 0xfffffff0)
+		remap_pci_mem(pci_resource_start(pdev, cfg_base_addr_index)
 				+ cfg_offset, sizeof(CfgTable_struct));
 	c->board_id = board_id;

diff -burN lx261.orig/drivers/block/cciss.h lx261/drivers/block/cciss.h
--- lx261.orig/drivers/block/cciss.h	2004-01-09 00:59:02.000000000 -0600
+++ lx261/drivers/block/cciss.h	2004-01-21 15:53:59.000000000 -0600
@@ -42,8 +42,8 @@
 	char	firm_ver[4]; // Firmware version
 	struct pci_dev *pdev;
 	__u32	board_id;
-	ulong   vaddr;
-	__u32	paddr;
+	unsigned long vaddr;
+	unsigned long paddr;
 	unsigned long io_mem_addr;
 	unsigned long io_mem_length;
 	CfgTable_struct *cfgtable;

Thanks,
mikem
mike.miller@hp.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cciss updates for 2.6 [1 of 11]
  2004-02-05  0:04 cciss updates for 2.6 [1 of 11] mikem
@ 2004-02-05  4:30 ` Andrew Morton
  2004-02-05 11:10 ` Christoph Hellwig
  2004-02-06  1:09 ` Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2004-02-05  4:30 UTC (permalink / raw)
  To: mikem; +Cc: axboe, linux-kernel

mikem@beardog.cca.cpqcorp.net wrote:
>
> Patch 1 of 11. Please apply in order.

You seem to have used an email client which trims off all trailing
whitespace.  But `patch -l' happily applied everything so that's OK.

For next time: we don't normally use a cast to indicate that we're
deliberately discarding return values.

+	(void) pci_read_config_word(pdev, PCI_COMMAND,&command);

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cciss updates for 2.6 [1 of 11]
  2004-02-05  0:04 cciss updates for 2.6 [1 of 11] mikem
  2004-02-05  4:30 ` Andrew Morton
@ 2004-02-05 11:10 ` Christoph Hellwig
  2004-02-06  1:09 ` Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2004-02-05 11:10 UTC (permalink / raw)
  To: mikem; +Cc: axboe, akpm, linux-kernel

On Wed, Feb 04, 2004 at 06:04:46PM -0600, mikem@beardog.cca.cpqcorp.net wrote:
> +static int find_PCI_BAR_index(struct pci_dev *pdev,
> +				unsigned long pci_bar_addr)
> +{
> +	int i, offset, mem_type, bar_type;
> +	if (pci_bar_addr == PCI_BASE_ADDRESS_0) /* looking for BAR zero? */
> +		return 0;
> +	offset = 0;
> +	for (i=0; i<DEVICE_COUNT_RESOURCE; i++) {
> +		bar_type = pci_resource_flags(pdev, i) &
> +			PCI_BASE_ADDRESS_SPACE;
> +		if (bar_type == PCI_BASE_ADDRESS_SPACE_IO)
> +			offset += 4;
> +		else {
> +			mem_type = pci_resource_flags(pdev, i) &
> +				PCI_BASE_ADDRESS_MEM_TYPE_MASK;
> +			switch (mem_type) {
> +				case PCI_BASE_ADDRESS_MEM_TYPE_32:
> +				case PCI_BASE_ADDRESS_MEM_TYPE_1M:
> +					offset += 4; /* 32 bit */
> +					break;
> +				case PCI_BASE_ADDRESS_MEM_TYPE_64:
> +					offset += 8;
> +					break;
> +				default: /* reserved in PCI 2.2 */
> +					printk(KERN_WARNING "Base address is invalid\n");
> +			       		return -1;
> +				break;
> +			}
> +		}
> + 		if (offset == pci_bar_addr - PCI_BASE_ADDRESS_0)
> +			return i+1;
> +	}
> +	return -1;
> +}

Urgg, this stuff looks extremly kludgy.  What's missing from pci_request_regions
for you?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cciss updates for 2.6 [1 of 11]
  2004-02-05  0:04 cciss updates for 2.6 [1 of 11] mikem
  2004-02-05  4:30 ` Andrew Morton
  2004-02-05 11:10 ` Christoph Hellwig
@ 2004-02-06  1:09 ` Greg KH
  2004-02-06  1:54   ` mikem
  2 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2004-02-06  1:09 UTC (permalink / raw)
  To: mikem; +Cc: axboe, akpm, linux-kernel

On Wed, Feb 04, 2004 at 06:04:46PM -0600, mikem@beardog.cca.cpqcorp.net wrote:
> +
> +static int find_PCI_BAR_index(struct pci_dev *pdev,
> +				unsigned long pci_bar_addr)

What are you trying to do here that the PCI core doesn't do already?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: cciss updates for 2.6 [1 of 11]
  2004-02-06  1:09 ` Greg KH
@ 2004-02-06  1:54   ` mikem
  0 siblings, 0 replies; 5+ messages in thread
From: mikem @ 2004-02-06  1:54 UTC (permalink / raw)
  To: Greg KH; +Cc: axboe, akpm, linux-kernel

On Thu, 5 Feb 2004, Greg KH wrote:

> On Wed, Feb 04, 2004 at 06:04:46PM -0600, mikem@beardog.cca.cpqcorp.net wrote:
> > +
> > +static int find_PCI_BAR_index(struct pci_dev *pdev,
> > +				unsigned long pci_bar_addr)
>
> What are you trying to do here that the PCI core doesn't do already?
>
> thanks,
>
> greg k-h
>
I've already been informed of pci_request_regions. Thanks for your input.

mikem

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-02-06  1:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-05  0:04 cciss updates for 2.6 [1 of 11] mikem
2004-02-05  4:30 ` Andrew Morton
2004-02-05 11:10 ` Christoph Hellwig
2004-02-06  1:09 ` Greg KH
2004-02-06  1:54   ` mikem

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).